Skip to content

Commit

Permalink
Only emit trades executed after subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
aloysius-pgast committed Jun 21, 2018
1 parent 2974893 commit 242370b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [v1.1.6]
* Only return trades which were executed after subscription (this means that first 'trades' event will be emitted only when the first trade will be executed after subscription)

## [v1.1.5]
* Fix _ticker_ timestamp

Expand Down
20 changes: 19 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,25 @@ _queryExchangeState(pair)
// only if we didn't already emitted a 'trades' event for same cseq
if (self._subscriptions.markets.pairs[pair].lastUpdateCseq != data.N)
{
self.emit('trades', tradesEvt);
// only emit trades which were executed after subscription
let minTimestamp = self._subscriptions.markets.pairs[pair].timestamp;
// if oldest entry is < timestamp(subscription), we need to do some filtering
if (tradesEvt.data[tradesEvt.data.length - 1].timestamp < minTimestamp)
{
let data = [];
_.forEach(tradesEvt.data, (e) => {
if (e.timestamp < minTimestamp)
{
return;
}
data.push(e);
});
tradesEvt.data = data;
}
if (0 != tradesEvt.data.length)
{
self.emit('trades', tradesEvt);
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bittrex-signalr-client",
"version": "1.1.5",
"version": "1.1.6",
"description": "Node.js implementation of SignalR protocol tailored for Bittrex exchange",
"main": "lib/client.js",
"scripts": {},
Expand Down

0 comments on commit 242370b

Please sign in to comment.