Skip to content

Commit

Permalink
Merge pull request #1732 from RodeRickIsWatching/feat/apex-omni
Browse files Browse the repository at this point in the history
Add Apex-omni fee&volume
  • Loading branch information
dtmkeng committed Aug 1, 2024
2 parents d2dc7a8 + f42e284 commit 9b74a3d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
66 changes: 66 additions & 0 deletions dexs/apex-omni/index.ts
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;
30 changes: 30 additions & 0 deletions fees/apex-omni.ts
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;

0 comments on commit 9b74a3d

Please sign in to comment.