From 230c5a1d03e93e809401d06fd22211346cea390d Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Tue, 20 Feb 2024 11:03:19 +0000 Subject: [PATCH] fix helix perp --- dexs/helix-perp/index.ts | 33 --------------------------------- dexs/helix/index.ts | 34 +++++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 40 deletions(-) delete mode 100644 dexs/helix-perp/index.ts diff --git a/dexs/helix-perp/index.ts b/dexs/helix-perp/index.ts deleted file mode 100644 index dc2afddee5..0000000000 --- a/dexs/helix-perp/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { FetchResultVolume, SimpleAdapter } from "../../adapters/types"; -import { CHAIN } from "../../helpers/chains"; -import fetchURL from "../../utils/fetchURL" - -const URL = "https://external.api.injective.network/api/aggregator/v1/derivative/contracts"; -interface IVolume { - target_volume: number; - open_interest: number; -} - -const fetch = async (timestamp: number): Promise => { - const volume: IVolume[] = (await fetchURL(URL)); - const dailyVolume = volume.reduce((e: number, a: IVolume) => a.target_volume + e, 0); - const dailyOpenInterest = volume.reduce((e: number, a: IVolume) => a.open_interest + e, 0); - - return { - dailyVolume: dailyVolume.toString(), - dailyOpenInterest: dailyOpenInterest.toString(), - timestamp - } -} - - -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.INJECTIVE]: { - fetch: fetch, - start: 1706313600, - } - } -} - -export default adapter; diff --git a/dexs/helix/index.ts b/dexs/helix/index.ts index d995b45f72..998276dab5 100644 --- a/dexs/helix/index.ts +++ b/dexs/helix/index.ts @@ -1,10 +1,11 @@ -import { ChainBlocks, FetchOptions, FetchResultVolume, SimpleAdapter } from "../../adapters/types"; +import { BreakdownAdapter, ChainBlocks, FetchOptions, FetchResultVolume, SimpleAdapter } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import fetchURL from "../../utils/fetchURL" const URL = "https://external.api.injective.network/api/aggregator/v1/spot/tickers"; interface IVolume { target_volume: number; + open_interest: number; } const fetch = async (timestamp: number, _: ChainBlocks, { createBalances }: FetchOptions): Promise => { @@ -18,14 +19,33 @@ const fetch = async (timestamp: number, _: ChainBlocks, { createBalances }: Fetc } } +const URL_Derivative = "https://external.api.injective.network/api/aggregator/v1/derivative/contracts"; +const fetchDerivative = async (timestamp: number): Promise => { + const volume: IVolume[] = (await fetchURL(URL_Derivative)); + const dailyVolume = volume.reduce((e: number, a: IVolume) => a.target_volume + e, 0); + const dailyOpenInterest = volume.reduce((e: number, a: IVolume) => a.open_interest + e, 0); -const adapter: SimpleAdapter = { - adapter: { - [CHAIN.INJECTIVE]: { - fetch: fetch, - start: 1676505600, - } + return { + dailyVolume: dailyVolume.toString(), + dailyOpenInterest: dailyOpenInterest.toString(), + timestamp } } +const adapter: BreakdownAdapter = { + breakdown: { + "helix": { + [CHAIN.INJECTIVE]: { + fetch: fetch, + start: 1676505600, + } + }, + "helix-perp": { + [CHAIN.INJECTIVE]: { + fetch: fetchDerivative, + start: 1706313600, + } + } + } +} export default adapter;