diff --git a/lib/trader.js b/lib/trader.js index 7bc7ccdf..5584b44b 100644 --- a/lib/trader.js +++ b/lib/trader.js @@ -16,6 +16,8 @@ var Trader = module.exports = function (db) { this.logger = new (winston.Logger)({ transports: [new (winston.transports.Console)()] }); + + this._tradeQueue = []; }; Trader.prototype._findExchange = function (name) { @@ -149,6 +151,18 @@ Trader.prototype.sendBitcoins = function (deviceFingerprint, tx, cb) { }); }; +Trader.prototype.trade = function (fiat, satoshis, currency, callback) { + this._tradeQueue.push({fiat: fiat, satoshis: satoshis, currency: currency}); + callback(null); +}; + +Trader.prototype.tradeQueueFiatBalance = function (exchangeRate) { + var satoshis = this._tradeQueue.reduce(function (memo, rec) { + return memo + rec.satoshis; + }, 0); + return (satoshis / SATOSHI_FACTOR) * exchangeRate; +}; + Trader.prototype.startPolling = function () { this.pollBalance(); this.pollRate();