fix: sanity checks on ccxt responses
This commit is contained in:
parent
7b96ed966a
commit
3fe3fed203
1 changed files with 16 additions and 5 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue