Skip to content

Commit

Permalink
Merge pull request #620 from clober-dex/master
Browse files Browse the repository at this point in the history
feat: add `totalVolume` for Clober Dex
  • Loading branch information
dtmkeng committed Jul 14, 2023
2 parents 2f11c0c + 3029286 commit 1572e64
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dexs/clober/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import { CHAIN } from "../../helpers/chains";

type TMarket = {
volumeUsd24h: number;
accumulatedVolumeUsd: number;
}

type TVolume = {
volume_usd24h: number;
accumulated_volume_usd: number;
}

const fetch = (chain: string) => async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const { markets }: { markets: TMarket[] } = (await fetchURL(`https://prod.clober-api.com/${chain}/markets`)).data;
let dailyVolume = markets.map(market => market.volumeUsd24h).reduce((acc, cur) => acc + cur, 0)
let totalVolume = markets.map(market => market.accumulatedVolumeUsd).reduce((acc, cur) => acc + cur, 0)
if (chain === '1101') {
const {result}: {result: TVolume} = (await fetchURL(`https://pathfinder.clober-api.com/status`)).data;
dailyVolume += result.volume_usd24h;
totalVolume += result.accumulated_volume_usd;
}
return {
dailyVolume: `${dailyVolume}`,
totalVolume: `${totalVolume}`,
timestamp: dayTimestamp,
};
};
Expand Down

0 comments on commit 1572e64

Please sign in to comment.