29 std::optional<std::int64_t>
id;
30 std::optional<std::int64_t>
sid;
31 std::optional<std::int64_t>
seq;
41 return "disconnected";
47 return "reconnecting";
114 ws::SubscribeParams params = {});
119 std::vector<std::string> market_tickers);
121 std::vector<std::string> market_tickers);
125 std::vector<std::string> market_tickers);
140 std::shared_ptr<Impl> impl_;
Signs Kalshi requests with an API key.
Definition signer.hpp:32
Streams Kalshi's WebSocket channels.
Definition websocket.hpp:89
std::vector< ws::Subscription > subscriptions() const
The subscriptions this client holds.
void on_message(std::function< void(const WsMessage &)> callback)
Result< void > add_markets(ws::Subscription subscription, std::vector< std::string > market_tickers)
WebSocketClient(WebSocketClient &&) noexcept
bool is_connected() const noexcept
Result< void > unsubscribe(ws::Subscription subscription)
void on_state_change(std::function< void(WsState)> callback)
WsState state() const noexcept
WebSocketClient(Signer signer, WsConfig config={})
Creates a client that authenticates with a copy of signer.
Result< ws::Subscription > subscribe(ws::Channel channel, ws::SubscribeParams params={})
Subscribes to one channel.
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< void > connect()
Opens the connection and waits up to connect_timeout for the handshake.
void disconnect()
Closes the connection and forgets every subscription.
Result< std::int64_t > list_subscriptions()
Asks the server for its view of this connection's subscriptions.
Result< void > remove_markets(ws::Subscription subscription, std::vector< std::string > market_tickers)
Result< void > update_subscription(ws::Subscription subscription, const ws::UpdateSubscriptionParams ¶ms)
const WsConfig & config() const noexcept
void on_error(std::function< void(const WsError &)> callback)
std::variant< Update< OrderbookSnapshot >, Update< OrderbookDelta >, Update< Ticker >, Update< Trade >, Update< Fill >, Update< MarketPosition >, Update< EventLifecycle >, Update< EventFeeUpdate >, Update< MultivariateMarketLifecycle >, Update< RfqCreated >, Update< RfqDeleted >, Update< QuoteCreated >, Update< QuoteAccepted >, Update< QuoteExecuted >, Update< OrderGroupUpdates >, Update< UserOrder >, Update< CfbenchmarksValue >, Update< CfbenchmarksIndexList >, Update< CfbenchmarksValue5Hz >, Update< Cfbenchmarks5HzIndexList >, Update< PythValue >, Update< PythUnderlyingList >, Update< MarketMetadataUpdated >, Update< MarketLifecycleV2 >, Subscribed, Unsubscribed, Updated, SubscriptionList > Message
Everything WebSocketClient delivers to on_message.
Definition ws_models.hpp:1041
constexpr std::string_view to_string(HttpMethod method) noexcept
Definition http_client.hpp:22
WsState
Definition websocket.hpp:36
Environment
Kalshi deployment.
Definition environment.hpp:10
std::expected< T, Error > Result
Result type for SDK operations.
Definition error.hpp:50
ws::Message WsMessage
Everything on_message delivers: channel data as ws::Update<T>, and subscription events.
Definition websocket.hpp:21
constexpr std::string_view websocket_url(Environment environment) noexcept
WebSocket URL for streaming market and account data.
Definition environment.hpp:19
Definition websocket.hpp:52
std::chrono::milliseconds reconnect_delay
The first reconnect waits about this long; each failure doubles the wait, with jitter,...
Definition websocket.hpp:60
std::chrono::seconds idle_timeout
Definition websocket.hpp:68
static WsConfig for_environment(Environment environment)
Definition websocket.hpp:73
std::chrono::milliseconds connect_timeout
How long connect() waits for the handshake.
Definition websocket.hpp:55
std::chrono::seconds ping_interval
Ping after this much silence, and drop the connection after idle_timeout without a reply.
Definition websocket.hpp:67
bool auto_reconnect
Reconnect and resubscribe after the connection drops.
Definition websocket.hpp:57
bool resync_on_gap
Request fresh order book snapshots when an orderbook_delta sequence number is skipped.
Definition websocket.hpp:71
std::uint32_t max_reconnect_attempts
Stop after this many failed attempts in a row; 0 keeps trying.
Definition websocket.hpp:64
std::chrono::milliseconds max_reconnect_delay
Definition websocket.hpp:61
std::string url
Definition websocket.hpp:53
An error frame from the server, or a problem the client found itself.
Definition websocket.hpp:24
std::string message
Definition websocket.hpp:27
std::optional< ws::Subscription > subscription
The subscription the error concerns, when known.
Definition websocket.hpp:33
std::optional< std::int64_t > id
The command that failed, when the server names one.
Definition websocket.hpp:29
std::int64_t code
Kalshi's error code (see ws::error_code_name), or 0 for a client error.
Definition websocket.hpp:26
std::optional< std::int64_t > seq
Definition websocket.hpp:31
std::optional< std::int64_t > sid
Definition websocket.hpp:30
A handle for one channel subscription.
Definition ws_models.hpp:359
Options for update_subscription; the client sets the subscription.
Definition ws_models.hpp:922