knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.81k stars 1.93k forks source link

Cexio streaming orderbook return an empty snapshot as first response #3845

Closed katamarano closed 3 years ago

katamarano commented 3 years ago

Hello everyone, as stated in cexio docs, when requesting an orderbook via WebSocket, we should receive first a snapshot of the book, and then a single message of "update", to edit the local book. There is a "depth" parameter that according to docs if set to 0 should return all the orderbook as a snapshot in the first message while setting to a value N > 0 return only the first N bids and asks. In xchange code this parameter is hard coded to 0 in CexioWebSocketOrderBookSubscriptionData.

 public CexioWebSocketOrderBookSubscriptionData(CurrencyPair currencyPair, boolean subscribe) {
    pair =
        new ArrayList<String>(
            Arrays.asList(currencyPair.base.toString(), currencyPair.counter.toString()));
    this.subscribe = subscribe;
    this.depth = 0; // 0 for full depth
  }

Well, for me the first snapshot is always empty (empty bids and asks) so it's impossible to maintain the local orderbook in sync. If instead, I use a depth N > 0, the snapshot contains the first N bids and docs as stated in the doc.

So would be nice to have the possibility to specify the depth during the request, and propagate this parameter till CexioWebSocketOrderBookSubscriptionData. For instance, during the getOrderBook request:

exchange.getStreamingMarketDataService().getOrderBook(currencyPair, 100 /* depth value */).subscribe( //other code

so to have it propagated to:

 public CexioWebSocketOrderBookSubscriptionData(CurrencyPair currencyPair, boolean subscribe, int depth) 

I already made this change, using the varargs parameter provided by the existent implementation, if needed.

earce commented 3 years ago

Submit a PR if this fixes your issue we can review

katamarano commented 3 years ago

Submit a PR if this fixes your issue we can review

Just created a PR for it

earce commented 3 years ago

Closed