Skip to content

Commit ad0a3d0

Browse files
committed
add volume source queries to synthetix-data - WIP - need to update the api endpoint once the volume graph PR is merged
1 parent 54e1ba6 commit ad0a3d0

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The below all return a Promise that resolves with the requested results.
3939
27. `snx.aggregateActiveStakers({ max, timeSeries })` Get the number of active stakers across various time series.
4040
28. `snx.totalActiveStakers()` Get the current number of active stakers.
4141
29. `rate.dailyRateChange({ synths })` get the rate change over the past 24 hours for any synth. Can pass in a list to retrieve multiple synths.
42+
30. `exchanger.exchangeSourceData({ timeSeries, partner })` Get the list of volume from all or specific sources.
4243

4344
## Supported subscriptions
4445

bin.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,18 @@ program
474474
.then(showResultCount({ max }));
475475
});
476476

477+
program
478+
.command('exchanger.exchangeSourceData')
479+
.option('-t, --timeSeries <value>', 'The type of timeSeries - 7d, 30d, 1mo, 365d, 12mo, 1y', '1mo')
480+
.option('-p, --partner <value>', 'Partner to filter on, if any')
481+
482+
.action(async ({ timeSeries, partner }) => {
483+
exchanger
484+
.exchangeSourceData({ timeSeries, partner })
485+
.then(logResults())
486+
.then(showResultCount({ max: 'n/a' }));
487+
});
488+
477489
program.command('exchanges.observe').action(async () => {
478490
exchanges.observe().subscribe({
479491
next(val) {

index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const graphAPIEndpoints = {
1616
exchanger: 'https://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-exchanger',
1717
};
1818

19+
const tempEndpoint = 'https://api.thegraph.com/subgraphs/name/dvd-schwrtz/exchanger';
20+
1921
const graphWSEndpoints = {
2022
exchanges: 'wss://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-exchanges',
2123
rates: 'wss://api.thegraph.com/subgraphs/name/synthetixio-team/synthetix-rates',
@@ -1242,5 +1244,41 @@ module.exports = {
12421244
)
12431245
.catch(err => console.error(err));
12441246
},
1247+
exchangeSourceData({ timeSeries = '1mo', partner = undefined }) {
1248+
const now = new Date();
1249+
const currentDayID = Math.floor(now.getTime() / 86400 / 1000);
1250+
let searchFromDayID;
1251+
if (timeSeries === '7d') {
1252+
searchFromDayID = currentDayID - 7;
1253+
} else if (timeSeries === '1mo' || timeSeries === '30d') {
1254+
searchFromDayID = currentDayID - 30;
1255+
} else if (timeSeries === '1y' || timeSeries === '365d' || timeSeries === '12mo') {
1256+
searchFromDayID = currentDayID - 365;
1257+
}
1258+
return pageResults({
1259+
api: tempEndpoint,
1260+
max: 10000,
1261+
query: {
1262+
entity: 'dailyExchangePartners',
1263+
selection: {
1264+
orderBy: 'id',
1265+
orderDirection: 'desc',
1266+
where: {
1267+
dayID_gt: searchFromDayID ? `\\"${searchFromDayID}\\"` : undefined,
1268+
partner: partner ? `\\"${partner}\\"` : undefined,
1269+
},
1270+
},
1271+
properties: ['trades', 'usdVolume', 'usdFees', 'partner', 'dayID'],
1272+
},
1273+
}).then(results =>
1274+
results.map(({ dayID, partner, trades, usdFees, usdVolume }) => ({
1275+
dayID: Number(dayID),
1276+
partner,
1277+
trades: Number(trades),
1278+
usdFees: Math.round(Number(usdFees) * 100) / 100,
1279+
usdVolume: Math.round(Number(usdVolume) * 100) / 100,
1280+
})),
1281+
);
1282+
},
12451283
},
12461284
};

0 commit comments

Comments
 (0)