Start adding trading back to Trader

This commit is contained in:
Maciej Małecki 2014-04-16 17:09:39 +02:00
parent 8cb9783bde
commit b79bdf8789

View file

@ -16,6 +16,8 @@ var Trader = module.exports = function (db) {
this.logger = new (winston.Logger)({ this.logger = new (winston.Logger)({
transports: [new (winston.transports.Console)()] transports: [new (winston.transports.Console)()]
}); });
this._tradeQueue = [];
}; };
Trader.prototype._findExchange = function (name) { 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 () { Trader.prototype.startPolling = function () {
this.pollBalance(); this.pollBalance();
this.pollRate(); this.pollRate();