Skip to content

Commit

Permalink
Fix mongodb missing candles (askmike#2600)
Browse files Browse the repository at this point in the history
* v0.6 support for bitx (aka Luno)

* v0.6 support for bitx (aka Luno)

* remove log

* move dependency to gb

* rename bitx to luno

* rename bitx to luno

* temp fix simultaneous advice error

* - re-add logging
- Retry insufficient balance due to server update delay
- Enhanced getPorfolio
- getOrder now return fees

* update

* update

* update

* revert 4b5d09f

* add useful info to export

* standardize naming

* fix mongodb missing candles
  • Loading branch information
hiyan authored and askmike committed Dec 2, 2018
1 parent 617f819 commit a3a8331
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions plugins/mongodb/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ Store.prototype.writeCandles = function writeCandles () {
candles.push(mCandle);
});

this.historyCollection.insert(candles);
// Fix error when whole batch would failed to insert if one or more duplicate candle
this.historyCollection.insert(candles, { ordered: false }, e => {
if (e) {
let msg = 'mongojs insert() ' + e.writeErrors.length + ' of ' + candles.length + ' failed.';
_.forEach(_.countBy(e.writeErrors, 'code'), (c, k) => {
msg += ' Code: E' + k + ' count: ' + c;
});
log.debug(msg);
}
});

this.candleCache = [];
}

Expand All @@ -59,15 +69,18 @@ var processCandle = function processCandle (candle, done) {
this.marketTime = candle.start;

this.candleCache.push(candle);
if (this.candleCache.length > 100)
if (this.candleCache.length >= 100)
this.writeCandles();
done();
}

var finalize = function(done) {
this.writeCandles();
this.db = null;
done();
// Fix connection closed before all candles was written to db
setTimeout( () => {
this.db = null;
done();
}, 1000);
}

var processAdvice = function processAdvice (advice) {
Expand Down

0 comments on commit a3a8331

Please sign in to comment.