From 89746fe5e6a004f2ac9c3e29a868d24e19235c1b Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 7 Dec 2024 20:58:51 +0100 Subject: [PATCH] init script with implementation plan and basic adex connection --- scripts/fetchKpis.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 scripts/fetchKpis.js diff --git a/scripts/fetchKpis.js b/scripts/fetchKpis.js new file mode 100644 index 00000000..c695a0e7 --- /dev/null +++ b/scripts/fetchKpis.js @@ -0,0 +1,53 @@ +/* eslint-disable no-console */ +const adex = require("alphadex-sdk-js"); + +// Welcome developer +console.log("Hi 👋\nStarting script to fetch KPIs..."); + +// call the init function to connect to the AlphaDEX exchange +// and initialize the clientState object +adex.init(); + +// assign the clientState object to a local variable +let myAdexState = adex.clientState; + +console.log(myAdexState); + +// IMPLEMENTATION PLAN + +// Script Pseudocode +// Step 0a: Verify if the user provided an input parameter for the script. +// Supported parameter: `weeksBack`, which indicates how many weeks to look back. +// weeksBack=1 means last week only, weeksBack=10 means the last 10 weeks +// (excluding the current week). If no parameter was provided, set to 1. +// Step 0b: initialize resultDict: Key=DateString, value=VolumeData for that week +// Step 1 : Initialize connection to alphadex +// Step 2a: Fetch all available pairs for DeXter (PlatformId=4) +// Step 2b: Create and populate a pairAddress -> pairName dictionary +// Step 3 : Get lastWeeks array +// Step 4 : For each week, do this: +// Step 5 : For each pair, do this: +// Step 6 : a) set currentSelectedPair to the pair +// b) set canclePeriod to 1W +// c) get the pairName based on the pairAddress +// d) get Volume of that week from candle stick data +// and set resultDict[weekStr][pairName]: volume + +// Helper functions needed +// getLastWeeks(n: number): Date[] +// -> returns array of dates, each date represents the start of a week (Monday). +// -> the current week is not included +// -> if run without parameters, it returns a sigle date, which is last weeks monday +// -> we return last week, because the ongoing week is not finished yet + +// dateToUnixTimestamp(date: Date): number +// -> Number(date) -> returns unix timestamp of a date + +// dateToDateStr(date: Date, returnFormat: "DD-MM-YYYY" | "YYYY-MM-DD): string +// -> returns the date in the specified return format: +// - DD-MM-YYYY (needed for coingecko historic API) +// - YYYY-MM-DD (needed for google sheet KPI tracking) + +// Coingecko.getHistoricPrice(date: string, coinId: string): number +// -> given date (day in the format "31-12-2023") and the coinSlug (e.g. "radix") +// returns the historic USD price on that day.