Skip to main content

Module websocket

Module websocket 

Source
Expand description

WebSocket client for real-time market data and account-scoped updates.

Connects to the Hypercall WS endpoint (/ws) for streaming:

  • Public: orderbook, trades, index prices, options chain
  • Account-scoped: order updates, fills, portfolio, position changes

§Example

use hypercall_client::WsClient;

let ws = WsClient::new();
ws.connect("https://api.hypercall.xyz", None).await?;

// Subscribe to fills (options + perps, distinguished by instrument_type)
ws.subscribe(vec!["fills", "order_updates"]).await?;

// Wait for a message
let msg = ws.wait_for_message(|_| true, 5000).await;
println!("{:?}", msg);

§Channels

ChannelAuthDescription
orderbookNoL2 orderbook updates (filterable by symbols)
tradesNoPublic trade events
index_pricesNoSpot/index prices for all underlyings
indicative_market_dataNoAggregated quote-provider prices, one row per frame
indicative_market_data_v2NoThe same prices in batch frames, see WsClient::subscribe_indicative_market_data
order_updatesYesOrder status changes (includes instrument_type)
fillsYesFill notifications (includes instrument_type)
portfolioYesPortfolio balance + position updates

§Compression

The client offers RFC 7692 permessage-deflate on every connection. When the server accepts, compressed frames are inflated transparently, with the same size limit as uncompressed messages; when it does not, the connection runs uncompressed with identical JSON messages. Opt out with WsClient::with_permessage_deflate.

§Batched indicative market data

WsClient::subscribe_indicative_market_data subscribes to indicative_market_data_v2, which delivers IndicativeMarketDataBatch frames, each carrying the rows of one short batch window. Servers that predate that channel confirm any channel name, so the client checks the confirmation: only {"type":"Subscribed","channel":"indicative_market_data_v2","batch":true} means the server batches. Any other confirmation makes the client switch that subscription to indicative_market_data (one row per frame) for the rest of the client’s life. crate::indicative decodes both. Opt out with WsClient::with_batched_indicative.

Structs§

WsClient
WebSocket client for Hypercall.
WsClientConfig
Reconnection and handshake policy for WsClient.
WsRecoveryPlan
Application work required before state is continuous after a reconnect.

Enums§

WsConnectionState
Current lifecycle state of the client-managed WebSocket session.
WsDisconnectReason
Why an established WebSocket session ended.