Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,29 @@ program
.then(showResultCount({ max }));
});

program
.command('exchanger.dailyExchangeSourceData')
.option('-t, --timeSeries <value>', 'The type of timeSeries - 7d, 30d, 1mo, 365d, 12mo, 1y', '1mo')
.option('-p, --partner <value>', '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 <value>', '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) {
Expand Down
58 changes: 58 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down