Skip to content

Commit 20e5737

Browse files
committed
script
1 parent f4e6f43 commit 20e5737

File tree

2 files changed

+245
-121
lines changed

2 files changed

+245
-121
lines changed

src/utils/prices.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const axios = require("axios");
44
const retry = require("async-retry");
55

66
const maxNumberOfPrices = 150;
7+
const REQUEST_TIMEOUT = 30_000;
8+
const RETRY_OPTS = { retries: 3, minTimeout: 1000, maxTimeout: 5000 };
79

810
export const getSingleLlamaPrice = async (
911
chain: string,
@@ -14,7 +16,8 @@ export const getSingleLlamaPrice = async (
1416
const url = timestamp
1517
? PRICES_API + `/historical/${timestamp}/${chain}:${token}`
1618
: PRICES_API + `/current/${chain}:${token}`;
17-
const res = await retry(async (_bail: any) => await axios.get(url));
19+
20+
const res = await retry(async (_bail: any) => await axios.get(url, { timeout: REQUEST_TIMEOUT }), RETRY_OPTS);
1821
const price = res?.data?.coins?.[`${chain}:${token}`];
1922
if (!confidenceThreshold || !price || price.confidence > confidenceThreshold) {
2023
return price;
@@ -39,9 +42,13 @@ export const getLlamaPrices = async (tokens: string[], timestamp?: number): Prom
3942
const url = timestamp
4043
? `${PRICES_API}/historical/${timestamp}/${remainingTokens.slice(0, maxNumberOfPrices).join(",")}`
4144
: `${PRICES_API}/current/${remainingTokens.slice(0, maxNumberOfPrices).join(",")}`;
42-
const res = await retry(async () => await axios.get(url));
43-
const prices = res?.data?.coins;
44-
Object.assign(finalPrices, prices);
45+
try {
46+
const res = await retry(async () => await axios.get(url, { timeout: REQUEST_TIMEOUT }), RETRY_OPTS);
47+
const prices = res?.data?.coins;
48+
Object.assign(finalPrices, prices);
49+
} catch (e) {
50+
console.error(`[PRICES] Failed fetching prices for batch after retries, skipping batch. ${(e as any)?.message}`);
51+
}
4552
remainingTokens = remainingTokens.slice(maxNumberOfPrices);
4653
}
4754

@@ -65,4 +72,3 @@ function splitOnce(input: string, separator: string): string[] {
6572
const part2 = input.substring(index + separator.length);
6673
return [part1, part2];
6774
}
68-

0 commit comments

Comments
 (0)