|
| | WebsocketStreams (WebsocketStreamsConfig configuration, std::vector< std::string > url_paths={}, detail::ClientOptions options={}) |
| | Throws ConfigError if url or proxy is invalid.
|
| | ~WebsocketStreams () |
| | WebsocketStreams (const WebsocketStreams &)=delete |
| WebsocketStreams & | operator= (const WebsocketStreams &)=delete |
| | WebsocketStreams (WebsocketStreams &&)=delete |
| WebsocketStreams & | operator= (WebsocketStreams &&)=delete |
| const WebsocketStreamsConfig & | configuration () const noexcept |
| | The configuration, as given but without private_key_passphrase (the key is loaded).
|
| boost::asio::any_io_executor | get_executor () const noexcept |
| template<class CompletionToken> |
| auto | async_connect (std::vector< std::string > streams, CompletionToken &&token) |
| | Opens every connection that is not open.
|
| void | connect (std::vector< std::string > streams={}) |
| template<class CompletionToken> |
| auto | async_disconnect (CompletionToken &&token) |
| | Drops every subscription and callback (existing handles no longer do anything), then closes the connections like WebsocketApi::disconnect.
|
| void | disconnect () |
| bool | is_connected () const |
| void | ping_server () |
| template<class F> |
| Subscription | on_event (F &&callback, bool with_messages=true) |
| void | subscribe (const std::vector< std::string > &streams, std::optional< StreamId > id={}, const std::optional< std::string > &url_path={}) |
| | Sends SUBSCRIBE for the streams not already subscribed, or queues them until their connection opens.
|
| void | unsubscribe (const std::vector< std::string > &streams, std::optional< StreamId > id={}, const std::optional< std::string > &url_path={}) |
| | Sends UNSUBSCRIBE for the streams that no handle uses.
|
| bool | is_subscribed (const std::string &stream) const |
| | True if stream is subscribed (or queued), on any URL path.
|
| WebsocketStreamHandle | create_stream (std::string stream, std::optional< StreamId > id={}, std::optional< std::string > url_path={}) |
| | Subscribes to stream and returns a handle for its callbacks.
|
| 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 (a SUBSCRIBE response, or a connection that opened with it in its URL), at once if it already has.
|
| void | wait_subscribed (std::string stream, std::optional< std::string > url_path={}, std::optional< std::chrono::milliseconds > timeout={}) |
The WebSocket market / user streams transport shared by every product.
- A pool of mode.pool_size() connections per URL path (e.g. market, public, private for USDⓈ-M futures, or the base URL alone). Streams are spread over it round-robin, at most 1024 per connection while another connection has room.
- Subscriptions made while no connection is open (reconnecting, or between disconnect() and the next connect()) are kept, and sent once their connection opens.
- SUBSCRIBE and UNSUBSCRIBE made in one go (e.g. a loop of create_stream) are batched into one request per connection when they are still queued (always, when made on the client's executor). Nothing is delayed for it.
- Reconnects and 23 h renewals resubscribe through the connection URL; streams that do not fit in it (about 4 KB) are subscribed once the connection opens. Signed streams have no streams in their URL: they are all subscribed again by command once the connection opens.
- Around a renewal, a stream comes from the previous socket until the new one delivers it, so a few messages may repeat.
- A SUBSCRIBE the server rejects drops its streams (is_subscribed turns false, they leave reconnect URLs) and emits an Error event. Signed streams' commands have no id: each acknowledgement answers the oldest command of its kind sent on that socket.
- Stream callbacks are keyed by stream_key(stream, url_path). UNSUBSCRIBE is sent only once no handle uses a stream.
- Streams of a connection that closes for good move to another connection of the pool, or stay until the next connect() if none is left.
Threading, callbacks and destruction work as for WebsocketApi. Only connect, disconnect and wait_subscribed wait for the executor (they throw if called on it).
template<class CompletionToken>
| auto binance::common::WebsocketStreams::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 (a SUBSCRIBE response, or a connection that opened with it in its URL), at once if it already has.
It waits across reconnects and while the client is not connected yet. Fails with WebsocketResponseError if the server rejected the SUBSCRIBE, and with WebsocketCancelledError if the stream is not subscribed, or stops being before (unsubscribed, disconnect(), destruction of the client), or if the token's cancellation slot fires (any cancellation type; the subscription stays). wait_subscribed blocks and throws WebsocketTimeoutError once timeout passes, if given.