bitrich-info / xchange-stream

XChange-stream is a Java library providing a simple and consistent streaming API for interacting with Bitcoin and other crypto currency exchanges via WebSocket protocol. It is build on top of of XChange library providing new interfaces for streaming API. User can subscribe for live updates via reactive streams of RxJava library.
Apache License 2.0
413 stars 222 forks source link

[Kraken] Potential bug on userTrades stream #498

Closed makarid closed 4 years ago

makarid commented 4 years ago

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 4 years ago

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.

makarid commented 4 years ago

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 4 years ago

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

makarid commented 4 years ago

Thanks @mdvx

makarid commented 4 years ago

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 4 years ago

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

makarid commented 4 years ago

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

mdvx commented 4 years ago

https://support.kraken.com/hc/en-us/articles/360034499912-WebSocket-API-Private-Feeds-ownTrades

makarid commented 4 years ago

https://support.kraken.com/hc/en-us/articles/360034499912-WebSocket-API-Private-Feeds-ownTrades

Thanks @mdvx , my bad!

badgerwithagun commented 4 years ago

@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.