Skip to content

Commit

Permalink
fix anyhedge
Browse files Browse the repository at this point in the history
  • Loading branch information
A60AB5450353F40E committed Mar 16, 2024
1 parent d0f48be commit d061710
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions dexs/anyhedge/index.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
import { SimpleAdapter } from "../../adapters/types";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import fetchURL from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";
import { getTimestampAtStartOfNextDayUTC } from "../../utils/date";

const methodology = {
DailyVolume: "Scan the blockchain for AnyHedge input pattern, add up all such inputs BCH value. The daily volume is the volume of all settled contracts for the day."
Volume: "Scan the blockchain for AnyHedge input pattern, add up all such inputs BCH value. The daily volume is the volume of all settled contracts for the day. Indexer: https://gitlab.com/0353F40E/anyhedge-stats",
Fees: "N/A",
Revenue: "N/A",
}

interface IAnyhedgeVolumeResponse {
daily_volume: number;
total_volume: number;
}

// endDay formatted as 2011-12-13
export const anyhedgeVolumeEndpoint = (endDay: string) => {
// day formatted as 2011-12-13
export const anyhedgeVolumeEndpoint = (day: string) => {
// Data & calculation method is fully reproducible, see:
// https://gitlab.com/0353F40E/anyhedge-stats/-/blob/master/readme.md
return "https://gitlab.com/0353F40E/anyhedge-stats/-/raw/master/stats_daily/" + endDay + ".csv";
return "https://gitlab.com/0353F40E/anyhedge-stats/-/raw/master/stats_daily/" + day + ".csv";
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BITCOIN_CASH]: {
fetch: fetchAnyhedgeVolumeData,
start: 1654787405,
meta: {
methodology
}
},
},
};

export async function fetchAnyhedgeVolumeData(
/** Timestamp representing the end of the 24 hour period */
timestamp: number
) {
const fetchAnyhedgeVolumeData: Fetch = async (timestamp: number, _: ChainBlocks, options: FetchOptions) => {
const dayString = new Date(timestamp * 1000).toISOString().slice(0,10);
const anyhedgeVolumeData = await getAnyhedgeVolumeData(anyhedgeVolumeEndpoint(dayString));

const dailyVolume = Number(anyhedgeVolumeData?.daily_volume);
const totalVolume = Number(anyhedgeVolumeData?.total_volume);

const dailyVolume = options.createBalances();
const totalVolume = options.createBalances();
dailyVolume.addCGToken('bitcoin-cash', Number(anyhedgeVolumeData?.daily_volume));
totalVolume.addCGToken('bitcoin-cash', Number(anyhedgeVolumeData?.total_volume));

return {
timestamp,
Expand Down Expand Up @@ -76,4 +65,15 @@ function toObject(keys, values) {
return res
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BITCOIN_CASH]: {
fetch: fetchAnyhedgeVolumeData,
start: 1654787405,
meta: {
methodology
}
},
},
};
export default adapter;

0 comments on commit d061710

Please sign in to comment.