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