From 763d042165bc80951b54a0356e69fd3aebdc7e0b Mon Sep 17 00:00:00 2001 From: devexolix Date: Tue, 30 Nov 2021 11:44:01 +0200 Subject: [PATCH] add exolix reports --- config.json.sample | 1 + src/exolix.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++ src/reporter.js | 15 +++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/exolix.js diff --git a/config.json.sample b/config.json.sample index bd8dd15..f2583de 100644 --- a/config.json.sample +++ b/config.json.sample @@ -12,6 +12,7 @@ "changellyApiKey": "xxx", "changenowApiKey": "xxx", "changellyApiSecret": "xxx", + "exolixApiKey" : "xxx", "faastAffiliateId": "xxx", "faastSecret": "xxx", "totleApiKey": "xxx", diff --git a/src/exolix.js b/src/exolix.js new file mode 100644 index 0000000..7f0e19d --- /dev/null +++ b/src/exolix.js @@ -0,0 +1,83 @@ +// @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 EXOLIX_CACHE = './cache/exRaw.json' + +const PER_PAGE = 100 + +async function doExolix (swapFuncParams: SwapFuncParams) { + return checkSwapService(fetchExolix, + EXOLIX_CACHE, + 'EX', + swapFuncParams + ) +} + +async function fetchExolix (swapFuncParams: SwapFuncParams) { + if (!swapFuncParams.useCache) { + console.log('Fetching Exolix...') + } + let diskCache = { txs: [] } + try { + diskCache = js.readFileSync(EXOLIX_CACHE) + } catch (e) {} + let page = diskCache.page ? diskCache.page : 1 + + const ssFormatTxs: Array = [] + + while (1 && !swapFuncParams.useCache) { + const response = await fetch( + `https://exolix.com/api/history?page=${page}&per_page=${PER_PAGE}`, + { + Authorization: config.exolixApiKey + } + ) + const result = await response.json() + + const txs = result.data + + if (!txs.length) { + return {} + } + + for (const tx of txs) { + if (tx.status === 'success') { + const ssTx: StandardTx = { + status: 'complete', + inputTXID: tx.input_hash, + inputAddress: tx.deposit_address, + inputCurrency: tx.coin_from.toUpperCase(), + inputAmount: tx.amount_from, + outputAddress: tx.destination_address, + outputCurrency: tx.coin_to.toUpperCase(), + outputAmount: tx.amount_to, + timestamp: tx.created_at + } + ssFormatTxs.push(ssTx) + } + } + + if (result.total < PER_PAGE) { + break + } + + page++ + + if (result.last_page < page) { + break + } + } + + const out = { + diskCache, + newTransactions: ssFormatTxs + } + return out +} + +module.exports = { doExolix } diff --git a/src/reporter.js b/src/reporter.js index d69ef40..fd27424 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -1,5 +1,6 @@ // @flow import type { SwapFuncParams, TxDataMap } from './checkSwapService.js' +const { doExolix } = require('./exolix.js') const { doShapeShift } = require('./shapeshift.js') const { doChangelly } = require('./changelly.js') const { doLibertyX } = require('./libertyx.js') @@ -25,6 +26,10 @@ const config = require('../config.json') const { sprintf } = require('sprintf-js') async function main (swapFuncParams: SwapFuncParams) { + const rEx = await doExolix(swapFuncParams).catch(e => { + console.error('doExolix failed') + return {} + }) const rChn = await doChangenow(swapFuncParams).catch(e => { console.error('doChangenow failed') return {} @@ -112,6 +117,7 @@ async function main (swapFuncParams: SwapFuncParams) { return {} }) + printTxDataMap('EX', rEx) printTxDataMap('CHN', rChn) printTxDataMap('CHA', rCha) printTxDataMap('FAA', rFaa) @@ -265,6 +271,9 @@ async function report (argv: Array) { const fiatResults: { [string]: TxDataMap } = {} // swaps (crypto-to-crypto) + const exResults = config.exolixApiKey + ? await doSummaryFunction(doExolix) + : {} const cnResults = config.changenowApiKey ? await doSummaryFunction(doChangenow) : {} @@ -325,6 +334,7 @@ async function report (argv: Array) { const banResults = await doSummaryFunction(doBanxa) const bityResults = await doSummaryFunction(doBity) + combineResults(results, exResults) combineResults(results, cnResults) combineResults(results, chResults) combineResults(results, faResults) @@ -335,6 +345,11 @@ async function report (argv: Array) { combineResults(results, gxResults) combineResults(results, swResults) + console.log('\n***** Exolix Daily *****') + printTxDataMap('EX', exResults.daily) + console.log('\n***** Exolix monthly *****') + printTxDataMap('EX', exResults.monthly) + console.log('\n***** Change NOW Daily *****') printTxDataMap('CHN', cnResults.daily) console.log('\n***** Change NOW monthly *****')