Skip to content

Commit

Permalink
add obyte vol
Browse files Browse the repository at this point in the history
  • Loading branch information
Taump committed Mar 2, 2023
1 parent 7d5693d commit cea106e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
90 changes: 90 additions & 0 deletions dexs/oswap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import axios from "axios";

import type { SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../helpers/chains";

interface ITicker {
full_market_name: string;
quote_symbol: string;
base_symbol: string;
quote_id: string;
base_id: string;
lowest_price_24h: number;
highest_price_24h: number;
last_price: number;
quote_volume: number;
base_volume: number;
}

interface ITickers {
[market_full_name: string]: ITicker;
}


interface IExchangeRates {
[key: string]: number;
}


const OSWAP_STATS_ENDPOINT = "http://localhost:4200/api/v1";

const getTickers = async () => {
const tickers: ITickers = (await axios.get(`${OSWAP_STATS_ENDPOINT}/tickers`))?.data;
return Object.values(tickers);
}

const getExchangeRates = async () => {
const exchangeRates: IExchangeRates = (await axios.get(`${OSWAP_STATS_ENDPOINT}/exchangeRates`))?.data;

return exchangeRates;
}


const getDailyVolume = async () => {
const tickers = await getTickers();
const exchangeRates = await getExchangeRates();

const volume = tickers.reduce((acc, { base_id, quote_id, quote_volume, base_volume }) => {
let volumeInUSD = 0;
const assetId0 = base_id === "base" ? "GBYTE" : base_id;
const assetId1 = quote_id === "base" ? "GBYTE" : quote_id;

if (exchangeRates[`${assetId0}_USD`]) {
volumeInUSD = exchangeRates[`${assetId0}_USD`] * base_volume;
} else if (exchangeRates[`${assetId1}_USD`]) {
volumeInUSD = exchangeRates[`${assetId1}_USD`] * quote_volume;
}

return acc + volumeInUSD;
}, 0);

return volume;
}


const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dailyVolume = await getDailyVolume();

return {
timestamp: dayTimestamp,
dailyVolume: dailyVolume.toString(),
}
}

const getStartTimestamp = async () => {
return 0;
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.OBYTE]: {
start: getStartTimestamp,
runAtCurrTime: true,
fetch: fetch
}
}
};

export default adapter;
3 changes: 2 additions & 1 deletion helpers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export enum CHAIN {
ARBITRUM_NOVA = "arbitrum_nova",
INJECTIVE = "injective",
ORAI = "orai",
TON = "ton"
TON = "ton",
OBYTE = "obyte"
}

// Don´t use
Expand Down

0 comments on commit cea106e

Please sign in to comment.