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 = {}
|
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) {
|
function ticker (fiatCode, cryptoCode, tickerName) {
|
||||||
if (!tickerObjects[tickerName]) {
|
if (!tickerObjects[tickerName]) {
|
||||||
tickerObjects[tickerName] = new ccxt[tickerName]({
|
tickerObjects[tickerName] = new ccxt[tickerName]({
|
||||||
|
|
@ -45,12 +53,15 @@ function getCurrencyRates (ticker, fiatCode, cryptoCode) {
|
||||||
}
|
}
|
||||||
const symbol = buildMarket(fiatCode, cryptoCode, ticker.id)
|
const symbol = buildMarket(fiatCode, cryptoCode, ticker.id)
|
||||||
return ticker.fetchTicker(symbol)
|
return ticker.fetchTicker(symbol)
|
||||||
.then(res => ({
|
.then(res => {
|
||||||
rates: {
|
sanityCheckRates(res.ask, res.bid, cryptoCode)
|
||||||
ask: new BN(res.ask),
|
return {
|
||||||
bid: new BN(res.bid)
|
rates: {
|
||||||
|
ask: new BN(res.ask),
|
||||||
|
bid: new BN(res.bid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue