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

A connection to the StockOptions 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< OrderReportV2StreamResponse > order_report_v2_stream (const OrderReportV2StreamParams &params) const
 Order Report V2 Stream.

Friends

class WebsocketStreams

Detailed Description

A connection to the StockOptions 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::stock_options::websocket_streams::WebsocketStreamsConnection::configuration ( ) const
inlinenodiscardnoexcept

◆ disconnect()

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

◆ async_disconnect()

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

◆ is_connected()

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

◆ ping_server()

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

Sends a ping frame on every open connection.

◆ on_event()

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

Registers a lifecycle callback (common::WebsocketEvent).

Destroying the returned subscription removes it.

◆ stream()

common::WebsocketStreamHandle binance::stock_options::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::stock_options::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::stock_options::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::stock_options::websocket_streams::WebsocketStreamsConnection::is_subscribed ( const std::string & stream) const
inlinenodiscard

◆ async_wait_subscribed()

template<class CompletionToken>
auto binance::stock_options::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::stock_options::websocket_streams::WebsocketStreamsConnection::wait_subscribed ( std::string stream,
std::optional< std::string > url_path = {},
std::optional< std::chrono::milliseconds > timeout = {} )
inline

◆ order_report_v2_stream()

common::WebsocketStream< OrderReportV2StreamResponse > binance::stock_options::websocket_streams::WebsocketStreamsConnection::order_report_v2_stream ( const OrderReportV2StreamParams & params) const
inlinenodiscard

Order Report V2 Stream.

<listenKey>@orderReportV2.

Real-time push of the user's order updates. Option orders are pushed on orderReportV2, not on orderReport.

orderReportV2 carries both US stock and US stock option orders; tell them apart with the ac field. To process option orders only, subscribe to orderReportV2 and handle events where ac = us_option.

A push is sent once when an open order changes (x = ORDER_UPDATE) and once when it reaches a terminal state (x = ORDER_TERMINAL). Pushes are best-effort: a failed push is not retried, events while the listenKey is invalid are not replayed, and an order never pushed in an open state (e.g. rejected immediately) may not get a terminal push. After reconnecting, call Current Open Option Orders for a full snapshot first. Fill-level details are not pushed; use Option Order Detail or Option Trade History.

For expiration-day auto-liquidation orders by the broker (o = market), p, b, q, tc, u, ct, sp and ed may be null; get contract details from Option Exchange Info by os.

Prerequisite: obtain a listenKey via the Listen Key endpoint first.

See https://developers.binance.com/en/docs/catalog/advanced-trading-stock-option-trading/api/ws-streams/user-streams#order-report-v2-stream

◆ WebsocketStreams

friend class WebsocketStreams
friend