Skip to main content

WsClient

Struct WsClient 

Source
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

Source

pub async fn connect(client: &Client) -> Result<Self>

Open a WebSocket connection to the Gateway that client is pointed at.

Internally:

  1. Issues a /tickle HTTP call to mint a session cookie.
  2. Derives the wss://…/ws URL from the REST base URL.
  3. Attaches Cookie: api={"session":"…"} to the WS handshake.
  4. Returns a connected WsClient.
§Errors

Any tickle / handshake / TLS failure surfaces as Error.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for WsClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more