Class BinanceStreamingService
java.lang.Object
info.bitrich.xchangestream.service.ConnectableService
info.bitrich.xchangestream.service.netty.NettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
info.bitrich.xchangestream.service.netty.JsonNettyStreamingService
info.bitrich.xchangestream.binance.BinanceStreamingService
-
Nested Class Summary
Nested classes/interfaces inherited from class info.bitrich.xchangestream.service.netty.NettyStreamingService
NettyStreamingService.NettyWebSocketClientHandler, NettyStreamingService.Subscription -
Field Summary
Fields inherited from class info.bitrich.xchangestream.service.netty.JsonNettyStreamingService
objectMapperFields inherited from class info.bitrich.xchangestream.service.netty.NettyStreamingService
channels, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_RETRY_DURATION, uriFields inherited from class info.bitrich.xchangestream.service.ConnectableService
BEFORE_CONNECTION_HANDLER -
Constructor Summary
ConstructorsConstructorDescriptionBinanceStreamingService(String baseUri, ProductSubscription productSubscription, KlineSubscription klineSubscription) BinanceStreamingService(String baseUri, ProductSubscription productSubscription, KlineSubscription klineSubscription, int maxFramePayloadLength, Duration connectionTimeout, Duration retryDuration, int idleTimeoutSeconds) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidprotected StringgetChannelNameFromMessage(com.fasterxml.jackson.databind.JsonNode message) The available subscriptions for this streaming service.getSubscribeMessage(String channelName, Object... args) Get the live subscription messagegetUnsubscribeMessage(String channelName, Object... args) Get the live unsubscription messageprotected io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandlerprotected WebSocketClientHandlergetWebSocketClientHandler(io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker handshake, WebSocketClientHandler.WebSocketMessageHandler handler) protected voidhandleMessage(com.fasterxml.jackson.databind.JsonNode message) booleanvoidWe override this method because we must not use Live Subscription in case of reconnection.voidsendMessage(String message) voidsetChannelInactiveHandler(WebSocketClientHandler.WebSocketMessageHandler channelInactiveHandler) voidunsubscribeChannel(String channelId) Live Unsubscription from stream.Methods inherited from class info.bitrich.xchangestream.service.netty.JsonNettyStreamingService
messageHandler, processArrayMessageSeparately, sendObjectMessageMethods inherited from class info.bitrich.xchangestream.service.netty.NettyStreamingService
disconnect, getChannel, getCustomHeaders, getSubscriptionUniqueId, handleChannelError, handleChannelMessage, handleError, handleIdle, isSocketOpen, openConnection, setAcceptAllCertificates, setAutoReconnect, setEnableLoggingHandler, setLoggingHandlerLevel, setSocksProxyHost, setSocksProxyPort, subscribeChannel, subscribeConnectionState, subscribeConnectionSuccess, subscribeDisconnect, subscribeIdle, subscribeReconnectFailure, useCompressedMessagesMethods inherited from class info.bitrich.xchangestream.service.ConnectableService
connect, setBeforeConnectionHandler
-
Constructor Details
-
BinanceStreamingService
public BinanceStreamingService(String baseUri, ProductSubscription productSubscription, KlineSubscription klineSubscription) -
BinanceStreamingService
public BinanceStreamingService(String baseUri, ProductSubscription productSubscription, KlineSubscription klineSubscription, int maxFramePayloadLength, Duration connectionTimeout, Duration retryDuration, int idleTimeoutSeconds)
-
-
Method Details
-
getChannelNameFromMessage
- Specified by:
getChannelNameFromMessagein classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
-
handleMessage
protected void handleMessage(com.fasterxml.jackson.databind.JsonNode message) - Overrides:
handleMessagein classNettyStreamingService<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 ... for more details. All the channels will be resubscribed at connection time.- Overrides:
resubscribeChannelsin classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
-
getSubscribeMessage
Get the live subscription message- Specified by:
getSubscribeMessagein classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>- Throws:
IOException
-
getUnsubscribeMessage
Get the live unsubscription message- Specified by:
getUnsubscribeMessagein classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>- Throws:
IOException
-
sendMessage
- Overrides:
sendMessagein classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
-
getWebSocketClientExtensionHandler
protected io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler getWebSocketClientExtensionHandler()- Overrides:
getWebSocketClientExtensionHandlerin classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
-
getProductSubscription
The available subscriptions for this streaming service.- Returns:
- The subscriptions for the currently open connection.
-
getKlineSubscription
-
enableLiveSubscription
public void enableLiveSubscription() -
disableLiveSubscription
public void disableLiveSubscription() -
isLiveSubscriptionEnabled
public boolean isLiveSubscriptionEnabled() -
unsubscribeChannel
Live Unsubscription from stream. This send a message through the websocket to Binance with method UNSUBSCRIBE. (see ... 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
-
getWebSocketClientHandler
protected WebSocketClientHandler getWebSocketClientHandler(io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker handshake, WebSocketClientHandler.WebSocketMessageHandler handler) - Overrides:
getWebSocketClientHandlerin classNettyStreamingService<com.fasterxml.jackson.databind.JsonNode>
-
setChannelInactiveHandler
public void setChannelInactiveHandler(WebSocketClientHandler.WebSocketMessageHandler channelInactiveHandler)
-