|
| | WebsocketApi (WebsocketApiConfig configuration, detail::ClientOptions options={}) |
| | Throws ConfigError if url or proxy is invalid, or ConnectorClientError if the private key cannot be loaded.
|
| | ~WebsocketApi () |
| | WebsocketApi (const WebsocketApi &)=delete |
| WebsocketApi & | operator= (const WebsocketApi &)=delete |
| | WebsocketApi (WebsocketApi &&)=delete |
| WebsocketApi & | operator= (WebsocketApi &&)=delete |
| const WebsocketApiConfig & | configuration () const noexcept |
| | The configuration, as given but without private_key_passphrase (the key is loaded).
|
| const SignatureGenerator & | signature_generator () const noexcept |
| boost::asio::any_io_executor | get_executor () const noexcept |
| template<class CompletionToken> |
| auto | async_connect (CompletionToken &&token) |
| | Opens every connection of the pool that is not open, each within connect_timeout.
|
| void | connect () |
| template<class CompletionToken> |
| auto | async_disconnect (CompletionToken &&token) |
| | Stops reconnecting, waits up to 30 s for pending responses, then closes every connection with code 1000.
|
| void | disconnect () |
| bool | is_connected () const |
| | True if at least one connection is open.
|
| void | ping_server () |
| | Sends a ping frame on every open connection.
|
| template<class F> |
| Subscription | on_event (F &&callback, bool with_messages=true) |
| | Registers a lifecycle callback (WebsocketEvent).
|
| template<class CompletionToken> |
| auto | async_send_message (std::string method, Params payload, WebsocketMessageSendOptions options, CompletionToken &&token) |
| | Sends a request and completes with its response: one per connection for is_session_logon / is_session_logout (sent on every connection), else exactly one.
|
| std::vector< WebsocketApiRawResponse > | send_message (std::string method, Params payload, WebsocketMessageSendOptions options={}) |
| | Blocking async_send_message.
|
| template<class CompletionToken> |
| auto | async_subscribe (std::string method, Params payload, WebsocketMessageSendOptions options, CompletionToken &&token) |
| | Sends a request that opens a user-data subscription (e.g.
|
| WebsocketApiRawSubscription | subscribe (std::string method, Params payload, WebsocketMessageSendOptions options={}) |
| | Blocking async_subscribe.
|
| WebsocketStreamHandle | create_stream (std::string id={}) |
| | A handle receiving every user-data event from any connection, for subscriptions managed by the caller.
|
The WebSocket API transport (request / response) shared by every product.
- A pool of mode.pool_size() connections, used round-robin.
- Requests are matched to responses by id and time out after timeout.
- Dropped connections reconnect after reconnect_delay, unless the close code says it is permanent (see WebsocketConnectionFailureReason).
- Connections are renewed every 23 hours, and when the server announces serverShutdown, without losing in-flight requests.
- With auto_session_relogon, a session logged on with session.logon is logged on again after every reconnect.
- User-data subscriptions made with subscribe are sent again after every reconnect and renewal (after the session logon, if any), on the connection that made them. Their stream ends them (see async_subscribe).
- Other requests about subscriptions (userDataStream.unsubscribe, session.subscriptions) sent with send_message go to one connection, like any request, and Binance numbers the subscriptions of each connection from 0: with pool_size() > 1, end a subscription through its stream. A successful userDataStream.unsubscribe also stops sending the subscriptions it ended again.
The client runs on its own I/O thread, or on configuration.executor when set. Completion handlers run on their associated executor, or on the client's (get_executor()). Callbacks (events, user data) run on the client's executor unless bound to another, so they should not block. Every member function is thread-safe. Blocking calls (connect, disconnect, send_message, subscribe) throw WebsocketError if made from the client's executor or a thread running it (for io_context and thread_pool executors and their strands); with other executors, do not make them from its threads. The other calls never block on the executor.
Errors are WebsocketError subclasses, or ConnectorClientError for a request that cannot be built (missing api_key, signing failure).
Destroying the client closes its connections at once and fails pending requests with WebsocketCancelledError; call disconnect() first for a graceful close.
template<class CompletionToken>
| auto binance::common::WebsocketApi::async_connect |
( |
CompletionToken && | token | ) |
|
|
inline |
Opens every connection of the pool that is not open, each within connect_timeout.
Completes once all are open, or with the first failure. A call made while connecting completes with that attempt; one made while disconnecting connects once that is done.
template<class CompletionToken>
Sends a request and completes with its response: one per connection for is_session_logon / is_session_logout (sent on every connection), else exactly one.
Supports per-operation cancellation (bind_cancellation_slot, cancel_after(timer, …)): it then completes with WebsocketCancelledError. A response that arrives later is dropped, but the request may still have been executed.
template<class CompletionToken>
Sends a request that opens a user-data subscription (e.g.
userDataStream.subscribe) and completes with its response and a stream of its events ({"event": {...}} messages from that subscription). The client sends the request again whenever the connection reopens, and the server may then assign another subscriptionId. stream.unsubscribe(), or destroying the stream, ends the subscription: it sends userDataStream.unsubscribe with the current subscriptionId on the connection holding it, and stops sending the request again. Failures are reported as Error events. stream.stream() is the first subscriptionId. Per-operation cancellation is not supported: it completes with the response.