|
Binance C++ Connector 2.0.0
Official C++ connectors for the Binance APIs
|
One subscribed stream (WebSocket streams) or user-data subscription (WebSocket API), with untyped callbacks. More...
#include <websocket_stream.hpp>
Public Member Functions | |
| WebsocketStreamHandle ()=default | |
| WebsocketStreamHandle (std::string stream, std::shared_ptr< detail::StreamBinding > binding) | |
| WebsocketStreamHandle (WebsocketStreamHandle &&) noexcept=default | |
| WebsocketStreamHandle & | operator= (WebsocketStreamHandle &&other) noexcept |
| WebsocketStreamHandle (const WebsocketStreamHandle &)=delete | |
| WebsocketStreamHandle & | operator= (const WebsocketStreamHandle &)=delete |
| ~WebsocketStreamHandle () | |
| const std::string & | stream () const noexcept |
| The stream name, or the subscription's id for user data. | |
| template<class F> | |
| void | on_message (F &&callback) |
| Adds a callback. | |
| void | unsubscribe () noexcept |
| Removes this handle's callbacks and, for WebSocket streams, unsubscribes from the stream once no other handle uses it. | |
| void | release () noexcept |
| Detaches this handle: the subscription and its callbacks stay until the client is destroyed, and the handle becomes empty. | |
| template<class CompletionToken> | |
| auto | async_wait_subscribed (CompletionToken &&token) |
| Completes once the server has acknowledged the subscription (see WebsocketStreams::async_wait_subscribed), at once for a user-data subscription. | |
| void | wait_subscribed (std::optional< std::chrono::milliseconds > timeout={}) |
One subscribed stream (WebSocket streams) or user-data subscription (WebSocket API), with untyped callbacks.
Move-only: destroying it unsubscribes, like unsubscribe(); release() keeps the subscription and its callbacks for the client's lifetime. on_message and unsubscribe are thread-safe.
Payloads received before the first callback is added are kept (up to 1000) and delivered to it. A default-constructed handle is empty: its calls do nothing.
|
default |
| binance::common::WebsocketStreamHandle::WebsocketStreamHandle | ( | std::string | stream, |
| std::shared_ptr< detail::StreamBinding > | binding ) |
|
defaultnoexcept |
|
delete |
| binance::common::WebsocketStreamHandle::~WebsocketStreamHandle | ( | ) |
|
noexcept |
|
delete |
|
nodiscardnoexcept |
The stream name, or the subscription's id for user data.
|
inline |
Adds a callback.
It runs on its associated executor if it has one (see boost::asio::bind_executor), else on the client's executor, so it should not block. Exceptions it throws are logged. No callback starts once unsubscribe() or the client's destructor has returned. The destructor waits for callbacks running on the client's executor, but not for those running on their own.
|
noexcept |
Removes this handle's callbacks and, for WebSocket streams, unsubscribes from the stream once no other handle uses it.
A callback running on another thread of the client's executor is waited for (one on its own executor is not). A user-data subscription is ended on the server (see WebsocketApi::async_subscribe).
|
noexcept |
Detaches this handle: the subscription and its callbacks stay until the client is destroyed, and the handle becomes empty.
|
inline |
Completes once the server has acknowledged the subscription (see WebsocketStreams::async_wait_subscribed), at once for a user-data subscription.
Fails with WebsocketCancelledError if the handle is empty or unsubscribed, or the client is gone. wait_subscribed blocks and throws WebsocketTimeoutError once timeout passes, if given.
| void binance::common::WebsocketStreamHandle::wait_subscribed | ( | std::optional< std::chrono::milliseconds > | timeout = {} | ) |