Skip to content

Commit

Permalink
add main function to fetch all market cap data (#79)
Browse files Browse the repository at this point in the history
* add main function to fetch all market cap data

* write output to temp file

* use backoff

Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>

* fix format

Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>

---------

Signed-off-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
Co-authored-by: Nguyen Le Vu Long <vulongvn98@gmail.com>
  • Loading branch information
h2physics and longngn authored Jun 23, 2023
1 parent 3bb2c51 commit 82e270a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Internal files used by Minswap team
35 changes: 35 additions & 0 deletions internal/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { backOff } from "exponential-backoff";
import fs from "fs";

import { SupplyFetcherResponse, supplyFetchers } from "../src";

async function main(): Promise<void> {
const marketCapData: Record<string, SupplyFetcherResponse> = {};
for (const [key, supplyFetcher] of Object.entries(supplyFetchers)) {
try {
await backOff(
async () => {
const data = await supplyFetcher();
marketCapData[key] = data;
},
{
retry(err, attempt): boolean {
// eslint-disable-next-line no-console
console.error(
`fail to run fetcher for ${key}, retry ${attempt}...`,
err
);
return true;
},
numOfAttempts: 3,
}
);
} catch (err) {
// eslint-disable-next-line no-console
console.error(`fail to run fetcher for ${key}`, err);
}
}
fs.writeFileSync("/tmp/market-cap.json", JSON.stringify(marketCapData));
}

void main();
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"build": "rimraf build && rollup -c rollup.config.js",
"test": "jest",
"format": "prettier --write **/*.{ts,tsx} && eslint --fix --ext .ts,.tsx .",
"check-format": "prettier --check **/*.{ts,tsx} && eslint --ext .ts,.tsx ."
"check-format": "prettier --check **/*.{ts,tsx} && eslint --ext .ts,.tsx .",
"run-market-cap": "ts-node internal/main.ts"
},
"keywords": [
"minswap",
Expand Down Expand Up @@ -46,6 +47,7 @@
"eslint": "^8.34.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"exponential-backoff": "^3.1.1",
"jest": "^29.4.2",
"prettier": "^2.8.4",
"rollup": "^2.70.2",
Expand Down

0 comments on commit 82e270a

Please sign in to comment.