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

In Cexio streaming orderbook no alert if orderbook goes out of sync. #3846

Closed katamarano closed 3 years ago

katamarano commented 3 years ago

Hello again, another issue in cex.io streaming is in the function

 @Override
    public OrderBook apply(CexioWebSocketOrderBookSubscribeResponse t) throws Exception {
      OrderBook retVal;
      if (prevID != null && prevID.add(BigInteger.ONE).compareTo(t.id) != 0) {
        orderBookSoFar =
            new OrderBook(new Date(), new ArrayList<LimitOrder>(), new ArrayList<LimitOrder>());
      }

      prevID = t.id;
      orderBookSoFar = CexioAdapters.adaptOrderBookIncremental(orderBookSoFar, t);
      retVal = orderBookSoFar;

      return retVal;
    }

in class CexioStreamingMarketDataService.OrderBookUpdateConsumer

First, a new instance of orderBookSoFar is created and then anyway is overwritten by

orderBookSoFar = CexioAdapters.adaptOrderBookIncremental(orderBookSoFar, t);

What is the meaning to create a new instance and then reassign it? I think that instead of creating a new instance (useless cause then anyway is reassigned) should be thrown an exception cause the orderbook is compromised if the ID of the message is not in sequence with the local ID that was saved from the previous message. Instead, in this case, the user is ignoring that its orderbook messages are out of order and not in sync. Very dangerous imho if the goal is to recreate a local orderbook and keep in sync.

earce commented 3 years ago

This seems right, I think triggering a reconnect and recreation of state would be the right thing. This can be done by way of exception.

earce commented 3 years ago

Closed with PR