bitrich-info/xchange-stream

how to use getOrderBook with Binance?

Closed this issue · 2 comments

Hi,

I am trying to retrieve orderbooks from binance, but it keeps returning a nullPointerException :

ProductSubscriptionBuilder subscriptionBuilder = ProductSubscription.create();
ProductSubscription subscription = subscriptionBuilder.build();
streamingExchange.getStreamingMarketDataService()
    .getOrderBook(CurrencyPair.LTC_BTC)
    .subscribe(orderBook -> {
    	logger.info(
            "Order Book ({}): askDepth={} ask={} askSize={} bidDepth={}. bid={}, bidSize={}"
        );
}, throwable -> logger.error("ERROR in getting order book: ", throwable));

I also tried :

streamingExchange.getStreamingMarketDataService().getOrderBook(c).subscribe(orderBook -> {
    logger.info("OB :" + c.toString() + " " + (orderBook.toString()));
}, throwable -> {
			// Bleh bleh
    });

What is the right way ?

You need to:

  • Connect first
  • Subscribe to the currency pair on connection

See BinanceManualExample.

Closing. Feel free to re-open if you have more questions.