| 
1 |  | -import fetchURL from "../../utils/fetchURL"  | 
2 | 1 | import { SimpleAdapter } from "../../adapters/types";  | 
3 | 2 | import { CHAIN } from "../../helpers/chains";  | 
4 |  | -import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";  | 
5 |  | - | 
6 |  | -const historicalVolumeEndpoint = (symbol: string, endTime: number) => `https://pro.apex.exchange/api/v1/klines?end=${endTime}&interval=D&start=1708732800&symbol=${symbol}&limit=10`  | 
7 |  | -const allTiker = (symbol: string) => `https://pro.apex.exchange/api/v1/ticker?symbol=${symbol}`  | 
8 |  | -interface IVolumeall {  | 
9 |  | -    id: string;  | 
10 |  | -    volume: string;  | 
11 |  | -    timestamp: number;  | 
12 |  | -    price: string;  | 
13 |  | -    volumeUSD: number;  | 
14 |  | -}  | 
15 |  | -const symbol: string[] = [...new Set([  | 
16 |  | -    '1000PEPEUSDC', 'APTUSDC',      'ARBUSDC',  | 
17 |  | -    'ATOMUSDC',     'AVAXUSDC',     'BCHUSDC',  | 
18 |  | -    'BLURUSDC',     'BNBUSDC',      'BTCUSDC',  | 
19 |  | -    'BTCUSDT',      'DOGEUSDC',     'DYDXUSDC',  | 
20 |  | -    'ETCUSDC',      'ETHUSDC',      'ETHUSDT',  | 
21 |  | -    'LBRUSDC',      'LDOUSDC',      'LINKUSDC',  | 
22 |  | -    'LTCUSDC',      'MATICUSDC',    'OPUSDC',  | 
23 |  | -    'ORDIUSDT',     'SOLUSDC',      'TIAUSDC',  | 
24 |  | -    'TONUSDC',      'WLDUSDC',      'XRPUSDC',  | 
25 |  | -    'STXUSDT',      'BIGTIMEUSDT',  'MEMEUSDT',  | 
26 |  | -    'PYTHUSDT',     'FETUSDT',      'RNDRUSDT',  | 
27 |  | -    'ICPUSDT',      '1000BONKUSDT', 'DOTUSDT',  | 
28 |  | -    'SEIUSDT',      'INJUSDT',      'ENSUSDT',  | 
29 |  | -    '1000SATSUSDT', 'PENDLEUSDT',   'GMTUSDT',  | 
30 |  | -    'MANTAUSDT',    'LINKUSDT',     'SOLUSDT',  | 
31 |  | -    'MATICUSDT',    'STRKUSDT',     'SUIUSDT'  | 
32 |  | -])]  | 
33 |  | -interface IOpenInterest {  | 
34 |  | -    id: string;  | 
35 |  | -    openInterest: string;  | 
36 |  | -    lastPrice: string;  | 
37 |  | -}  | 
38 |  | - | 
39 |  | -const fetch = async (timestamp: number) => {  | 
40 |  | -    const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))  | 
41 |  | -    const historical: any[] = (await Promise.all(symbol.map((coins: string) => fetchURL(historicalVolumeEndpoint(coins, dayTimestamp + 60 * 60 * 24)))))  | 
42 |  | -        .map((e: any) => Object.values(e.data)).flat().flat()  | 
43 |  | -        .map((e: any) => { return { timestamp: e.t / 1000, volume: e.v, price: e.c } });  | 
44 |  | -    const openInterestHistorical: IOpenInterest[] = (await Promise.all(symbol.map((coins: string) => fetchURL(allTiker(coins)))))  | 
45 |  | -        .map((e: any) => e.data).flat().map((e: any) => { return { id: e.symbol, openInterest: e.openInterest, lastPrice: e.lastPrice } });  | 
46 |  | -    const openInterestAtEnd = openInterestHistorical.reduce((a: number, { openInterest, lastPrice }) => a + Number(openInterest) * Number(lastPrice), 0);  | 
47 |  | -    const historicalUSD = historical.map((e: IVolumeall) => {  | 
48 |  | -        return {  | 
49 |  | -            ...e,  | 
50 |  | -            volumeUSD: Number(e.volume) * Number(e.price)  | 
51 |  | -        }  | 
52 |  | -    });  | 
53 |  | -    const dailyVolume = historicalUSD.filter((e: IVolumeall) => e.timestamp === dayTimestamp)  | 
54 |  | -        .reduce((a: number, { volumeUSD }) => a + volumeUSD, 0);  | 
55 |  | -    return {  | 
56 |  | -        dailyVolume: dailyVolume,  | 
57 |  | -        openInterestAtEnd,  | 
58 |  | -    };  | 
59 |  | -};  | 
60 |  | - | 
61 | 3 | 
 
  | 
62 | 4 | const adapter: SimpleAdapter = {  | 
63 | 5 |     deadFrom: '2025-04-26', // https://apex-pro.gitbook.io/apex-pro/apex-pro-discontinued/about-apex-pro  | 
64 | 6 |     adapter: {  | 
65 | 7 |         [CHAIN.ETHEREUM]: {  | 
66 |  | -            fetch,  | 
 | 8 | +            fetch: () => { throw new Error("Apex Pro has been discontinued") },  | 
67 | 9 |             start: '2022-10-05',  | 
68 | 10 |         }  | 
69 | 11 |     },  | 
 | 
0 commit comments