Class BinanceStreamingMarketDataService

java.lang.Object
info.bitrich.xchangestream.binance.BinanceStreamingMarketDataService
All Implemented Interfaces:
StreamingMarketDataService

public class BinanceStreamingMarketDataService extends Object implements StreamingMarketDataService
  • Constructor Details

  • Method Details

    • getOrderBook

      public io.reactivex.Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args)
      Description copied from interface: StreamingMarketDataService
      Get an order book representing the current offered exchange rates (market depth).

      Warning: The library will attempt to keep the snapshots returned in sync with the exchange using the approaches published by that exchange. However, there are currently no guarantees that messages will not be skipped, or that any initial state message will be sent on connection. Emits NotConnectedException when not connected to the WebSocket API.

      Specified by:
      getOrderBook in interface StreamingMarketDataService
      Parameters:
      currencyPair - Currency pair of the order book
      Returns:
      Observable that emits OrderBook when exchange sends the update.
    • getTicker

      public io.reactivex.Observable<Ticker> getTicker(CurrencyPair currencyPair, Object... args)
      Description copied from interface: StreamingMarketDataService
      Get a ticker representing the current exchange rate. Emits NotConnectedException When not connected to the WebSocket API.

      Warning: There are currently no guarantees that messages will not be skipped, or that any initial state message will be sent on connection.

      Specified by:
      getTicker in interface StreamingMarketDataService
      Parameters:
      currencyPair - Currency pair of the ticker
      Returns:
      Observable that emits Ticker when exchange sends the update.
    • getTrades

      public io.reactivex.Observable<Trade> getTrades(CurrencyPair currencyPair, Object... args)
      Description copied from interface: StreamingMarketDataService
      Get the trades performed by the exchange. Emits NotConnectedException When not connected to the WebSocket API.

      Warning: There are currently no guarantees that messages will not be skipped.

      Specified by:
      getTrades in interface StreamingMarketDataService
      Parameters:
      currencyPair - Currency pair of the trades
      Returns:
      Observable that emits Trade when exchange sends the update.
    • getOrderBook

      public io.reactivex.Observable<OrderBook> getOrderBook(Instrument instrument, Object... args)
      Specified by:
      getOrderBook in interface StreamingMarketDataService
    • getTicker

      public io.reactivex.Observable<Ticker> getTicker(Instrument instrument, Object... args)
      Specified by:
      getTicker in interface StreamingMarketDataService
    • getTrades

      public io.reactivex.Observable<Trade> getTrades(Instrument instrument, Object... args)
      Specified by:
      getTrades in interface StreamingMarketDataService
    • getFundingRate

      public io.reactivex.Observable<FundingRate> getFundingRate(Instrument instrument, Object... args)
      Description copied from interface: StreamingMarketDataService
      Get funding rate of specific instrument.
      Specified by:
      getFundingRate in interface StreamingMarketDataService
      Parameters:
      instrument - Instrument to get the funding rate for
      Returns:
      Observable that emits FundingRate when exchange sends the update.
    • getRawTicker

      public io.reactivex.Observable<BinanceTicker24h> getRawTicker(Instrument instrument)
    • getRawBookTicker

      public io.reactivex.Observable<BinanceBookTicker> getRawBookTicker(Instrument instrument)
    • getRawTrades

      public io.reactivex.Observable<BinanceRawTrade> getRawTrades(Instrument instrument)
    • getKlines

      public io.reactivex.Observable<BinanceKline> getKlines(Instrument instrument, KlineInterval interval)
    • getOrderBookUpdates

      public io.reactivex.Observable<List<OrderBookUpdate>> getOrderBookUpdates(Instrument instrument)
      Api to get binance incremental order book updates. As binance websocket provides only api to get incremental updates getOrderBook(Instrument, Object...) have to build book from rest and websocket which leads to delay before the order book will be received by subscriber. This api provides the ability to start receiving updates immediately. It is allowed to subscribe to this api and getOrderBook(Instrument, Object...) at the same time.
    • openSubscriptions

      public void openSubscriptions(ProductSubscription productSubscription, KlineSubscription klineSubscription)
      Registers subscriptions with the streaming service for the given products.

      As we receive messages as soon as the connection is open, we need to register subscribers to handle these before the first messages arrive.

    • unsubscribe

      public void unsubscribe(Instrument instrument, BinanceSubscriptionType subscriptionType)
      Live Unsubscription that should be called in the Observable.doOnDispose(). This is required to stop receiving data from the stream. This method also clear the subscription from the appropriate map.
    • unsubscribeKline

      public void unsubscribeKline(Instrument instrument, KlineInterval klineInterval)