Bring back trading to fiatBalance
This commit is contained in:
parent
d83a46bf7d
commit
49f77c50b8
1 changed files with 15 additions and 1 deletions
|
|
@ -116,7 +116,21 @@ Trader.prototype.fiatBalance = function (transferSatoshis, tradeFiat) {
|
|||
// [ $ ] = [ $ ]
|
||||
var fiatTransferBalance = ((adjustedTransferBalance / SATOSHI_FACTOR) * rate) / lowBalanceMargin;
|
||||
|
||||
return fiatTransferBalance;
|
||||
// If this server is also configured to trade received fiat for Bitcoins,
|
||||
// we also need to calculate if we have enough funds on our trade exchange.
|
||||
if (balance.tradeBalance === null) return fiatTransferBalance;
|
||||
var tradeBalance = balance.tradeBalance;
|
||||
|
||||
// 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);
|
||||
|
||||
// So we subtract `adjustedFiat` from `tradeBalance` and again, apply
|
||||
// `lowBalanceMargin`.
|
||||
var fiatTradeBalance = (tradeBalance - adjustedFiat) / lowBalanceMargin;
|
||||
|
||||
// And we return the smallest number.
|
||||
return Math.min(fiatTransferBalance, fiatTradeBalance);
|
||||
};
|
||||
|
||||
Trader.prototype.sendBitcoins = function (deviceFingerprint, tx, cb) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue