better handling of ticker errors
This commit is contained in:
parent
e4888da2f3
commit
fafac16742
2 changed files with 15 additions and 0 deletions
|
|
@ -38,6 +38,8 @@ function plugins (settings, deviceId) {
|
|||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||
const rateRec = tickers[i]
|
||||
|
||||
if (!rateRec) return
|
||||
|
||||
const cashInCommission = BN(1).add(BN(cryptoConfig.cashInCommission).div(100))
|
||||
|
||||
const cashOutCommission = _.isNil(cryptoConfig.cashOutCommission)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
const mem = require('mem')
|
||||
const configManager = require('./config-manager')
|
||||
const ph = require('./plugin-helper')
|
||||
const logger = require('./logger')
|
||||
|
||||
const lastRate = {}
|
||||
|
||||
const FETCH_INTERVAL = 10000
|
||||
function getRates (settings, fiatCode, cryptoCode) {
|
||||
|
|
@ -12,11 +15,21 @@ function getRates (settings, fiatCode, cryptoCode) {
|
|||
const account = settings.accounts[plugin]
|
||||
const ticker = ph.load(ph.TICKER, plugin)
|
||||
|
||||
const market = [cryptoCode, fiatCode].join('-')
|
||||
|
||||
return ticker.ticker(account, fiatCode, cryptoCode)
|
||||
.then(r => ({
|
||||
rates: r.rates,
|
||||
timestamp: Date.now()
|
||||
}))
|
||||
.then(r => {
|
||||
lastRate[market] = r
|
||||
return r
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error(err)
|
||||
return lastRate[market]
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue