From ef8cb5edd543f256e036d925ad695bd8b066d051 Mon Sep 17 00:00:00 2001 From: Harshit Agarwal Date: Thu, 19 Mar 2020 18:58:42 +0530 Subject: [PATCH 1/2] Add Transak report integration code Integration code for Transak has been added. All the edge users' orders with Transak can be fetched using the implemented code and will be mapped to the standard transaction format as provided. --- src/reporter.js | 15 +++++++++++ src/transak.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/transak.js diff --git a/src/reporter.js b/src/reporter.js index 1e137d4..53ee793 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -10,6 +10,7 @@ const { doFox } = require('./fox.js') const { doFaast } = require('./faast.js') const { doCoinswitch } = require('./coinswitch.js') const { doMoonpay } = require('./moonpay.js') +const { doTransak } = require('./transak.js') const { doWyre } = require('./wyre.js') const { doBog } = require('./bitsOfGold.js') const { doGodex } = require('./godex.js') @@ -25,6 +26,10 @@ async function main (swapFuncParams: SwapFuncParams) { const rChn = await doChangenow(swapFuncParams).catch(e => { console.error('doChangenow failed') return {} + }) + const rTnk = await doTransak(swapFuncParams).catch(e => { + console.error('doTransak failed') + return {} }) const rCha = await doChangelly(swapFuncParams).catch(e => { console.error('doChangelly failed') @@ -106,6 +111,7 @@ async function main (swapFuncParams: SwapFuncParams) { printTxDataMap('CS', rCs) printTxDataMap('GDX', rGdx) printTxDataMap('MNP', rMnp) + printTxDataMap('TNK', rTnk) printTxDataMap('WYR', rWyr) printTxDataMap('SAF', rSaf) printTxDataMap('BOG', rBog) @@ -281,6 +287,9 @@ async function report (argv: Array) { const mnpResults = config.moonpayApiKey ? await doSummaryFunction(doMoonpay) : {} + const tnkResults = config.transak_api_secret + ? await doSummaryFunction(doTransak) + : {} const wyrResults = config.wyre && config.wyre.periscopeClientKey ? await doSummaryFunction(doWyre) : {} @@ -359,6 +368,11 @@ async function report (argv: Array) { console.log('\n***** Moonpay Daily *****') printTxDataMap('MNP', mnpResults.daily) + console.log('\n***** Transak Monthly *****') + printTxDataMap('TNK', tnkResults.monthly) + console.log('\n***** Transak Daily *****') + printTxDataMap('TNK', tnkResults.daily) + console.log('\n***** Wyre Monthly *****') printTxDataMap('WYR', wyrResults.monthly) console.log('\n***** Wyre Daily *****') @@ -399,6 +413,7 @@ async function report (argv: Array) { combineResults(fiatResults, lxResults) combineResults(fiatResults, btResults) combineResults(fiatResults, mnpResults) + combineResults(fiatResults, tnkResults) combineResults(fiatResults, wyrResults) combineResults(fiatResults, safResults) combineResults(fiatResults, bogResults) diff --git a/src/transak.js b/src/transak.js new file mode 100644 index 0000000..420666c --- /dev/null +++ b/src/transak.js @@ -0,0 +1,70 @@ +// @flow +import type { StandardTx, SwapFuncParams } from './checkSwapService.js' +const js = require('jsonfile') +const fetch = require('node-fetch') +const confFileName = './config.json' +const config = js.readFileSync(confFileName) +const { checkSwapService } = require('./checkSwapService.js') + +const CACHE_FILE = './cache/tnkRaw.json' + +const isConfigValid = (typeof config.transak_api_secret !== 'undefined') + +let query = '' +if (isConfigValid) { + query = config.transak_api_secret +} + +async function doTransak (swapFuncParams: SwapFuncParams) { + return checkSwapService(fetchTransak, + CACHE_FILE, + 'TNK', + swapFuncParams + ) +} + +async function fetchTransak (swapFuncParams: SwapFuncParams) { + if (!swapFuncParams.useCache) { + console.log('Fetching Transak...') + } + let diskCache = { txs: [] } + try { + diskCache = js.readFileSync(CACHE_FILE) + } catch (e) {} + + const ssFormatTxs: Array = [] + + const url = `https://api.transak.com/api/v1/partners/orders/?partnerAPISecret=${query}` + const result = await fetch(url, { + method: 'GET' + }) + const orders = await result.json() + if(!orders && !orders.response){ + throw new Error('Orders fetching failed for Transak') + } + + for (const order of orders.response) { + if (order.status === 'COMPLETE') { + const ssTx: StandardTx = { + inputTXID: order.transactionHash, + inputAddress: order.fromWalletAddress, + inputCurrency: order.fiatCurrency, + inputAmount: order.fiatAmount, + outputAddress: order.walletAddress, + outputCurrency: order.cryptocurrency, + status: 'complete', + timestamp: order.completedAt, + outputAmount: order.cryptoAmount + } + ssFormatTxs.push(ssTx) + } + } + + const out = { + diskCache, + newTransactions: ssFormatTxs + } + return out +} + +module.exports = { doTransak } From 6ece3b275c328b3d384e203b3058e6e4589a808d Mon Sep 17 00:00:00 2001 From: Yeshu Agarwal Date: Thu, 7 May 2020 21:40:23 +0530 Subject: [PATCH 2/2] Add limit & skip parameter for the pagination. Earlier, there were no parameters for the pagination while fetching the orders. So added limit & skip parameter to fetch the orders properly. --- src/transak.js | 105 +++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 56 deletions(-) diff --git a/src/transak.js b/src/transak.js index 420666c..a16e9c3 100644 --- a/src/transak.js +++ b/src/transak.js @@ -1,70 +1,63 @@ // @flow -import type { StandardTx, SwapFuncParams } from './checkSwapService.js' +import type {StandardTx, SwapFuncParams} from './checkSwapService.js' const js = require('jsonfile') const fetch = require('node-fetch') const confFileName = './config.json' const config = js.readFileSync(confFileName) -const { checkSwapService } = require('./checkSwapService.js') +const {checkSwapService} = require('./checkSwapService.js') const CACHE_FILE = './cache/tnkRaw.json' -const isConfigValid = (typeof config.transak_api_secret !== 'undefined') - -let query = '' -if (isConfigValid) { - query = config.transak_api_secret -} - -async function doTransak (swapFuncParams: SwapFuncParams) { - return checkSwapService(fetchTransak, - CACHE_FILE, - 'TNK', - swapFuncParams - ) +async function doTransak(swapFuncParams: SwapFuncParams) { + return checkSwapService(fetchTransak, + CACHE_FILE, + 'TNK', + swapFuncParams + ) } -async function fetchTransak (swapFuncParams: SwapFuncParams) { - if (!swapFuncParams.useCache) { - console.log('Fetching Transak...') - } - let diskCache = { txs: [] } - try { - diskCache = js.readFileSync(CACHE_FILE) - } catch (e) {} - - const ssFormatTxs: Array = [] - - const url = `https://api.transak.com/api/v1/partners/orders/?partnerAPISecret=${query}` - const result = await fetch(url, { - method: 'GET' - }) - const orders = await result.json() - if(!orders && !orders.response){ - throw new Error('Orders fetching failed for Transak') - } - - for (const order of orders.response) { - if (order.status === 'COMPLETE') { - const ssTx: StandardTx = { - inputTXID: order.transactionHash, - inputAddress: order.fromWalletAddress, - inputCurrency: order.fiatCurrency, - inputAmount: order.fiatAmount, - outputAddress: order.walletAddress, - outputCurrency: order.cryptocurrency, - status: 'complete', - timestamp: order.completedAt, - outputAmount: order.cryptoAmount - } - ssFormatTxs.push(ssTx) +async function fetchTransak(swapFuncParams: SwapFuncParams) { + if (!swapFuncParams.useCache) console.log('Fetching Transak...') + let diskCache = {offset: 0, txs: []} + try { + diskCache = js.readFileSync(CACHE_FILE) + } catch (e) { + } + let offset = diskCache.offset ? diskCache.offset : 0 + const ssFormatTxs: Array = [] + + while (1 && !swapFuncParams.useCache) { + let limit = 100, orders = [] + const apiResponse = await fetch(`https://api.transak.com/api/v1/partners/orders/?partnerAPISecret=${config.transak_api_secret}?limit=${limit}&skip=${offset}`) + const ordersData = await apiResponse.json(); + + if (ordersData && ordersData.response && orders.response.length) orders = ordersData.response; + else return {} + + for (const order of orders) { + if (order.status === 'COMPLETE') { + const ssTx: StandardTx = { + inputTXID: order.transactionHash, + inputAddress: order.fromWalletAddress, + inputCurrency: order.fiatCurrency, + inputAmount: order.fiatAmount, + outputAddress: order.walletAddress, + outputCurrency: order.cryptocurrency, + status: 'complete', + timestamp: order.completedAt, + outputAmount: order.cryptoAmount + } + ssFormatTxs.push(ssTx) + } + } + + if (orders.length < 100) break + offset += 100 } - } - const out = { - diskCache, - newTransactions: ssFormatTxs - } - return out + diskCache.offset = offset - 500 + const out = {diskCache, newTransactions: ssFormatTxs} + return out } -module.exports = { doTransak } +module.exports = {doTransak}