|
kalshi-cpp 0.6.2
C++23 client for Kalshi's Predictions API
|
Streams Kalshi's WebSocket channels. More...
#include <kalshi/websocket.hpp>
Public Member Functions | |
| WebSocketClient (Signer signer, WsConfig config={}) | |
Creates a client that authenticates with a copy of signer. | |
| ~WebSocketClient () | |
| WebSocketClient (WebSocketClient &&) noexcept | |
| WebSocketClient & | operator= (WebSocketClient &&) noexcept |
| WebSocketClient (const WebSocketClient &)=delete | |
| WebSocketClient & | operator= (const WebSocketClient &)=delete |
| Result< void > | connect () |
Opens the connection and waits up to connect_timeout for the handshake. | |
| void | disconnect () |
| Closes the connection and forgets every subscription. | |
| WsState | state () const noexcept |
| bool | is_connected () const noexcept |
| Result< ws::Subscription > | subscribe (ws::Channel channel, ws::SubscribeParams params={}) |
| Subscribes to one channel. | |
| Result< void > | unsubscribe (ws::Subscription subscription) |
| Result< void > | update_subscription (ws::Subscription subscription, const ws::UpdateSubscriptionParams ¶ms) |
| Result< void > | add_markets (ws::Subscription subscription, std::vector< std::string > market_tickers) |
| Result< void > | remove_markets (ws::Subscription subscription, std::vector< std::string > market_tickers) |
| Result< void > | request_snapshot (ws::Subscription subscription, std::vector< std::string > market_tickers) |
| Asks for order book snapshots of markets in an orderbook_delta subscription, without changing it. | |
| Result< std::int64_t > | list_subscriptions () |
| Asks the server for its view of this connection's subscriptions. | |
| std::vector< ws::Subscription > | subscriptions () const |
| The subscriptions this client holds. | |
| void | on_message (std::function< void(const WsMessage &)> callback) |
| void | on_error (std::function< void(const WsError &)> callback) |
| void | on_state_change (std::function< void(WsState)> callback) |
| const WsConfig & | config () const noexcept |
Streams Kalshi's WebSocket channels.
Subscriptions survive reconnects: the client resubscribes with the same parameters and keeps each ws::Subscription handle, while the server's sid changes. Callbacks run on the client's network thread, which blocks SIGPIPE on POSIX systems, except the Disconnected state change from disconnect(), which runs on the caller's. They may call any method, including destroying the client, but should return quickly. Every method is thread-safe.
Creates a client that authenticates with a copy of signer.
| kalshi::WebSocketClient::~WebSocketClient | ( | ) |
|
noexcept |
|
delete |
|
noexcept |
|
delete |
| Result< void > kalshi::WebSocketClient::connect | ( | ) |
Opens the connection and waits up to connect_timeout for the handshake.
Subscriptions made before the call are sent once connected.
| void kalshi::WebSocketClient::disconnect | ( | ) |
Closes the connection and forgets every subscription.
connect() can open a new session afterwards.
|
noexcept |
|
noexcept |
| Result< ws::Subscription > kalshi::WebSocketClient::subscribe | ( | ws::Channel | channel, |
| ws::SubscribeParams | params = {} |
||
| ) |
Subscribes to one channel.
The handle is usable at once: updates and unsubscribes made before the server confirms are sent after it does.
| Result< void > kalshi::WebSocketClient::unsubscribe | ( | ws::Subscription | subscription | ) |
| Result< void > kalshi::WebSocketClient::update_subscription | ( | ws::Subscription | subscription, |
| const ws::UpdateSubscriptionParams & | params | ||
| ) |
| Result< void > kalshi::WebSocketClient::add_markets | ( | ws::Subscription | subscription, |
| std::vector< std::string > | market_tickers | ||
| ) |
| Result< void > kalshi::WebSocketClient::remove_markets | ( | ws::Subscription | subscription, |
| std::vector< std::string > | market_tickers | ||
| ) |
| Result< void > kalshi::WebSocketClient::request_snapshot | ( | ws::Subscription | subscription, |
| std::vector< std::string > | market_tickers | ||
| ) |
Asks for order book snapshots of markets in an orderbook_delta subscription, without changing it.
| Result< std::int64_t > kalshi::WebSocketClient::list_subscriptions | ( | ) |
Asks the server for its view of this connection's subscriptions.
The reply arrives as ws::SubscriptionList carrying the returned ID.
| std::vector< ws::Subscription > kalshi::WebSocketClient::subscriptions | ( | ) | const |
The subscriptions this client holds.
| void kalshi::WebSocketClient::on_message | ( | std::function< void(const WsMessage &)> | callback | ) |
| void kalshi::WebSocketClient::on_error | ( | std::function< void(const WsError &)> | callback | ) |
| void kalshi::WebSocketClient::on_state_change | ( | std::function< void(WsState)> | callback | ) |
|
noexcept |