Fix double CMC api calls being made and set the timeout to 6mins to stay under the hard cap this month

This commit is contained in:
Marco van Dijk 2022-03-07 11:19:06 +01:00
parent 157c6677ea
commit da4b365397

View File

@ -23,7 +23,7 @@ const web3layer2 = createAlchemyWeb3(API_L2_HTTP);
const web3layer2WS = createAlchemyWeb3(API_L2_WS); const web3layer2WS = createAlchemyWeb3(API_L2_WS);
// Update CoinMarketCap related api calls every 5 minutes // Update CoinMarketCap related api calls every 5 minutes
const timeoutCMC = 300000; const timeoutCMC = 360000;
let cmcPriceGet = 0; let cmcPriceGet = 0;
let ethPrice = 0; let ethPrice = 0;
let lptPrice = 0; let lptPrice = 0;
@ -334,8 +334,8 @@ apiRouter.get("/cmc", async (req, res) => {
const now = new Date().getTime(); const now = new Date().getTime();
// Update cmc once their data has expired // Update cmc once their data has expired
if (now - cmcPriceGet > timeoutCMC) { if (now - cmcPriceGet > timeoutCMC) {
await parseCmc();
cmcPriceGet = now; cmcPriceGet = now;
await parseCmc();
} }
res.send(cmcCache); res.send(cmcCache);
} catch (err) { } catch (err) {
@ -349,8 +349,8 @@ apiRouter.get("/blockchains", async (req, res) => {
const now = new Date().getTime(); const now = new Date().getTime();
// Update blockchain data if the cached data has expired // Update blockchain data if the cached data has expired
if (now - arbGet > timeoutAlchemy) { if (now - arbGet > timeoutAlchemy) {
await parseEthBlockchain();
arbGet = now; arbGet = now;
await parseEthBlockchain();
} }
res.send({ res.send({
timestamp: now, timestamp: now,
@ -383,9 +383,8 @@ apiRouter.get("/quotes", async (req, res) => {
const now = new Date().getTime(); const now = new Date().getTime();
// Update cmc once their data has expired // Update cmc once their data has expired
if (now - cmcPriceGet > timeoutCMC) { if (now - cmcPriceGet > timeoutCMC) {
cmcCache = await cmcClient.getTickers({ limit: 200 });
await parseCmc();
cmcPriceGet = now; cmcPriceGet = now;
await parseCmc();
} }
res.send(cmcQuotes); res.send(cmcQuotes);
} catch (err) { } catch (err) {