Class BinanceStreamingService


public class BinanceStreamingService
extends JsonNettyStreamingService
  • Constructor Details

    • BinanceStreamingService

      public BinanceStreamingService​(String baseUri, ProductSubscription productSubscription)
    • BinanceStreamingService

      public BinanceStreamingService​(String baseUri, ProductSubscription productSubscription, int maxFramePayloadLength, Duration connectionTimeout, Duration retryDuration, int idleTimeoutSeconds)
  • Method Details

    • getChannelNameFromMessage

      protected String getChannelNameFromMessage​(com.fasterxml.jackson.databind.JsonNode message) throws IOException
      Specified by:
      getChannelNameFromMessage in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
      Throws:
      IOException
    • handleMessage

      protected void handleMessage​(com.fasterxml.jackson.databind.JsonNode message)
      Overrides:
      handleMessage in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
    • resubscribeChannels

      public void resubscribeChannels()
      We override this method because we must not use Live Subscription in case of reconnection. The reason is that Binance has a Websocket limits to 5 incoming messages per second. If we pass this limit the socket is closed automatically by Binance. See https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md#websocket-limits for more details. All the channels will be resubscribed at connection time.
      Overrides:
      resubscribeChannels in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
    • getSubscribeMessage

      public String getSubscribeMessage​(String channelName, Object... args) throws IOException
      Get the live subscription message
      Specified by:
      getSubscribeMessage in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
      Throws:
      IOException
    • getUnsubscribeMessage

      public String getUnsubscribeMessage​(String channelName) throws IOException
      Get the live unsubscription message
      Specified by:
      getUnsubscribeMessage in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
      Throws:
      IOException
    • sendMessage

      public void sendMessage​(String message)
      Overrides:
      sendMessage in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
    • getWebSocketClientExtensionHandler

      protected io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler getWebSocketClientExtensionHandler()
      Overrides:
      getWebSocketClientExtensionHandler in class NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
    • getProductSubscription

      public ProductSubscription getProductSubscription()
      The available subscriptions for this streaming service.
      Returns:
      The subscriptions for the currently open connection.
    • enableLiveSubscription

      public void enableLiveSubscription()
    • disableLiveSubscription

      public void disableLiveSubscription()
    • isLiveSubscriptionEnabled

      public boolean isLiveSubscriptionEnabled()
    • unsubscribeChannel

      public void unsubscribeChannel​(String channelId)
      Live Unsubscription from stream. This send a message through the websocket to Binance with method UNSUBSCRIBE. (see https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md#unsubscribe-to-a-stream for more details) This is the only way to really stop receiving data from the stream (Disposable.dispose() dispose the resource but don't stop the data to be received from Binance).
      Parameters:
      channelId - e.g. btcusdt@depth, btcusdt@trade