pub struct WsClient { /* private fields */ }Expand description
A live Bezant WebSocket connection. Clone cheaply to share across tasks —
actually no, WebSocket sinks aren’t cheap to split arbitrarily. Keep one
owner per connection and WsClient::split if you need a read/write
halving.
Implementations§
Source§impl WsClient
impl WsClient
Sourcepub async fn connect(client: &Client) -> Result<Self>
pub async fn connect(client: &Client) -> Result<Self>
Open a WebSocket connection to the Gateway that client is pointed at.
Internally:
- Issues a
/tickleHTTP call to mint a session cookie. - Derives the
wss://…/wsURL from the REST base URL. - Attaches
Cookie: api={"session":"…"}to the WS handshake. - Returns a connected
WsClient.
§Errors
Any tickle / handshake / TLS failure surfaces as Error.
Sourcepub async fn subscribe_market_data(
&mut self,
conid: i64,
fields: &MarketDataFields,
) -> Result<Subscription>
pub async fn subscribe_market_data( &mut self, conid: i64, fields: &MarketDataFields, ) -> Result<Subscription>
Subscribe to level-1 market data for a single contract id. Use
MarketDataFields::default_l1 if you just want the common fields.
Returns a Subscription handle — call Subscription::cancel
when you’re done with the feed instead of tracking the conid
yourself.
§Errors
Any send failure surfaces as Error::WsTransport /
Error::WsProtocol.
Sourcepub async fn unsubscribe_market_data(&mut self, conid: i64) -> Result<()>
pub async fn unsubscribe_market_data(&mut self, conid: i64) -> Result<()>
Unsubscribe from a previously-subscribed market data feed by
raw conid. Prefer Subscription::cancel on the handle returned
by Self::subscribe_market_data — this raw form remains for
callers that already track conids themselves.
§Errors
Any send failure surfaces as Error::WsTransport.
Sourcepub async fn subscribe_orders(&mut self) -> Result<Subscription>
pub async fn subscribe_orders(&mut self) -> Result<Subscription>
Subscribe to order status updates. Returns a Subscription
you can cancel later.
§Errors
Any send failure surfaces as Error::WsTransport.
Sourcepub async fn subscribe_pnl(&mut self) -> Result<Subscription>
pub async fn subscribe_pnl(&mut self) -> Result<Subscription>
Subscribe to PnL updates. Returns a Subscription you can
cancel later.
§Errors
Any send failure surfaces as Error::WsTransport.
Sourcepub async fn send_text(&mut self, payload: String) -> Result<()>
pub async fn send_text(&mut self, payload: String) -> Result<()>
Send a raw text frame. Useful for subscribing to topics Bezant doesn’t
yet model — follow the topic+{json} format.
§Errors
Any send failure surfaces as Error::other.
Sourcepub async fn next_message(&mut self) -> Result<Option<WsMessage>>
pub async fn next_message(&mut self) -> Result<Option<WsMessage>>
Pull the next decoded message. None means the socket closed.
§Errors
Any read failure surfaces as Error::other.
Sourcepub fn raw_stream(self) -> impl Stream<Item = Result<WsMessage>> + Unpin
pub fn raw_stream(self) -> impl Stream<Item = Result<WsMessage>> + Unpin
Return a Stream of WsMessages that yields until the socket
closes. Consuming this yields exclusive access to the reader; use
WsClient::next_message on the client itself if you also need to
send frames on the same task.
Sourcepub fn split(self) -> (WsSink, WsRecv)
pub fn split(self) -> (WsSink, WsRecv)
Split the client into independent sink + stream halves so one task can send and another can receive concurrently.
Returns concrete SplitSink/SplitStream types from
futures_util so callers can name them in struct fields
without resorting to Box<dyn …> or impl Trait-only
associated types.
Sourcepub const fn recommended_keepalive() -> Duration
pub const fn recommended_keepalive() -> Duration
How long to wait between application-level pings if you implement a ticker task on top. Chosen to match CPAPI’s 5-minute session timeout with a safety margin.