-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1732 from RodeRickIsWatching/feat/apex-omni
Add Apex-omni fee&volume
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import fetchURL from "../../utils/fetchURL" | ||
import { SimpleAdapter, Fetch } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
|
||
const historicalVolumeEndpoint = (symbol: string, endTime: number) => `https://omni.apex.exchange/api/v3/klines?end=${endTime}&interval=D&start=1718380800&symbol=${symbol}&limit=10` | ||
const allTiker = (symbol: string) => `https://omni.apex.exchange/api/v3/ticker?symbol=${symbol}` | ||
const getSumbols = async ()=>{ | ||
const res = await fetchURL('https://omni.apex.exchange/api/v3/symbols') | ||
const symbol = res?.data?.contractConfig?.perpetualContract?.map((i: any)=>i?.crossSymbolName) | ||
return symbol || [] | ||
} | ||
interface IVolumeall { | ||
id: string; | ||
volume: string; | ||
timestamp: number; | ||
price: string; | ||
volumeUSD: number; | ||
} | ||
|
||
interface IOpenInterest { | ||
id: string; | ||
openInterest: string; | ||
lastPrice: string; | ||
} | ||
|
||
const getVolume = async (timestamp: number) => { | ||
const _symbol: string[] = await getSumbols() | ||
const symbol = [...new Set(_symbol)] | ||
|
||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) | ||
const historical: any[] = (await Promise.all(symbol.map((coins: string) => fetchURL(historicalVolumeEndpoint(coins, dayTimestamp + 60 * 60 * 24))))) | ||
.map((e: any) => Object.values(e.data)).flat().flat() | ||
.map((e: any) => { return { timestamp: e.t / 1000, volume: e.v, price: e.c } }); | ||
const openInterestHistorical: IOpenInterest[] = (await Promise.all(symbol.map((coins: string) => fetchURL(allTiker(coins))))) | ||
.map((e: any) => e.data).flat().map((e: any) => { return { id: e.symbol, openInterest: e.openInterest, lastPrice: e.lastPrice } }); | ||
const dailyOpenInterest = openInterestHistorical.reduce((a: number, { openInterest, lastPrice }) => a + Number(openInterest) * Number(lastPrice), 0); | ||
const historicalUSD = historical.map((e: IVolumeall) => { | ||
return { | ||
...e, | ||
volumeUSD: Number(e.volume) * Number(e.price) | ||
} | ||
}); | ||
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) | ||
.reduce((a: number, { volumeUSD }) => a + volumeUSD, 0); | ||
|
||
return { | ||
totalVolume: `${totalVolume}`, | ||
dailyOpenInterest: `${dailyOpenInterest}`, | ||
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined, | ||
timestamp: dayTimestamp, | ||
}; | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.ETHEREUM]: { | ||
fetch: getVolume, | ||
start: 1718380800, | ||
} | ||
}, | ||
}; | ||
|
||
export default adapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FetchResultFees, SimpleAdapter } from "../adapters/types" | ||
import { CHAIN } from "../helpers/chains"; | ||
import { getTimestampAtStartOfDayUTC } from "../utils/date" | ||
import fetchURL from "../utils/fetchURL" | ||
|
||
|
||
interface IFees { | ||
feeOfDate: string; | ||
} | ||
const fees = async (timestamp: number): Promise<FetchResultFees> => { | ||
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp) * 1000; | ||
const url = `https://omni.apex.exchange/api/v3/data/fee-by-date?time=${todaysTimestamp}`; | ||
const feesData: IFees = (await fetchURL(url)).data; | ||
const dailyFees = feesData?.feeOfDate || '0'; | ||
return { | ||
dailyFees: dailyFees, | ||
dailyUserFees: dailyFees, | ||
timestamp | ||
} | ||
} | ||
const adapter: SimpleAdapter = { | ||
version: 1, | ||
adapter: { | ||
[CHAIN.ETHEREUM]: { | ||
fetch: fees, | ||
start: 1693440000, | ||
} | ||
} | ||
} | ||
export default adapter; |