bitrich-info/xchange-stream

[Kraken] Potential bug on userTrades stream

Closed this issue · 10 comments

Hello, when some subscribes to kraken userTrades stream, he receives a list of trades(maybe the last X trades). After that everything works correctly. My question is, if i receive past trades every time i connect to the websocket, does it means that in a reconnection event i will also get past trades?
If this is true then we have to fix that bug. We don't want to get random trades every time we make a reconnection or even a connection. Thanks

mdvx commented

Umm, It basically replicates what the socket does, when it subscribes to ownTrades. I understand the concern, but I have always worked under the assuption that you could get duplicate updates of trades or orders (up to you to cache them). Take for instance the case where it send you a userTrade and the connection immidiatly breaks; There is no protocol for the server to know if you got it , or not.

Also, XStream would have to hold state for each trade to make that work.

So, it means that it is up to us to discard any unwanted trades? There is no way we can do something in this library?

mdvx commented

You could use a guave cache with expireAfterWrite
@badgerwithagun might have different ideas

Thanks @mdvx

Hello, i reopen the issue because it is very dangerous for live trading. Does this problem has to do with what Kraken send us or it has to do with how you have implement it? I have read the code and i haven't find any issue with it. The implementation doesn't save any local copy of the userTrades,is that right? Thanks

mdvx commented

So you have userTradeObservable, that is created the first time getUserTrades is called. CurrencyPair is not used by the channel, so the observable is for all userTrades updates.

Say you call getUserTrades(CurrencyPair.BTC_USD) - you only get those (except you also get updates for userTrades that do not have a currencyPair - deltas)
Say you call getUserTrades(null) - you get all these updates (and the deltas)

When the socket is opened, you get the default userTrade history. if the socket ever has to reconnect, you will get that default history again (with new values). NettyStreamingService.

The implementation doesn't save any local copy of the userTrades,is that right?
That is correct

So if i have understand correctly, there is no way to get past trades(let's 30 minutes ago trades) if the stream reconnects itself based on the implementation. This has to do with what Kraken sends when you reconnect,is that right? Because this doesn't happen every time i reconnect. Maybe these are deltas but i cannot understand why i get past deltas (30minutes-1 hour ago). Thank you

@makarid - yeah basically we took the decision that with the private streams we aren't going to "standardise" their behaviour regarding duplicates and missing data. For most practical purposes you need to combine the streams with duplicate detection and REST calls to check for gaps.