From a6687964ba54f3d4686baa82e2075f55e101f76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Thu, 17 Apr 2014 13:02:36 +0200 Subject: [PATCH] Add `Trader#_consolidateTrades` --- lib/trader.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/trader.js b/lib/trader.js index 5584b44b..a07b99be 100644 --- a/lib/trader.js +++ b/lib/trader.js @@ -163,6 +163,27 @@ Trader.prototype.tradeQueueFiatBalance = function (exchangeRate) { return (satoshis / SATOSHI_FACTOR) * exchangeRate; }; +Trader.prototype._consolidateTrades = function () { + var queue = this._tradeQueue; + + var tradeRec = { + fiat: 0, + satoshis: 0, + currency: 'USD' + }; + + while (true) { + var lastRec = queue.shift(); + if (!lastRec) { + break; + } + tradeRec.fiat += lastRec.fiat; + tradeRec.satoshis += lastRec.satoshis; + tradeRec.currency = lastRec.currency; + } + return tradeRec; +}; + Trader.prototype.startPolling = function () { this.pollBalance(); this.pollRate();