bitrich-info/xchange-stream

Subscribe to Tickers only

Closed this issue · 2 comments

cymp commented

Hello,

I noticed that on connection, xchange-stream connects to all of the books. For example, I have this:

StreamingExchange streamingExchange = StreamingExchangeFactory.INSTANCE.createExchange(BinanceStreamingExchange.class.getName());
List<CurrencyPair> symbols = ExchangeFactory.INSTANCE.createExchange(BinanceExchange.class).getExchangeSymbols();
ProductSubscription.ProductSubscriptionBuilder productSubscriptionBuilder = ProductSubscription.create();
symbols.forEach(productSubscriptionBuilder::addAll);
streamingExchange.connect(productSubscriptionBuilder.build()).blockingAwait();
symbols.stream()
       .filter(Objects::nonNull)
       .forEach(symbol -> {
         streamingExchange
             .getStreamingMarketDataService()
             .getTicker(symbol)
             .subscribe(ticker -> {
               log.debug("Ticker data received for {}", symbol);
             });
       });

I am only interested in tickers, but I can notice in the logs that it REST-fetches all the initial snapshots of the order books. This is a problem, especially on Binance for the following causes:

  • We are rate limited there, so REST-calling 500+ orderbooks will result in a ban
  • We can't even reach this problem since we are getting a "414 URL too large" at websocket startup

Is there any way to completely ignore the orderbooks when we only want the tickers?

Regards

You're using ProductSubscriptionBuilder::addAll. You should use ProductSubscriptionBuilder::addTicker.

Binance requires all subscriptions to be stated on connection (the socket is one-way - you can't send messages changing subscriptions once you've already connected), so you're actually subscribing to everything, not just tickers.

PS: I'm about to submit a PR with a solution to the rate ban (you can pass a rate limiter as an exchange argument).

cymp commented

My bad, you are right. Thank you.