Browse Source

filter out trades with 0 volume, fix #486

develop
Mike van Rossum 4 years ago
parent
commit
4ead6a1ff3
2 changed files with 27 additions and 0 deletions
  1. +7
    -0
      core/budfox/tradeBatcher.js
  2. +20
    -0
      test/tradeBatcher.js

+ 7
- 0
core/budfox/tradeBatcher.js View File

@ -99,6 +99,13 @@ TradeBatcher.prototype.filter = function(batch) {
if(lastTid === lastTid + 1)
util.die('trade tid is max int, Gekko can\'t process..');
// remove trades that have zero amount
// see @link
// https://github.com/askmike/gekko/issues/486
batch = _.filter(batch, function(trade) {
return trade.amount > 0;
});
// weed out known trades
// TODO: optimize by stopping as soon as the
// first trade is too old (reverse first)

+ 20
- 0
test/tradeBatcher.js View File

@ -23,6 +23,13 @@ var trades_tid_2 = [
{tid: 5, price: 10, amount: 1, date: 1466115797}
];
var empty_trades = [
{tid: 2, price: 10, amount: 0, date: 1466115794},
{tid: 3, price: 10, amount: 0, date: 1466115795},
{tid: 4, price: 10, amount: 0, date: 1466115796},
{tid: 5, price: 10, amount: 0, date: 1466115797}
];
describe('budfox/tradeBatcher', function() {
var tb;
@ -116,4 +123,17 @@ describe('budfox/tradeBatcher', function() {
expect(tbResult.data.length).to.equal(2);
});
// see @link
// https://github.com/askmike/gekko/issues/486
it('should filter out empty trades', function() {
tb = new TradeBatcher('tid');
var spy = sinon.spy();
tb.on('new batch', spy);
tb.write(empty_trades);
expect(spy.callCount).to.equal(0);
});
});

Loading…
Cancel
Save