pub struct KalshiWebSocketClient { /* private fields */ }Expand description
One multiplexed Predictions connection with reference-counted subscription intent.
Subscription calls record intent; events report venue confirmation or failure.
Intent survives disconnect and stop. Reset clears it, and dispose permanently closes admission.
Automatic transport reconnection is disabled. After an unexpected disconnect, call stop
before connect to create a freshly signed connection and restore retained intent.
Clones share lifecycle, subscription intent, and task ownership.
Implementations§
Source§impl KalshiWebSocketClient
impl KalshiWebSocketClient
Sourcepub fn new(
config: KalshiDataClientConfig,
) -> Result<(Self, UnboundedReceiver<KalshiWsEvent>)>
pub fn new( config: KalshiDataClientConfig, ) -> Result<(Self, UnboundedReceiver<KalshiWsEvent>)>
Creates a disconnected client and its unbounded event receiver.
§Errors
Returns an error if configuration is invalid.
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Connects, authenticates, and waits for retained subscriptions to be confirmed.
§Errors
Returns an error if the client is disposed, credentials or signing fail, the connection or task admission fails, or retained subscriptions are not restored before the timeout.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns whether the authenticated transport and retained subscriptions are ready.
Sourcepub fn subscribe(&self, subscription: KalshiSubscription) -> Result<()>
pub fn subscribe(&self, subscription: KalshiSubscription) -> Result<()>
Adds one local reference and records intent, including before connection.
§Errors
Returns an error if arguments are invalid, the client is disposed, or the handler is stopped.
Sourcepub fn unsubscribe(&self, subscription: &KalshiSubscription) -> Result<()>
pub fn unsubscribe(&self, subscription: &KalshiSubscription) -> Result<()>
Removes one local reference; the final removal cancels replay intent.
§Errors
Returns an error if arguments are invalid or the handler is stopped.
Sourcepub fn update_subscription(
&self,
original: &KalshiSubscription,
action: KalshiUpdateAction,
markets: Vec<String>,
) -> Result<()>
pub fn update_subscription( &self, original: &KalshiSubscription, action: KalshiUpdateAction, markets: Vec<String>, ) -> Result<()>
Updates the shared subscription identified by its original arguments.
Adds and deletes change retained replay intent. Snapshot requests are connection-bound. Removing every explicitly selected market requires unsubscribe instead.
§Errors
Returns an error if the client is disposed, the channel or filter change is unsupported, intent is absent, markets are empty or duplicated, all markets would be deleted, the handler is stopped, or a snapshot is requested before the connection is ready.
Sourcepub async fn stop(&self) -> Result<()>
pub async fn stop(&self) -> Result<()>
Stops the connection and drains owned tasks while retaining subscription intent.
§Errors
Returns an error if bounded task teardown fails.
Trait Implementations§
Source§impl Clone for KalshiWebSocketClient
impl Clone for KalshiWebSocketClient
Auto Trait Implementations§
impl !RefUnwindSafe for KalshiWebSocketClient
impl !UnwindSafe for KalshiWebSocketClient
impl Freeze for KalshiWebSocketClient
impl Send for KalshiWebSocketClient
impl Sync for KalshiWebSocketClient
impl Unpin for KalshiWebSocketClient
impl UnsafeUnpin for KalshiWebSocketClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more