From 3fe3fed20344a69659ce341bab78afa5813b29af Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Tue, 31 Oct 2023 18:25:59 +0000 Subject: [PATCH] fix: sanity checks on ccxt responses --- lib/plugins/ticker/ccxt.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/plugins/ticker/ccxt.js b/lib/plugins/ticker/ccxt.js index 080b2f18..336ef8a3 100644 --- a/lib/plugins/ticker/ccxt.js +++ b/lib/plugins/ticker/ccxt.js @@ -8,6 +8,14 @@ const RETRIES = 2 const tickerObjects = {} +// This is probably fixed on upstream ccxt +// but we need to udpate node to get on the latest version +const sanityCheckRates = (ask, bid, tickerName) => { + if (new BN(0).eq(ask) || new BN(0).eq(bid)) { + throw new Error(`Failure fetching rates for ${tickerName}`) + } +} + function ticker (fiatCode, cryptoCode, tickerName) { if (!tickerObjects[tickerName]) { tickerObjects[tickerName] = new ccxt[tickerName]({ @@ -45,12 +53,15 @@ function getCurrencyRates (ticker, fiatCode, cryptoCode) { } const symbol = buildMarket(fiatCode, cryptoCode, ticker.id) return ticker.fetchTicker(symbol) - .then(res => ({ - rates: { - ask: new BN(res.ask), - bid: new BN(res.bid) + .then(res => { + sanityCheckRates(res.ask, res.bid, cryptoCode) + return { + rates: { + ask: new BN(res.ask), + bid: new BN(res.bid) + } } - })) + }) } catch (e) { return Promise.reject(e) }