Skip to content

Commit

Permalink
Refresh perpetual markets cache markets are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfraser committed Nov 25, 2024
1 parent c31a393 commit 77190e4
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ import { redisClient } from '../helpers/redis';
*/
export default async function runTask(): Promise<void> {
try {
const perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap());
const marketTickers = perpetualMarkets.map(
let perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap());
let marketTickers = perpetualMarkets.map(
(market: PerpetualMarketFromDatabase) => market.ticker,
);

// If no markets found, try updating the perpetual markets cache and fetch again
if (marketTickers.length === 0) {
throw new Error('perpetualMarketRefresher is empty');
await perpetualMarketRefresher.updatePerpetualMarkets();
perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap());
marketTickers = perpetualMarkets.map(
(market: PerpetualMarketFromDatabase) => market.ticker,
);

if (marketTickers.length === 0) {
throw new Error('perpetualMarketRefresher is empty');
}
}

logger.info({
Expand Down

0 comments on commit 77190e4

Please sign in to comment.