WIP
This commit is contained in:
parent
d9f64fd4d3
commit
dc923829e3
2 changed files with 12 additions and 11 deletions
|
|
@ -34,7 +34,6 @@ const SWEEP_LIVE_HD_INTERVAL = T.minute
|
|||
const SWEEP_OLD_HD_INTERVAL = 2 * T.minutes
|
||||
const TRADE_INTERVAL = T.minute
|
||||
const TRADE_TTL = 5 * T.minutes
|
||||
const LOW_BALANCE_MARGIN_DEFAULT = 1.05
|
||||
|
||||
const tickerPlugins = {}
|
||||
const traderPlugins = {}
|
||||
|
|
@ -301,12 +300,8 @@ function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) {
|
|||
const walletPlugin = walletPlugins[cryptoCode]
|
||||
const transactionFee = null
|
||||
|
||||
if (cryptoCode === 'BTC') {
|
||||
walletPlugin.sendBitcoins(toAddress, cryptoAtoms.truncated().toNumber(), transactionFee, cb)
|
||||
} else {
|
||||
walletPlugin.sendBitcoins(toAddress, cryptoAtoms, cryptoCode, transactionFee, cb)
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: This will fail if we have already sent coins because there will be
|
||||
// a db unique db record in the table already.
|
||||
|
|
@ -410,11 +405,13 @@ exports.dispenseAck = function (deviceId, tx) {
|
|||
exports.fiatBalance = function fiatBalance (cryptoCode, deviceId) {
|
||||
const config = configManager.scoped(cryptoCode, deviceId, cachedConfig)
|
||||
const deviceRate = exports.getDeviceRate(cryptoCode)
|
||||
|
||||
if (!deviceRate) return null
|
||||
const rawRate = deviceRate.rates.ask
|
||||
const commission = new BigNumber(config.commissions.cashInCommission).div(100)
|
||||
const commission = (new BigNumber(config.commissions.cashInCommission).div(100)).plus(1)
|
||||
const lastBalanceRec = lastBalances[cryptoCode]
|
||||
if (!lastBalanceRec) return null
|
||||
|
||||
const lastBalance = lastBalanceRec.balance
|
||||
|
||||
if (!rawRate || !lastBalance) return null
|
||||
|
|
@ -424,7 +421,7 @@ exports.fiatBalance = function fiatBalance (cryptoCode, deviceId) {
|
|||
|
||||
// `lowBalanceMargin` is our safety net. It's a number > 1, and we divide
|
||||
// all our balances by it to provide a safety margin.
|
||||
const lowBalanceMargin = config.commissions.lowBalanceMargin || LOW_BALANCE_MARGIN_DEFAULT
|
||||
const lowBalanceMargin = (new BigNumber(config.commissions.lowBalanceMargin).div(100)).plus(1)
|
||||
|
||||
const unitScale = new BigNumber(10).pow(coins[cryptoCode].unitScale)
|
||||
const fiatTransferBalance = lastBalance.div(unitScale).times(rate).div(lowBalanceMargin)
|
||||
|
|
@ -543,8 +540,11 @@ function pollBalance (cryptoCode, cb) {
|
|||
return cb && cb(err)
|
||||
}
|
||||
|
||||
logger.debug('[%s] Balance update: %j', cryptoCode, balance)
|
||||
lastBalances[cryptoCode] = {timestamp: Date.now(), balance: new BigNumber(balance[cryptoCode])}
|
||||
const unitScale = new BigNumber(10).pow(coins[cryptoCode].unitScale)
|
||||
const coinBalance = new BigNumber(balance[cryptoCode])
|
||||
const scaledCoinBalance = coinBalance.div(unitScale)
|
||||
logger.debug('[%s] Balance update: %s', cryptoCode, scaledCoinBalance.toString())
|
||||
lastBalances[cryptoCode] = {timestamp: Date.now(), balance: coinBalance}
|
||||
|
||||
return cb && cb(null, lastBalances)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ function buildBalances (deviceId) {
|
|||
const balanceRec = plugins.fiatBalance(cryptoCode, deviceId)
|
||||
if (!balanceRec) return logger.warn('No balance for ' + cryptoCode + ' yet')
|
||||
if (Date.now() - balanceRec.timestamp > STALE_BALANCE) return logger.warn('Stale balance for ' + cryptoCode)
|
||||
|
||||
_balances[cryptoCode] = balanceRec.balance
|
||||
})
|
||||
|
||||
|
|
@ -102,7 +103,7 @@ function poll (req, res) {
|
|||
reboot,
|
||||
rates,
|
||||
balances,
|
||||
coins: config.currencies.cryptos
|
||||
coins: config.currencies.cryptoCurrencies
|
||||
}
|
||||
|
||||
if (response.idVerificationEnabled) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue