pub struct WsClient { /* private fields */ }Expand description
WebSocket client for Hypercall.
Implementations§
Source§impl WsClient
impl WsClient
Sourcepub fn with_config(config: WsClientConfig) -> Self
pub fn with_config(config: WsClientConfig) -> Self
Create a WebSocket client with an explicit reconnection policy.
Sourcepub fn with_permessage_deflate(self, enabled: bool) -> Self
pub fn with_permessage_deflate(self, enabled: bool) -> Self
Choose whether to offer RFC 7692 permessage-deflate when connecting.
Enabled by default. The server decides whether to accept, and the client works either way: compressed frames are inflated transparently, and the JSON messages are identical. Disable it to save the CPU spent inflating, or to rule compression out while debugging. The setting applies to the initial connection and every reconnect.
Sourcepub fn with_batched_indicative(self, enabled: bool) -> Self
pub fn with_batched_indicative(self, enabled: bool) -> Self
Choose whether WsClient::subscribe_indicative_market_data uses
the batched indicative_market_data_v2 channel.
Enabled by default: fewer frames, rows up to one short batch window
later, and much better compression. Disable it to receive one
IndicativeMarketData frame per row from indicative_market_data.
Sourcepub fn indicative_batched(&self) -> bool
pub fn indicative_batched(&self) -> bool
Whether indicative subscriptions are currently delivered in batches: batching is enabled and no server has shown it lacks the v2 channel.
Sourcepub async fn connect(
&self,
base_url: &str,
wallet: Option<&AccountAddress>,
) -> Result<()>
pub async fn connect( &self, base_url: &str, wallet: Option<&AccountAddress>, ) -> Result<()>
Connect to the WebSocket endpoint.
If a wallet is provided, sends an Authenticate message after connecting
and waits for the Authenticated confirmation before returning. After
the initial connection succeeds, the client reconnects, reauthenticates,
and restores desired subscriptions until WsClient::disconnect is called
or the client is dropped.
Sourcepub async fn connect_rfq_v2(
&self,
base_url: &str,
grant: &RfqV2ReadGrant,
) -> Result<()>
pub async fn connect_rfq_v2( &self, base_url: &str, grant: &RfqV2ReadGrant, ) -> Result<()>
Connect using a signed private RFQ read grant. The grant is sent again before subscriptions on reconnect. Once it expires, sign a fresh grant and create a new session; no unsigned wallet identity grants RFQ access.
Sourcepub async fn ping_with_payload(&self, payload: impl Into<Vec<u8>>) -> Result<()>
pub async fn ping_with_payload(&self, payload: impl Into<Vec<u8>>) -> Result<()>
Send a WebSocket ping frame with a payload.
WebSocket control frame payloads are limited to 125 bytes by the protocol.
Sourcepub async fn pong_with_payload(&self, payload: impl Into<Vec<u8>>) -> Result<()>
pub async fn pong_with_payload(&self, payload: impl Into<Vec<u8>>) -> Result<()>
Send a WebSocket pong frame with a payload.
This is rarely needed directly because WsClient automatically responds
to server ping frames.
Sourcepub async fn subscribe_rfq_v2(&self) -> Result<()>
pub async fn subscribe_rfq_v2(&self) -> Result<()>
Send a subscription request for private RFQ V2 change hints. Ok means
the frame was sent; observe Subscribed or Error for server acceptance.
Use a periodic signed change-feed read to recover hints lost while a
socket stays connected.
Sourcepub async fn unsubscribe_rfq_v2(&self) -> Result<()>
pub async fn unsubscribe_rfq_v2(&self) -> Result<()>
Remove the RFQ V2 subscription, including its reconnect intent.
Sourcepub async fn subscribe_with_options(
&self,
channel: &str,
symbols: Option<Vec<String>>,
expiry: Option<String>,
option_type: Option<String>,
) -> Result<()>
pub async fn subscribe_with_options( &self, channel: &str, symbols: Option<Vec<String>>, expiry: Option<String>, option_type: Option<String>, ) -> Result<()>
Subscribe to a channel and retain its filters across reconnects.
Sourcepub async fn subscribe_indicative_market_data(
&self,
symbols: Option<Vec<String>>,
) -> Result<()>
pub async fn subscribe_indicative_market_data( &self, symbols: Option<Vec<String>>, ) -> Result<()>
Subscribe to indicative market data and retain the subscription across reconnects.
By default this uses indicative_market_data_v2, whose
IndicativeMarketDataBatch frames carry the rows of one short batch
window. If the server confirms v2 without "batch": true (it predates
the channel), the client switches to indicative_market_data, one
IndicativeMarketData frame per row. Read rows with
crate::indicative::indicative_rows_from_value, which handles both.
The server keeps one symbol filter per channel per connection: every
Subscribe adds symbols to it, and a filtered subscribe narrows an
unfiltered one. If you also subscribe to indicative_market_data
directly with a different filter, a fallback onto v1 shares that one
server filter with your direct subscription. Use one or the other per
connection when exact filters matter.
Sourcepub async fn unsubscribe_indicative_market_data(&self) -> Result<()>
pub async fn unsubscribe_indicative_market_data(&self) -> Result<()>
Stop the subscriptions made by
WsClient::subscribe_indicative_market_data, on whichever channel
each resolved to after a fallback, and stop restoring them after
reconnects. Subscriptions made with WsClient::subscribe_with_options
on either indicative channel are left alone.
Sourcepub async fn unsubscribe(&self, channels: Vec<&str>) -> Result<()>
pub async fn unsubscribe(&self, channels: Vec<&str>) -> Result<()>
Unsubscribe from channels and stop restoring them after reconnects.
Channels match exactly, and only subscriptions made directly (for
example with WsClient::subscribe_with_options) are released. To
stop a subscription made by
WsClient::subscribe_indicative_market_data, which may have moved
from indicative_market_data_v2 to indicative_market_data, use
WsClient::unsubscribe_indicative_market_data. If both own the same
channel and filter, the server subscription ends when both release it.
Sourcepub async fn disconnect(&self)
pub async fn disconnect(&self)
Stop reconnecting and close the current socket.
Sourcepub fn connection_state(&self) -> WsConnectionState
pub fn connection_state(&self) -> WsConnectionState
Return the current connection and recovery state.
Sourcepub fn connection_state_receiver(&self) -> Receiver<WsConnectionState>
pub fn connection_state_receiver(&self) -> Receiver<WsConnectionState>
Watch connection and recovery state transitions.
Sourcepub fn last_disconnect_reason(&self) -> Option<WsDisconnectReason>
pub fn last_disconnect_reason(&self) -> Option<WsDisconnectReason>
Return the most recent established-session disconnect reason.
Sourcepub fn mark_recovered(&self) -> Result<()>
pub fn mark_recovered(&self) -> Result<()>
Mark application-owned snapshot or REST recovery as complete.
Sourcepub async fn clear_pongs(&self)
pub async fn clear_pongs(&self)
Clear all received WebSocket pong payloads.
Sourcepub async fn wait_for_pong<F>(
&self,
check: F,
timeout_ms: u64,
) -> Option<Vec<u8>>
pub async fn wait_for_pong<F>( &self, check: F, timeout_ms: u64, ) -> Option<Vec<u8>>
Wait for a pong payload matching a predicate.
Sourcepub async fn get_messages(&self) -> Vec<Value>
pub async fn get_messages(&self) -> Vec<Value>
Get all received messages.
Sourcepub async fn clear_messages(&self)
pub async fn clear_messages(&self)
Clear all received messages.
Sourcepub async fn wait_for_message<F>(
&self,
check: F,
timeout_ms: u64,
) -> Option<Value>
pub async fn wait_for_message<F>( &self, check: F, timeout_ms: u64, ) -> Option<Value>
Wait for a message matching a predicate.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WsClient
impl !RefUnwindSafe for WsClient
impl !UnwindSafe for WsClient
impl Send for WsClient
impl Sync for WsClient
impl Unpin for WsClient
impl UnsafeUnpin for WsClient
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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