Make tradeQueueBalance private
Move `consolidateTrades` to private section
This commit is contained in:
parent
49f77c50b8
commit
7464b93d7b
1 changed files with 29 additions and 29 deletions
|
|
@ -51,6 +51,34 @@ Trader.prototype._findWallet = function (name) {
|
|||
return exchange.wallet || exchange;
|
||||
};
|
||||
|
||||
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._consolidateTrades = function () {
|
||||
var queue = this._tradeQueue;
|
||||
|
||||
var tradeRec = {
|
||||
fiat: 0,
|
||||
satoshis: 0,
|
||||
currency: this.config.exchanges.settings.currency
|
||||
};
|
||||
|
||||
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.configure = function (config) {
|
||||
if (config.exchanges.settings.lowBalanceMargin < 1) {
|
||||
throw new Error('`settings.lowBalanceMargin` has to be >= 1');
|
||||
|
|
@ -123,7 +151,7 @@ Trader.prototype.fiatBalance = function (transferSatoshis, tradeFiat) {
|
|||
|
||||
// We need to secure `tradeFiat` (amount of fiat in this transaction) and
|
||||
// enough fiat to cover our trading queue (trades aren't executed immediately).
|
||||
var adjustedFiat = tradeFiat + this.tradeQueueFiatBalance(rate);
|
||||
var adjustedFiat = tradeFiat + this._tradeQueueFiatBalance(rate);
|
||||
|
||||
// So we subtract `adjustedFiat` from `tradeBalance` and again, apply
|
||||
// `lowBalanceMargin`.
|
||||
|
|
@ -170,34 +198,6 @@ Trader.prototype.trade = function (fiat, satoshis, currency, callback) {
|
|||
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._consolidateTrades = function () {
|
||||
var queue = this._tradeQueue;
|
||||
|
||||
var tradeRec = {
|
||||
fiat: 0,
|
||||
satoshis: 0,
|
||||
currency: this.config.exchanges.settings.currency
|
||||
};
|
||||
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue