Binance C++ Connector 2.0.0
Official C++ connectors for the Binance APIs
Loading...
Searching...
No Matches
binance::spot::websocket_streams::WebsocketStreamsConnection Class Reference

A connection to the Spot WebSocket streams, returned connected by WebsocketStreams::connect(). More...

#include <websocket_streams.hpp>

Public Member Functions

const common::WebsocketStreamsConfig & configuration () const noexcept
void disconnect ()
template<class CompletionToken>
auto async_disconnect (CompletionToken &&token)
bool is_connected () const
void ping_server ()
 Sends a ping frame on every open connection.
template<class F>
common::Subscription on_event (F &&callback)
 Registers a lifecycle callback (common::WebsocketEvent).
common::WebsocketStreamHandle stream (std::string name, std::optional< common::StreamId > id={}, std::optional< std::string > url_path={})
 Subscribes to a stream by its name, for streams the SDK does not wrap yet, and returns a handle for its callbacks (payloads as boost::json::value).
void subscribe (const std::vector< std::string > &streams, std::optional< common::StreamId > id={}, const std::optional< std::string > &url_path={})
 Subscribes to raw stream names. Messages are delivered to handles from stream().
void unsubscribe (const std::vector< std::string > &streams, std::optional< common::StreamId > id={}, const std::optional< std::string > &url_path={})
bool is_subscribed (const std::string &stream) const
template<class CompletionToken>
auto async_wait_subscribed (std::string stream, std::optional< std::string > url_path, CompletionToken &&token)
 Completes once the server has acknowledged the subscription of stream; see common::WebsocketStreams::async_wait_subscribed.
void wait_subscribed (std::string stream, std::optional< std::string > url_path={}, std::optional< std::chrono::milliseconds > timeout={})
common::WebsocketStream< UserDataStreamEventsResponse > user_data (std::string listen_key, std::optional< common::StreamId > id={}) const
 User data stream of listen_key.
common::WebsocketStream< AggTradeResponse > agg_trade (const AggTradeParams &params) const
 Aggregate Trade Streams.
common::WebsocketStream< std::vector< AllMarketRollingWindowTickerResponseInner > > all_market_rolling_window_ticker (const AllMarketRollingWindowTickerParams &params) const
 All Market Rolling Window Statistics Streams.
common::WebsocketStream< std::vector< AllMiniTickerResponseInner > > all_mini_ticker (const AllMiniTickerParams &params={}) const
 All Market Mini Tickers Stream.
common::WebsocketStream< AvgPriceResponse > avg_price (const AvgPriceParams &params) const
 Average Price.
common::WebsocketStream< BlockTradeResponse > block_trade (const BlockTradeParams &params) const
 Block Trade Streams.
common::WebsocketStream< BookTickerResponse > book_ticker (const BookTickerParams &params) const
 Individual Symbol Book Ticker Streams.
common::WebsocketStream< DiffBookDepthResponse > diff_book_depth (const DiffBookDepthParams &params) const
 Diff.
common::WebsocketStream< KlineResponse > kline (const KlineParams &params) const
 Kline/Candlestick Streams for UTC.
common::WebsocketStream< KlineOffsetResponse > kline_offset (const KlineOffsetParams &params) const
 Kline/Candlestick Streams with timezone offset.
common::WebsocketStream< MiniTickerResponse > mini_ticker (const MiniTickerParams &params) const
 Individual Symbol Mini Ticker Stream.
common::WebsocketStream< PartialBookDepthResponse > partial_book_depth (const PartialBookDepthParams &params) const
 Partial Book Depth Streams.
common::WebsocketStream< ReferencePriceResponse > reference_price (const ReferencePriceParams &params) const
 Reference Price Streams.
common::WebsocketStream< RollingWindowTickerResponse > rolling_window_ticker (const RollingWindowTickerParams &params) const
 Individual Symbol Rolling Window Statistics Streams.
common::WebsocketStream< TickerResponse > ticker (const TickerParams &params) const
 Individual Symbol Ticker Streams.
common::WebsocketStream< TradeResponse > trade (const TradeParams &params) const
 Trade Streams.

Friends

class WebsocketStreams

Detailed Description

A connection to the Spot WebSocket streams, returned connected by WebsocketStreams::connect().

Cheap to copy: copies share one common::WebsocketStreams (connection pool and executor), which reconnects, renews its connections and resubscribes until disconnect().

Member Function Documentation

◆ configuration()

const common::WebsocketStreamsConfig & binance::spot::websocket_streams::WebsocketStreamsConnection::configuration ( ) const
inlinenodiscardnoexcept

◆ disconnect()

void binance::spot::websocket_streams::WebsocketStreamsConnection::disconnect ( )
inline

◆ async_disconnect()

template<class CompletionToken>
auto binance::spot::websocket_streams::WebsocketStreamsConnection::async_disconnect ( CompletionToken && token)
inline

◆ is_connected()

bool binance::spot::websocket_streams::WebsocketStreamsConnection::is_connected ( ) const
inlinenodiscard

◆ ping_server()

void binance::spot::websocket_streams::WebsocketStreamsConnection::ping_server ( )
inline

Sends a ping frame on every open connection.

◆ on_event()

template<class F>
common::Subscription binance::spot::websocket_streams::WebsocketStreamsConnection::on_event ( F && callback)
inline

Registers a lifecycle callback (common::WebsocketEvent).

Destroying the returned subscription removes it.

◆ stream()

common::WebsocketStreamHandle binance::spot::websocket_streams::WebsocketStreamsConnection::stream ( std::string name,
std::optional< common::StreamId > id = {},
std::optional< std::string > url_path = {} )
inlinenodiscard

Subscribes to a stream by its name, for streams the SDK does not wrap yet, and returns a handle for its callbacks (payloads as boost::json::value).

Data arriving before the first callback is added is kept for it (up to 1000 messages).

◆ subscribe()

void binance::spot::websocket_streams::WebsocketStreamsConnection::subscribe ( const std::vector< std::string > & streams,
std::optional< common::StreamId > id = {},
const std::optional< std::string > & url_path = {} )
inline

Subscribes to raw stream names. Messages are delivered to handles from stream().

◆ unsubscribe()

void binance::spot::websocket_streams::WebsocketStreamsConnection::unsubscribe ( const std::vector< std::string > & streams,
std::optional< common::StreamId > id = {},
const std::optional< std::string > & url_path = {} )
inline

◆ is_subscribed()

bool binance::spot::websocket_streams::WebsocketStreamsConnection::is_subscribed ( const std::string & stream) const
inlinenodiscard

◆ async_wait_subscribed()

template<class CompletionToken>
auto binance::spot::websocket_streams::WebsocketStreamsConnection::async_wait_subscribed ( std::string stream,
std::optional< std::string > url_path,
CompletionToken && token )
inline

Completes once the server has acknowledged the subscription of stream; see common::WebsocketStreams::async_wait_subscribed.

◆ wait_subscribed()

void binance::spot::websocket_streams::WebsocketStreamsConnection::wait_subscribed ( std::string stream,
std::optional< std::string > url_path = {},
std::optional< std::chrono::milliseconds > timeout = {} )
inline

◆ user_data()

common::WebsocketStream< UserDataStreamEventsResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::user_data ( std::string listen_key,
std::optional< common::StreamId > id = {} ) const
inlinenodiscard

User data stream of listen_key.

No method of this SDK creates a listen key for this product: subscribe with user_data_stream_subscribe() of the WebSocket API instead.

◆ agg_trade()

common::WebsocketStream< AggTradeResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::agg_trade ( const AggTradeParams & params) const
inlinenodiscard

Aggregate Trade Streams.

<symbol>@aggTrade.

The Aggregate Trade Streams push trade information that is aggregated for a single taker order.

Update Speed: Real-time

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#agg-trade

◆ all_market_rolling_window_ticker()

common::WebsocketStream< std::vector< AllMarketRollingWindowTickerResponseInner > > binance::spot::websocket_streams::WebsocketStreamsConnection::all_market_rolling_window_ticker ( const AllMarketRollingWindowTickerParams & params) const
inlinenodiscard

All Market Rolling Window Statistics Streams.

!ticker_<windowSize>@arr.

Rolling window ticker statistics for all market symbols, computed over multiple windows.

Note that only tickers that have changed will be present in the array.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#all-market-rolling-window-ticker

◆ all_mini_ticker()

common::WebsocketStream< std::vector< AllMiniTickerResponseInner > > binance::spot::websocket_streams::WebsocketStreamsConnection::all_mini_ticker ( const AllMiniTickerParams & params = {}) const
inlinenodiscard

All Market Mini Tickers Stream.

!miniTicker@arr.

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.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#all-mini-ticker

◆ avg_price()

common::WebsocketStream< AvgPriceResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::avg_price ( const AvgPriceParams & params) const
inlinenodiscard

Average Price.

<symbol>@avgPrice.

Average price streams push changes in the average price over a fixed time interval.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#avg-price

◆ block_trade()

common::WebsocketStream< BlockTradeResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::block_trade ( const BlockTradeParams & params) const
inlinenodiscard

Block Trade Streams.

<symbol>@blockTrade.

Block Trade Streams push block trade information in real-time.

Update Speed: Real-time

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#block-trade

◆ book_ticker()

common::WebsocketStream< BookTickerResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::book_ticker ( const BookTickerParams & params) const
inlinenodiscard

Individual Symbol Book Ticker Streams.

<symbol>@bookTicker.

Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.

Multiple <symbol>@bookTicker streams can be subscribed to over one connection.

Update Speed: Real-time

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#book-ticker

◆ diff_book_depth()

common::WebsocketStream< DiffBookDepthResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::diff_book_depth ( const DiffBookDepthParams & params) const
inlinenodiscard

Diff.

Depth Stream

<symbol>@depth@<updateSpeed>.

Order book price and quantity depth updates used to locally manage an order book.

Update Speed: 1000ms or 100ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#diff-book-depth

◆ kline()

common::WebsocketStream< KlineResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::kline ( const KlineParams & params) const
inlinenodiscard

Kline/Candlestick Streams for UTC.

<symbol>@kline_<interval>.

The Kline/Candlestick Stream push updates to the current klines/candlestick every second in UTC+0 timezone

Update Speed: 1000ms for 1s, 2000ms for the other intervals

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#kline

◆ kline_offset()

common::WebsocketStream< KlineOffsetResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::kline_offset ( const KlineOffsetParams & params) const
inlinenodiscard

Kline/Candlestick Streams with timezone offset.

<symbol>@kline_<interval>@+08:00.

The Kline/Candlestick Stream push updates to the current klines/candlestick every second in UTC+8 timezone

Kline/Candlestick chart intervals:

Supported intervals: See Kline/Candlestick chart intervals

UTC+8 timezone offset:

  • Kline intervals open and close in the UTC+8 timezone. For example the 1d klines will open at the beginning of the UTC+8 day, and close at the end of the UTC+8 day.
  • Note that E (event time), t (start time) and T (close time) in the payload are Unix timestamps, which are always interpreted in UTC.

Update Speed: 1000ms for 1s, 2000ms for the other intervals

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#kline-offset

◆ mini_ticker()

common::WebsocketStream< MiniTickerResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::mini_ticker ( const MiniTickerParams & params) const
inlinenodiscard

Individual Symbol Mini Ticker Stream.

<symbol>@miniTicker.

24hr rolling window mini-ticker statistics. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#mini-ticker

◆ partial_book_depth()

common::WebsocketStream< PartialBookDepthResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::partial_book_depth ( const PartialBookDepthParams & params) const
inlinenodiscard

Partial Book Depth Streams.

<symbol>@depth<levels>@<updateSpeed>.

Top **<levels>** bids and asks, pushed every second. Valid **<levels>** are 5, 10, or 20.

Update Speed: 1000ms or 100ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#partial-book-depth

◆ reference_price()

common::WebsocketStream< ReferencePriceResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::reference_price ( const ReferencePriceParams & params) const
inlinenodiscard

Reference Price Streams.

<symbol>@referencePrice.

Reference price stream for a symbol.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#reference-price

◆ rolling_window_ticker()

common::WebsocketStream< RollingWindowTickerResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::rolling_window_ticker ( const RollingWindowTickerParams & params) const
inlinenodiscard

Individual Symbol Rolling Window Statistics Streams.

<symbol>@ticker_<windowSize>.

Rolling window ticker statistics for a single symbol, computed over multiple windows.

Note: This stream is different from the <symbol>@ticker stream. The open time "O" always starts on a minute, while the closing time "C" is the current time of the update. As such, the effective window might be up to 59999ms wider than <windowSize>.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#rolling-window-ticker

◆ ticker()

common::WebsocketStream< TickerResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::ticker ( const TickerParams & params) const
inlinenodiscard

Individual Symbol Ticker Streams.

<symbol>@ticker.

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.

Update Speed: 1000ms

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#ticker

◆ trade()

common::WebsocketStream< TradeResponse > binance::spot::websocket_streams::WebsocketStreamsConnection::trade ( const TradeParams & params) const
inlinenodiscard

Trade Streams.

<symbol>@trade.

The Trade Streams push raw trade information; each trade has a unique buyer and seller.

Update Speed: Real-time

See https://developers.binance.com/en/docs/catalog/core-trading-spot-trading/api/ws-streams/~#trade

◆ WebsocketStreams

friend class WebsocketStreams
friend