fix startup bug where rates weren't available
This commit is contained in:
parent
5418498d06
commit
c4cbe0f6bb
3 changed files with 31 additions and 17 deletions
|
|
@ -3,6 +3,8 @@
|
|||
var BigNumber = require('bignumber.js')
|
||||
var logger = require('./logger')
|
||||
|
||||
var E = require('./error')
|
||||
|
||||
var mock = false
|
||||
|
||||
var plugins
|
||||
|
|
@ -34,7 +36,7 @@ function buildRates () {
|
|||
var rates = {}
|
||||
cryptoCodes.forEach(function (cryptoCode) {
|
||||
var _rate = plugins.getDeviceRate(cryptoCode)
|
||||
if (!_rate) return
|
||||
if (!_rate) throw new E.NoDataError('No rate for ' + cryptoCode + ' yet')
|
||||
var rate = _rate.rates
|
||||
rates[cryptoCode] = {
|
||||
cashIn: rate.ask.times(cashInCommission),
|
||||
|
|
@ -51,6 +53,7 @@ function buildBalances () {
|
|||
var _balances = {}
|
||||
cryptoCodes.forEach(function (cryptoCode) {
|
||||
var balance = plugins.fiatBalance(cryptoCode)
|
||||
if (!balance) throw new E.NoDataError('No balance for ' + cryptoCode + ' yet')
|
||||
_balances[cryptoCode] = balance
|
||||
})
|
||||
|
||||
|
|
@ -65,8 +68,18 @@ function poll (req, res) {
|
|||
|
||||
logger.debug('poll request from: %s', fingerprint)
|
||||
|
||||
var rates = buildRates()
|
||||
var balances = buildBalances()
|
||||
var rates
|
||||
var balances
|
||||
|
||||
try {
|
||||
rates = buildRates()
|
||||
balances = buildBalances()
|
||||
} catch (e) {
|
||||
if (e instanceof E.NoDataError) {
|
||||
logger.debug(e)
|
||||
return res.send(500)
|
||||
}
|
||||
}
|
||||
|
||||
var config = plugins.getConfig()
|
||||
var settings = config.exchanges.settings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue