Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"test-integration": "playwright test",
"test-all": "npm run lint && npm run test && npm run test-integration",
"copy-pr": "node ./scripts/copy-pr.js",
"fetchUsers": "node ./scripts/fetchUsers.js"
"fetchUsers": "node ./scripts/fetchUsers.js",
"fetchKpis": "node ./scripts/fetchKpis.js"
},
"dependencies": {
"@mdx-js/loader": "^3.0.0",
Expand Down
53 changes: 53 additions & 0 deletions scripts/fetchKpis.js
Original file line number Diff line number Diff line change
@@ -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.