expire attempted trades

This commit is contained in:
Josh Harvey 2016-06-03 12:23:41 +03:00
parent 19ebf9d2a2
commit 1fe57e7cf1

View file

@ -26,6 +26,7 @@ var TRANSACTION_EXPIRATION = 48 * 60 * 60 * 1000
var SWEEP_LIVE_HD_INTERVAL = 60 * 1000
var SWEEP_OLD_HD_INTERVAL = 2 * 60 * 1000
var TRADE_INTERVAL = 60 * 1000
var TRADE_TTL = 5 * 60 * 1000
var cryptoCodes = null
@ -317,7 +318,8 @@ exports.trade = function trade (session, rawTrade) {
tradesQueues[cryptoCode].push({
currency: rawTrade.currency,
cryptoAtoms: rawTrade.cryptoAtoms,
cryptoCode: cryptoCode
cryptoCode: cryptoCode,
timestamp: Date.now()
})
}
@ -581,9 +583,12 @@ function consolidateTrades (cryptoCode) {
logger.debug('tradesQueues size: %d', tradesQueues[cryptoCode].length)
logger.debug('tradesQueues head: %j', tradesQueues[cryptoCode][0])
var cryptoAtoms = tradesQueues[cryptoCode].reduce(function (prev, current) {
return prev.plus(current.cryptoAtoms)
}, new BigNumber(0))
const t0 = Date.now()
const cryptoAtoms = tradesQueues[cryptoCode]
.filter(trade => t0 - trade.timestamp < TRADE_TTL)
.reduce((prev, current) => prev.plus(current.cryptoAtoms), new BigNumber(0))
var consolidatedTrade = {
currency: deviceCurrency,