pub struct PolymarketWebSocketClient { /* private fields */ }Expand description
Provides a WebSocket client for the Polymarket CLOB API.
A single instance targets one channel (market or user). Use
PolymarketWebSocketClient::new_market for public market data and
PolymarketWebSocketClient::new_user for authenticated order/trade streams.
Implementations§
Source§impl PolymarketWebSocketClient
impl PolymarketWebSocketClient
Sourcepub fn new_market(
base_url: Option<String>,
subscribe_new_markets: bool,
transport_backend: TransportBackend,
) -> Self
pub fn new_market( base_url: Option<String>, subscribe_new_markets: bool, transport_backend: TransportBackend, ) -> Self
Creates a new market-channel client (unauthenticated).
If base_url is None, the default production URL is used.
Sourcepub fn new_user(
base_url: Option<String>,
credential: Credential,
transport_backend: TransportBackend,
) -> Self
pub fn new_user( base_url: Option<String>, credential: Credential, transport_backend: TransportBackend, ) -> Self
Creates a new user-channel client (authenticated).
If base_url is None, the default production URL is used.
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Establishes the WebSocket connection and spawns the message handler.
§Errors
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Disconnects the WebSocket connection.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the number of active market asset subscriptions (pending + confirmed).
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Returns true if the user channel has been authenticated.
Sourcepub async fn subscribe_market(&self, asset_ids: Vec<String>) -> Result<()>
pub async fn subscribe_market(&self, asset_ids: Vec<String>) -> Result<()>
Subscribe to market data for the given asset IDs.
Sends a subscribe message immediately if connected; the IDs are also retained so they are re-sent automatically on reconnect.
§Errors
Returns an error if called on a user-channel client (incompatible channel).
Sourcepub async fn unsubscribe_market(&self, asset_ids: Vec<String>) -> Result<()>
pub async fn unsubscribe_market(&self, asset_ids: Vec<String>) -> Result<()>
Remove asset IDs from the active subscription set.
The IDs are dropped from the reconnect set so they will not be re-subscribed after a reconnect. No wire message is sent.
§Errors
Returns an error if called on a user-channel client (incompatible channel).
Sourcepub async fn subscribe_user(&self) -> Result<()>
pub async fn subscribe_user(&self) -> Result<()>
Authenticate and subscribe to the user channel.
§Errors
Returns an error if called on a market-channel client (no credentials available).
Sourcepub fn clone_subscription_handle(&self) -> WsSubscriptionHandle
pub fn clone_subscription_handle(&self) -> WsSubscriptionHandle
Returns a cloneable subscription handle for use in spawned tasks.
Sourcepub fn take_message_receiver(
&mut self,
) -> Option<UnboundedReceiver<PolymarketWsMessage>>
pub fn take_message_receiver( &mut self, ) -> Option<UnboundedReceiver<PolymarketWsMessage>>
Takes the message receiver, leaving None in its place.
This is useful when the data client needs to spawn its own handler
task that reads messages independently of the WS client.
Subscription methods (subscribe_market, etc.) remain usable on &self.
Sourcepub async fn next_message(&mut self) -> Option<PolymarketWsMessage>
pub async fn next_message(&mut self) -> Option<PolymarketWsMessage>
Receives the next message from the WebSocket handler.
Returns None when the handler has disconnected or the receiver
was not yet initialized (call connect first).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PolymarketWebSocketClient
impl !RefUnwindSafe for PolymarketWebSocketClient
impl Send for PolymarketWebSocketClient
impl Sync for PolymarketWebSocketClient
impl Unpin for PolymarketWebSocketClient
impl UnsafeUnpin for PolymarketWebSocketClient
impl !UnwindSafe for PolymarketWebSocketClient
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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