Skip to content

Commit

Permalink
update jojo volume
Browse files Browse the repository at this point in the history
  • Loading branch information
JoscelynFarr committed Apr 22, 2024
1 parent 15b5229 commit b424233
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions dexs/jojo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import fetchURL from "../../utils/fetchURL"
import { SimpleAdapter, Fetch } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const historicalVolumeEndpointZk = (symbol: string, chain: string) => `https://api.`+ chain +`-mainnet.jojo.exchange/v1/klines?marketId=${symbol}&interval=1D&startTime=1687017600000&limit=500`
const historicalVolumeEndpointZk = (symbol: string, chain: string) => `https://api.` + chain +`-mainnet.jojo.exchange/v1/platform/tradeVolume?marketId=${symbol}`
const coins = {
'ethusdc': 'coingecko:ethereum',
'btcusdc': 'coingecko:bitcoin',
Expand All @@ -14,23 +13,26 @@ interface IVolumeall {
id: string;
volume: string;
timestamp: number;
quoteVolume: string;
}

const getVolume = async (timestamp: number, chain: string) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historical = (await Promise.all(Object.keys(coins).map((coins: string) => fetchURL(historicalVolumeEndpointZk(coins, chain)))))
.map((a: any, index: number) => a.map((e: any) => { return { timestamp: e.time / 1000, volume: e.volume, id: Object.values(coins)[index], quoteVolume: e.quote_volume } })).flat()

const historicalUSD = historical.map((e: IVolumeall) => {
const historical = (await Promise.all(Object.keys(coins).map((coins: string) => fetchURL(historicalVolumeEndpointZk(coins, chain)))));

const historicalVolume = historical.map((item => item.dailyVolume))
const historicalUSD = historicalVolume.map((a: any, index: number) => a.map((e: any) => { return { timestamp: e.t / 1000, volume: e.v, id: Object.values(coins)[index]} })).flat()
const historicalUSD2 = historicalUSD.map((e: IVolumeall) => {
return {
...e,
volumeUSD: Number(e.quoteVolume)
volumeUSD: Number(e.volume)
}
});
const dailyVolume = historicalUSD.filter((e: IVolumeall) => e.timestamp === dayTimestamp)
.reduce((a: number, { volumeUSD }) => a + volumeUSD, 0);
const totalVolume = historicalUSD.filter((e: IVolumeall) => e.timestamp <= dayTimestamp)
const dailyVolume = historicalUSD2.filter((e: IVolumeall) => e.timestamp === dayTimestamp)
.reduce((a: number, { volumeUSD }) => a + volumeUSD, 0);
console.log(dailyVolume)

const totalVolume = historical.map(item => item.totalVolume).reduce((accumulator, currentValue) => accumulator + parseFloat(currentValue), 0);
return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
Expand All @@ -44,10 +46,6 @@ const getFetch = (chain: string): Fetch => async (timestamp: number) => {

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: getFetch("arbitrum"),
start: 1687017600,
},
[CHAIN.BASE]: {
fetch: getFetch("base"),
start: 1711965100,
Expand Down

0 comments on commit b424233

Please sign in to comment.