diff --git a/README.md b/README.md index 514c77d..f0bf7f8 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ The below all return a Promise that resolves with the requested results. 31. `snx.accountsFlaggedForLiquidation({ minTime, maxTime, account, max })` finds all the accounts that have been flagged for liquidation. 32. `snx.accountsLiquidated({ maxTime, minTime, account, max })` finds all the accounts that have been liquidated after being flagged for liquidation. 33. `snx.getActiveLiquidations({ max, account, minTime, maxTime })` finds all the accounts that have been flagged and are still pending liquidation or in a waiting state. Can also just check for a specific account if desired. +34. `exchanger.dailyExchangeSourceData({ timeSeries, partner })` Get the list of volume from all or specific sources. +35. `exchanger.exchangeSourceData({ partner })` Get the list of all time volume from all or specific sources. ## Supported subscriptions diff --git a/bin.js b/bin.js index 7be6fac..9e7421c 100755 --- a/bin.js +++ b/bin.js @@ -600,6 +600,29 @@ program .then(showResultCount({ max })); }); +program + .command('exchanger.dailyExchangeSourceData') + .option('-t, --timeSeries ', 'The type of timeSeries - 7d, 30d, 1mo, 365d, 12mo, 1y', '1mo') + .option('-p, --partner ', 'Partner to filter on, if any') + + .action(async ({ timeSeries, partner }) => { + exchanger + .dailyExchangeSourceData({ timeSeries, partner }) + .then(logResults()) + .then(showResultCount({ max: 'n/a' })); + }); + +program + .command('exchanger.exchangeSourceData') + .option('-p, --partner ', 'Partner to filter on, if any') + + .action(async ({ partner }) => { + exchanger + .exchangeSourceData({ partner }) + .then(logResults()) + .then(showResultCount({ max: 'n/a' })); + }); + program.command('exchanges.observe').action(async () => { exchanges.observe().subscribe({ next(val) { diff --git a/index.js b/index.js index c3b2fe7..9e7829e 100644 --- a/index.js +++ b/index.js @@ -1340,6 +1340,64 @@ module.exports = { ) .catch(err => console.error(err)); }, + dailyExchangeSourceData({ timeSeries = '1mo', partner = undefined }) { + const now = new Date(); + const currentDayID = Math.floor(now.getTime() / 86400 / 1000); + let searchFromDayID; + if (timeSeries === '7d') { + searchFromDayID = currentDayID - 7; + } else if (timeSeries === '1mo' || timeSeries === '30d') { + searchFromDayID = currentDayID - 30; + } else if (timeSeries === '1y' || timeSeries === '365d' || timeSeries === '12mo') { + searchFromDayID = currentDayID - 365; + } + return pageResults({ + api: graphAPIEndpoints.exchanger, + max: 10000, + query: { + entity: 'dailyExchangePartners', + selection: { + orderBy: 'id', + orderDirection: 'desc', + where: { + dayID_gt: searchFromDayID ? `\\"${searchFromDayID}\\"` : undefined, + partner: partner ? `\\"${partner}\\"` : undefined, + }, + }, + properties: ['trades', 'usdVolume', 'usdFees', 'partner', 'dayID'], + }, + }).then(results => + results.map(({ dayID, partner, trades, usdFees, usdVolume }) => ({ + dayID: Number(dayID), + partner, + trades: Number(trades), + usdFees: Math.round(Number(usdFees) * 100) / 100, + usdVolume: Math.round(Number(usdVolume) * 100) / 100, + })), + ); + }, + exchangeSourceData({ partner = undefined }) { + return pageResults({ + api: graphAPIEndpoints.exchanger, + max: 10000, + query: { + entity: 'exchangePartners', + selection: { + where: { + id: partner ? `\\"${partner}\\"` : undefined, + }, + }, + properties: ['trades', 'usdVolume', 'usdFees', 'id'], + }, + }).then(results => + results.map(({ id, trades, usdFees, usdVolume }) => ({ + partner: id, + trades: Number(trades), + usdFees: Math.round(Number(usdFees) * 100) / 100, + usdVolume: Math.round(Number(usdVolume) * 100) / 100, + })), + ); + }, }, liquidations: { accountsFlaggedForLiquidation({ diff --git a/package-lock.json b/package-lock.json index 28a20b7..6ad4945 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2568,7 +2568,8 @@ }, "elliptic": { "version": "6.5.2", - "resolved": "", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz", + "integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw==", "dev": true, "requires": { "bn.js": "^4.4.0", @@ -5637,7 +5638,8 @@ }, "kind-of": { "version": "6.0.2", - "resolved": "", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true }, "lcid": { @@ -5744,7 +5746,8 @@ }, "minimist": { "version": "1.2.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, "mixin-deep": { diff --git a/package.json b/package.json index 7a385b6..518b11d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "csv-stringify": "5.3.3", "graph-results-pager": "1.0.3", "graphql": "14.5.8", - "moment": "~2.24.0", + "moment": "2.24.0", "node-fetch": "2.6.1", "subscriptions-transport-ws": "0.9.16", "ws": "7.2.0"