From 0cd332a63e11880070f17c813a61765fc75a5a7d Mon Sep 17 00:00:00 2001 From: dvd-schwrtz Date: Mon, 2 Nov 2020 11:53:39 -0800 Subject: [PATCH 1/2] add volume source queries to synthetix-data - WIP - need to update the api endpoint once the volume graph PR is merged --- README.md | 1 + bin.js | 12 ++++++++++++ index.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/README.md b/README.md index 514c77d..6209e3e 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ 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.exchangeSourceData({ timeSeries, partner })` Get the list of volume from all or specific sources. ## Supported subscriptions diff --git a/bin.js b/bin.js index 7be6fac..3954c6d 100755 --- a/bin.js +++ b/bin.js @@ -600,6 +600,18 @@ program .then(showResultCount({ max })); }); +program + .command('exchanger.exchangeSourceData') + .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 + .exchangeSourceData({ timeSeries, 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..17eb976 100644 --- a/index.js +++ b/index.js @@ -1340,6 +1340,42 @@ module.exports = { ) .catch(err => console.error(err)); }, + exchangeSourceData({ 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, + })), + ); + }, }, liquidations: { accountsFlaggedForLiquidation({ From 282a475c4f5224dda9a86a427fdf3e617d0ac3a6 Mon Sep 17 00:00:00 2001 From: dvd-schwrtz Date: Mon, 21 Dec 2020 12:48:51 -0800 Subject: [PATCH 2/2] udpate volume source queries --- README.md | 3 ++- bin.js | 15 +++++++++++++-- index.js | 24 +++++++++++++++++++++++- package-lock.json | 9 ++++++--- package.json | 2 +- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6209e3e..f0bf7f8 100644 --- a/README.md +++ b/README.md @@ -43,7 +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.exchangeSourceData({ timeSeries, partner })` Get the list of volume from all or specific sources. +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 3954c6d..9e7421c 100755 --- a/bin.js +++ b/bin.js @@ -601,13 +601,24 @@ program }); program - .command('exchanger.exchangeSourceData') + .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 - .exchangeSourceData({ timeSeries, partner }) + .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' })); }); diff --git a/index.js b/index.js index 17eb976..9e7829e 100644 --- a/index.js +++ b/index.js @@ -1340,7 +1340,7 @@ module.exports = { ) .catch(err => console.error(err)); }, - exchangeSourceData({ timeSeries = '1mo', partner = undefined }) { + dailyExchangeSourceData({ timeSeries = '1mo', partner = undefined }) { const now = new Date(); const currentDayID = Math.floor(now.getTime() / 86400 / 1000); let searchFromDayID; @@ -1376,6 +1376,28 @@ module.exports = { })), ); }, + 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"