recalculate fiatBalance as balance at start of session
This commit is contained in:
parent
4925843906
commit
96f480a73c
2 changed files with 63 additions and 45 deletions
|
|
@ -19,19 +19,21 @@ Error.prototype.toJSON = function () {
|
|||
|
||||
var poll = function(req, res) {
|
||||
var rateRec = _trader.rate();
|
||||
var satoshiBalanceRec = _trader.balance;
|
||||
var balanceRec = _trader.balance;
|
||||
var fingerprint = req.connection.getPeerCertificate().fingerprint;
|
||||
|
||||
// `rateRec` and `satoshiBalanceRec` are both objects, so there's no danger
|
||||
// `rateRec` and `balanceRec` are both objects, so there's no danger
|
||||
// of misinterpreting rate or balance === 0 as 'Server initializing'.
|
||||
if (!rateRec || !satoshiBalanceRec) {
|
||||
if (!rateRec || !balanceRec) {
|
||||
return res.json({err: 'Server initializing'});
|
||||
}
|
||||
|
||||
if (Date.now() - rateRec.timestamp > STALE_TICKER) {
|
||||
var now = Date.now();
|
||||
if (now - rateRec.timestamp > STALE_TICKER) {
|
||||
return res.json({err: 'Stale ticker'});
|
||||
}
|
||||
|
||||
if (Date.now() - rateRec.timestamp > STALE_BALANCE) {
|
||||
if (now - balanceRec.timestamp > STALE_BALANCE) {
|
||||
return res.json({err: 'Stale balance'});
|
||||
}
|
||||
|
||||
|
|
@ -40,16 +42,16 @@ var poll = function(req, res) {
|
|||
res.json({
|
||||
err: null,
|
||||
rate: rate * _trader.config.exchanges.settings.commission,
|
||||
fiat: _trader.fiatBalance(0, 0),
|
||||
fiat: _trader.fiatBalance(fingerprint),
|
||||
locale: _trader.config.brain.locale,
|
||||
txLimit: parseInt(_trader.config.exchanges.settings.compliance.maximum.limit, 10)
|
||||
});
|
||||
};
|
||||
|
||||
var trade = function (req, res) {
|
||||
_trader.trade(req.body.fiat, req.body.satoshis, req.body.currency, function(err) {
|
||||
res.json({err: err});
|
||||
});
|
||||
var fingerprint = req.connection.getPeerCertificate().fingerprint;
|
||||
_trader.trade(req.body, fingerprint);
|
||||
res.json({err: null});
|
||||
};
|
||||
|
||||
var send = function(req, res) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue