don't fail completely if one coin is down
This commit is contained in:
parent
29759fe132
commit
aa4e471364
3 changed files with 12 additions and 27 deletions
|
|
@ -589,7 +589,7 @@ function pollRate (cryptoCode, cb) {
|
||||||
return cb && cb(err)
|
return cb && cb(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resRates.timestamp = new Date()
|
resRates.timestamp = Date.now()
|
||||||
var rates = resRates[deviceCurrency].rates
|
var rates = resRates[deviceCurrency].rates
|
||||||
if (rates) {
|
if (rates) {
|
||||||
rates.ask = rates.ask && new BigNumber(rates.ask)
|
rates.ask = rates.ask && new BigNumber(rates.ask)
|
||||||
|
|
@ -608,8 +608,6 @@ function pollRate (cryptoCode, cb) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getDeviceRate = function getDeviceRate (cryptoCode) {
|
exports.getDeviceRate = function getDeviceRate (cryptoCode) {
|
||||||
if (!lastRates[cryptoCode]) return null
|
|
||||||
|
|
||||||
var lastRate = lastRates[cryptoCode]
|
var lastRate = lastRates[cryptoCode]
|
||||||
if (!lastRate) return null
|
if (!lastRate) return null
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
var BigNumber = require('bignumber.js')
|
var BigNumber = require('bignumber.js')
|
||||||
var logger = require('./logger')
|
var logger = require('./logger')
|
||||||
|
|
||||||
var E = require('./error')
|
|
||||||
|
|
||||||
var mock = false
|
var mock = false
|
||||||
|
|
||||||
var plugins
|
var plugins
|
||||||
|
|
@ -15,12 +13,8 @@ module.exports = {
|
||||||
getFingerprint: getFingerprint
|
getFingerprint: getFingerprint
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
var STALE_TICKER = 10 * 60 * 1000
|
||||||
// Make sure these are higher than polling interval
|
var STALE_BALANCE = 10 * 60 * 1000
|
||||||
// or there will be a lot of errors
|
|
||||||
var STALE_TICKER = 180000
|
|
||||||
var STALE_BALANCE = 180000
|
|
||||||
*/
|
|
||||||
|
|
||||||
var pids = {}
|
var pids = {}
|
||||||
var reboots = {}
|
var reboots = {}
|
||||||
|
|
@ -36,7 +30,8 @@ function buildRates () {
|
||||||
var rates = {}
|
var rates = {}
|
||||||
cryptoCodes.forEach(function (cryptoCode) {
|
cryptoCodes.forEach(function (cryptoCode) {
|
||||||
var _rate = plugins.getDeviceRate(cryptoCode)
|
var _rate = plugins.getDeviceRate(cryptoCode)
|
||||||
if (!_rate) throw new E.NoDataError('No rate for ' + cryptoCode + ' yet')
|
if (!_rate) return logger.warn('No rate for ' + cryptoCode + ' yet')
|
||||||
|
if (Date.now() - _rate.timestamp > STALE_TICKER) return logger.warn('Stale rate for ' + cryptoCode)
|
||||||
var rate = _rate.rates
|
var rate = _rate.rates
|
||||||
rates[cryptoCode] = {
|
rates[cryptoCode] = {
|
||||||
cashIn: rate.ask.times(cashInCommission),
|
cashIn: rate.ask.times(cashInCommission),
|
||||||
|
|
@ -53,7 +48,8 @@ function buildBalances () {
|
||||||
var _balances = {}
|
var _balances = {}
|
||||||
cryptoCodes.forEach(function (cryptoCode) {
|
cryptoCodes.forEach(function (cryptoCode) {
|
||||||
var balance = plugins.fiatBalance(cryptoCode)
|
var balance = plugins.fiatBalance(cryptoCode)
|
||||||
if (!balance) throw new E.NoDataError('No balance for ' + cryptoCode + ' yet')
|
if (!balance) return logger.warn('No balance for ' + cryptoCode + ' yet')
|
||||||
|
if (Date.now() - balance.timestamp > STALE_BALANCE) return logger.warn('Stale balance for ' + cryptoCode)
|
||||||
_balances[cryptoCode] = balance
|
_balances[cryptoCode] = balance
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -68,18 +64,11 @@ function poll (req, res) {
|
||||||
|
|
||||||
// logger.debug('poll request from: %s', fingerprint)
|
// logger.debug('poll request from: %s', fingerprint)
|
||||||
|
|
||||||
var rates
|
var rates = {}
|
||||||
var balances
|
var balances = {}
|
||||||
|
|
||||||
try {
|
rates = buildRates()
|
||||||
rates = buildRates()
|
balances = buildBalances()
|
||||||
balances = buildBalances()
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof E.NoDataError) {
|
|
||||||
logger.debug(e)
|
|
||||||
return res.sendStatus(500)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var config = plugins.getConfig()
|
var config = plugins.getConfig()
|
||||||
var settings = config.exchanges.settings
|
var settings = config.exchanges.settings
|
||||||
|
|
@ -93,9 +82,6 @@ function poll (req, res) {
|
||||||
|
|
||||||
var response = {
|
var response = {
|
||||||
err: null,
|
err: null,
|
||||||
rate: rates.BTC.cashIn,
|
|
||||||
fiatRate: rates.BTC.cashOut,
|
|
||||||
fiat: balances.BTC,
|
|
||||||
locale: config.brain.locale,
|
locale: config.brain.locale,
|
||||||
txLimit: parseInt(complianceSettings.maximum.limit, 10),
|
txLimit: parseInt(complianceSettings.maximum.limit, 10),
|
||||||
idVerificationEnabled: complianceSettings.idVerificationEnabled,
|
idVerificationEnabled: complianceSettings.idVerificationEnabled,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
"node-uuid": "^1.4.2",
|
"node-uuid": "^1.4.2",
|
||||||
"numeral": "^1.5.3",
|
"numeral": "^1.5.3",
|
||||||
"pg": "^4.5.1",
|
"pg": "^4.5.1",
|
||||||
|
"pg-promise": "^4.2.4",
|
||||||
"pretty-ms": "^2.1.0",
|
"pretty-ms": "^2.1.0",
|
||||||
"ramda": "^0.21.0",
|
"ramda": "^0.21.0",
|
||||||
"wreck": "5.1.0"
|
"wreck": "5.1.0"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue