Class WebsocketClientImpl
java.lang.Object
com.binance.connector.client.impl.WebsocketClientImpl
- All Implemented Interfaces:
WebsocketClient
Websocket Streams
All stream endpoints under the Websocket Market Streams and User Data Streams section of the API documentation will be implemented in this class.Response will be returned as callback.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
aggTradeStream(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)
The Aggregate Trade Streams push trade information that is aggregated for a single taker order.int
allBookTickerStream(com.binance.connector.client.utils.WebSocketCallback callback)
Pushes any update to the best bid or ask's price or quantity in real-time for all symbols.int
allMiniTickerStream(com.binance.connector.client.utils.WebSocketCallback callback)
24hr rolling window mini-ticker statistics for all symbols that changed in an array.int
allTickerStream(com.binance.connector.client.utils.WebSocketCallback callback)
24hr rolling window ticker statistics for all symbols that changed in an array.int
bookTicker(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)
Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.void
Closes all streamsvoid
closeConnection(int connectionId)
Closes a specific stream based on stream Id.int
combineStreams(ArrayList<String> streams, com.binance.connector.client.utils.WebSocketCallback callback)
Combined streams are accessed at /stream?streams=<streamName1>/<streamName2>/<streamName3>int
diffDepthStream(String symbol, int speed, com.binance.connector.client.utils.WebSocketCallback callback)
Order book price and quantity depth updates used to locally manage an order book.int
klineStream(String symbol, String interval, com.binance.connector.client.utils.WebSocketCallback callback)
The Kline/Candlestick Stream push updates to the current klines/candlestick every second.int
listenUserStream(String listenKey, com.binance.connector.client.utils.WebSocketCallback callback)
User Data Streams are accessed at /ws/<listenKey>int
miniTickerStream(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)
24hr rolling window mini-ticker statistics.int
partialDepthStream(String symbol, int levels, int speed, com.binance.connector.client.utils.WebSocketCallback callback)
Top bids and asks, Valid are 5, 10, or 20.int
symbolTicker(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)
24hr rolling window ticker statistics for a single symbol.int
tradeStream(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)
The Trade Streams push raw trade information; each trade has a unique buyer and seller.
-
Constructor Details
-
WebsocketClientImpl
public WebsocketClientImpl() -
WebsocketClientImpl
-
-
Method Details
-
aggTradeStream
public int aggTradeStream(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)The Aggregate Trade Streams push trade information that is aggregated for a single taker order.
<symbol>@aggTrade
Update Speed: Real-time- Specified by:
aggTradeStream
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pair- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#aggregate-trade-streams
-
tradeStream
public int tradeStream(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)The Trade Streams push raw trade information; each trade has a unique buyer and seller.
<symbol>@trade
Update Speed: Real-time- Specified by:
tradeStream
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pair- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#trade-streams
-
klineStream
public int klineStream(String symbol, String interval, com.binance.connector.client.utils.WebSocketCallback callback)The Kline/Candlestick Stream push updates to the current klines/candlestick every second.
<symbol>@kline_<interval>
Update Speed: Real-time- Specified by:
klineStream
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pair- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-streams
-
miniTickerStream
public int miniTickerStream(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)24hr rolling window mini-ticker statistics. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs.
<symbol>@miniTicker
Update Speed: Real-time- Specified by:
miniTickerStream
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pair- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream
-
allMiniTickerStream
public int allMiniTickerStream(com.binance.connector.client.utils.WebSocketCallback callback)24hr rolling window mini-ticker statistics for all symbols that changed in an array. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Note that only tickers that have changed will be present in the array.
!miniTicker@arr
Update Speed: Real-time- Specified by:
allMiniTickerStream
in interfaceWebsocketClient
- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#all-market-mini-tickers-stream
-
symbolTicker
public int symbolTicker(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)24hr rolling window ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs.
<symbol>@ticker
Update Speed: Real-time- Specified by:
symbolTicker
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pair- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-ticker-streams
-
allTickerStream
public int allTickerStream(com.binance.connector.client.utils.WebSocketCallback callback)24hr rolling window ticker statistics for all symbols that changed in an array. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Note that only tickers that have changed will be present in the array.
!ticker@arr
Update Speed: Real-time- Specified by:
allTickerStream
in interfaceWebsocketClient
- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#all-market-tickers-stream
-
bookTicker
public int bookTicker(String symbol, com.binance.connector.client.utils.WebSocketCallback callback)Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.
<symbol>@bookTicker
Update Speed: Real-time- Specified by:
bookTicker
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pair- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-book-ticker-streams
-
allBookTickerStream
public int allBookTickerStream(com.binance.connector.client.utils.WebSocketCallback callback)Pushes any update to the best bid or ask's price or quantity in real-time for all symbols.
!bookTicker
Update Speed: Real-time- Specified by:
allBookTickerStream
in interfaceWebsocketClient
- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#all-book-tickers-stream
-
partialDepthStream
public int partialDepthStream(String symbol, int levels, int speed, com.binance.connector.client.utils.WebSocketCallback callback)Top bids and asks, Valid are 5, 10, or 20.
<symbol>@depth<levels>@<speed>ms
Update Speed: 1000ms or 100ms- Specified by:
partialDepthStream
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pairlevels
- Valid are 5, 10, or 20speed
- 1000ms or 100ms- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#partial-book-depth-streams
-
diffDepthStream
public int diffDepthStream(String symbol, int speed, com.binance.connector.client.utils.WebSocketCallback callback)Order book price and quantity depth updates used to locally manage an order book.
<symbol>@depth@<speed>ms
Update Speed: 1000ms or 100ms- Specified by:
diffDepthStream
in interfaceWebsocketClient
- Parameters:
symbol
- Name of trading pairspeed
- 1000ms or 100ms- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
-
listenUserStream
public int listenUserStream(String listenKey, com.binance.connector.client.utils.WebSocketCallback callback)User Data Streams are accessed at /ws/<listenKey>- Specified by:
listenUserStream
in interfaceWebsocketClient
- Parameters:
listenKey
- listen key obtained from this endpoint- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#user-data-streams
-
combineStreams
public int combineStreams(ArrayList<String> streams, com.binance.connector.client.utils.WebSocketCallback callback)Combined streams are accessed at /stream?streams=<streamName1>/<streamName2>/<streamName3>- Specified by:
combineStreams
in interfaceWebsocketClient
- Parameters:
streams
- A list of stream names to be combined- Returns:
- int - Connection ID
- See Also:
- https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams
-
closeConnection
public void closeConnection(int connectionId)Closes a specific stream based on stream Id.- Specified by:
closeConnection
in interfaceWebsocketClient
- Parameters:
connectionId
-
-
closeAllConnections
public void closeAllConnections()Closes all streams- Specified by:
closeAllConnections
in interfaceWebsocketClient
-