Skip to content

Commit

Permalink
fix combince
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Feb 14, 2024
1 parent c0e3e04 commit fe889de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 57 deletions.
39 changes: 0 additions & 39 deletions dexs/demex-perp/index.ts

This file was deleted.

47 changes: 29 additions & 18 deletions dexs/demex/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
import fetchURL from "../../utils/fetchURL"
import { SimpleAdapter } from "../../adapters/types";
import fetchURL from "../../utils/fetchURL";
import { BreakdownAdapter, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const START_TIME = 1659312000;
const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats`
const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats`;

interface IVolumeall {
market_type: string;
day_quote_volume: string;
date: string;
}

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.marketstats;
const fetch = (market_type: string) => {
return async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.marketstats;

const volume = historicalVolume
.filter((e: IVolumeall) => e.market_type === "spot")
.reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18;
const volume =
historicalVolume
.filter((e: IVolumeall) => e.market_type === market_type)
.reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18;

return {
dailyVolume: volume ? `${volume}` : undefined,
timestamp: dayTimestamp,
return {
dailyVolume: volume ? `${volume}` : undefined,
timestamp: dayTimestamp,
};
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.CARBON]: {
fetch,
start: START_TIME,
const adapters: BreakdownAdapter = {
breakdown: {
demex: {
[CHAIN.CARBON]: {
fetch: fetch("spot"),
start: START_TIME,
},
},
"demex-perp": {
[CHAIN.CARBON]: {
fetch: fetch("futures"),
start: START_TIME,
},
}
},
};

export default adapter;
export default adapters;

0 comments on commit fe889de

Please sign in to comment.