Skip to content

Commit

Permalink
fix data wrong data
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Oct 16, 2023
1 parent ccfb4e1 commit d85e9ab
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions dexs/dydx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ const url = 'https://dydx.metabaseapp.com/api/public/dashboard/5fa0ea31-27f7-4cd

const fetch = async (timestamp: number): Promise<FetchResultVolume> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const fromTimestamp = dayTimestamp - 60 * 60 * 24
const fromISO = new Date(fromTimestamp * 1000).toISOString();
// const fromTimestamp = dayTimestamp - 60 * 60 * 24
// const fromISO = new Date(fromTimestamp * 1000).toISOString();
const dateString = new Date(dayTimestamp * 1000).toISOString();
const markets: string[] = Object.keys((await fetchURL(historicalVolumeEndpoint))?.data.markets);
const historical: IVolumeall[] = (await Promise.all(markets.map((market: string) => fetchURL(candles(market, fromISO))))).map((e: any) => e.data.candles).flat()
const dailyolume = historical.filter((e: IVolumeall) => e.startedAt === dateString)
.reduce((a: number, b: IVolumeall) => a+Number(b.usdVolume), 0)
// const markets: string[] = Object.keys((await fetchURL(historicalVolumeEndpoint))?.data.markets);
// const historical: IVolumeall[] = (await Promise.all(markets.map((market: string) => fetchURL(candles(market, fromISO))))).map((e: any) => e.data.candles).flat()
// const dailyolume = historical.filter((e: IVolumeall) => e.startedAt === dateString)
// .reduce((a: number, b: IVolumeall) => a+Number(b.usdVolume), 0)
const timeString = dateString.split("T")[0];
const data: OpenInterest[] = (await fetchURL(url))?.data.data.rows.map((e: any) => {
return {
date: e[0].split('T')[0],
openInterest: e[2],
}
})
// const data: OpenInterest[] = (await fetchURL(url))?.data.data.rows.map((e: any) => {
// return {
// date: e[0].split('T')[0],
// openInterest: e[1],
// }
// })
// const fs = require('fs');
// fs.writeFileSync('dydx.json', JSON.stringify(data))
const data = require('./dydx.json')
const dailyOpenInterest = data.find((e: OpenInterest) => e.date === timeString)?.openInterest;
return {
dailyVolume: dailyolume ? `${dailyolume}` : undefined,
// dailyVolume: dailyolume ? `${dailyolume}` : undefined,
dailyOpenInterest: dailyOpenInterest ? `${dailyOpenInterest}` : undefined,
timestamp: timestamp,
};
Expand Down

0 comments on commit d85e9ab

Please sign in to comment.