refactor: exchanges config validation and error handling

This commit is contained in:
José Oliveira 2021-05-11 18:57:46 +01:00 committed by Josh Harvey
parent 60a19af1a8
commit dabe21f834
6 changed files with 34 additions and 20 deletions

View file

@ -10,6 +10,7 @@ function ticker (fiatCode, cryptoCode, tickerName) {
if (verifyFiatSupport(fiatCode, tickerName)) {
return getCurrencyRates(ticker, fiatCode, cryptoCode)
}
return axios.get('https://bitpay.com/rates')
.then(response => {
try {
@ -32,16 +33,17 @@ function ticker (fiatCode, cryptoCode, tickerName) {
function getCurrencyRates (ticker, fiatCode, cryptoCode) {
try {
if (ticker.has['fetchTicker']) {
const symbol = buildMarket(fiatCode, cryptoCode, ticker.id)
return ticker.fetchTicker(symbol)
.then(res => ({
rates: {
ask: BN(res.ask),
bid: BN(res.bid)
}
}))
if (!ticker.has['fetchTicker']) {
throw new Error('Ticker not available')
}
const symbol = buildMarket(fiatCode, cryptoCode, ticker.id)
return ticker.fetchTicker(symbol)
.then(res => ({
rates: {
ask: BN(res.ask),
bid: BN(res.bid)
}
}))
} catch (e) {
return Promise.reject(e)
}