pub struct WebSocketClient { /* private fields */ }Expand description
Synchronous WebSocket client.
All operations block the caller. No tokio runtime required. Internally owns one OS thread per active connection (the supervisor/owner thread).
Implementations§
Source§impl WebSocketClient
impl WebSocketClient
Sourcepub fn new(config: ConnectionConfig) -> Self
pub fn new(config: ConnectionConfig) -> Self
Create a new WebSocket client with default reconnection + health check config.
Sourcepub fn with_reconnection_config(
config: ConnectionConfig,
reconnection_config: ReconnectionConfig,
) -> Self
pub fn with_reconnection_config( config: ConnectionConfig, reconnection_config: ReconnectionConfig, ) -> Self
Create a new WebSocket client with custom reconnection config.
Sourcepub fn with_health_check_config(
config: ConnectionConfig,
health_check_config: HealthCheckConfig,
) -> Self
pub fn with_health_check_config( config: ConnectionConfig, health_check_config: HealthCheckConfig, ) -> Self
Create a new WebSocket client with custom health check config.
Sourcepub fn with_full_config(
config: ConnectionConfig,
reconnection_config: ReconnectionConfig,
health_check_config: HealthCheckConfig,
) -> Self
pub fn with_full_config( config: ConnectionConfig, reconnection_config: ReconnectionConfig, health_check_config: HealthCheckConfig, ) -> Self
Create a new WebSocket client with full custom config.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Current connection state (snapshot).
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true once the client has been disconnected and cannot be reused.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
True iff the supervisor reports a Connected state.
Sourcepub fn events(&self) -> &Arc<Mutex<Receiver<ConnectionEvent>>>
pub fn events(&self) -> &Arc<Mutex<Receiver<ConnectionEvent>>>
Reference to the event receiver. Lifecycle events arrive here (bounded channel, drop-newest on saturation).
Sourcepub fn state_events(&self) -> &Arc<Mutex<Receiver<ConnectionEvent>>>
pub fn state_events(&self) -> &Arc<Mutex<Receiver<ConnectionEvent>>>
Semantic alias for events.
Sourcepub fn messages(&self) -> Arc<MessageReceiver>
pub fn messages(&self) -> Arc<MessageReceiver>
Get the blocking inbound-message receiver. Idempotent; subsequent calls
return the same Arc<MessageReceiver>.
Sourcepub fn connect(&self) -> Result<(), MarketDataError>
pub fn connect(&self) -> Result<(), MarketDataError>
Connect to the WebSocket server and authenticate. Blocks until either authentication succeeds or fails.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn disconnect(&self) -> Result<(), MarketDataError>
pub fn disconnect(&self) -> Result<(), MarketDataError>
Disconnect gracefully with the default drain timeout
(DEFAULT_SHUTDOWN_TIMEOUT, 5 seconds).
See shutdown_with_timeout for
detailed sequencing — this is a thin wrapper.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn shutdown_with_timeout(
&self,
timeout_dur: Duration,
) -> Result<(), MarketDataError>
pub fn shutdown_with_timeout( &self, timeout_dur: Duration, ) -> Result<(), MarketDataError>
Disconnect with a caller-supplied drain timeout.
Sequence:
- Set the supervisor’s
should_stopflag. - Drop the writer-side sender so the owner loop’s drain step cannot pick up new frames.
- Wait up to
timeout_durfor the supervisor thread to signal exit (the owner loop pollsshould_stopeveryREAD_POLL_INTERVAL, drains its write queue, sends Close, then waits up to ~2 s for the peer’s Close ack). - On signal: best-effort
jointhe thread. - On timeout: leave the thread to wind down on its own (it has already been instructed to stop and will not resurrect the connection); detach the handle.
- Emit
Disconnected { intent: Client }and update state.
timeout_dur of zero is valid and behaves as “fire-and-forget”:
the call returns immediately, the supervisor exits in the
background.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn force_close(&self) -> Result<(), MarketDataError>
pub fn force_close(&self) -> Result<(), MarketDataError>
Force-close without waiting for the supervisor.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn subscribe(&self, sub: StockSubscription) -> Result<(), MarketDataError>
pub fn subscribe(&self, sub: StockSubscription) -> Result<(), MarketDataError>
Subscribe to a stock-domain stream.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn subscribe_futopt(
&self,
sub: FutOptSubscription,
) -> Result<(), MarketDataError>
pub fn subscribe_futopt( &self, sub: FutOptSubscription, ) -> Result<(), MarketDataError>
Subscribe to a FutOpt-domain stream.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn unsubscribe(
&self,
ids: impl IntoIterator<Item = impl Into<String>>,
) -> Result<(), MarketDataError>
pub fn unsubscribe( &self, ids: impl IntoIterator<Item = impl Into<String>>, ) -> Result<(), MarketDataError>
Unsubscribe by server id or local key.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn subscriptions(&self) -> Vec<SubscribeRequest>
pub fn subscriptions(&self) -> Vec<SubscribeRequest>
Get all active subscriptions.
Sourcepub fn subscription_keys(&self) -> Vec<String>
pub fn subscription_keys(&self) -> Vec<String>
Get list of active subscription keys.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Number of currently active subscriptions.
Sourcepub fn messages_dropped_total(&self) -> u64
pub fn messages_dropped_total(&self) -> u64
Total number of inbound messages dropped due to consumer-side channel saturation since this client was constructed.
Drop-newest backpressure: when the message buffer is full, new
arrivals are discarded rather than blocking the read thread. A
non-zero value usually indicates the consumer (messages()
reader) is too slow or stalled.
Sourcepub fn events_dropped_total(&self) -> u64
pub fn events_dropped_total(&self) -> u64
Total number of lifecycle ConnectionEvents dropped due to event-
channel saturation since this client was constructed.
Mirrors Self::messages_dropped_total for the lifecycle event
channel. Drop-newest backpressure: when the event channel is full,
new events are discarded rather than blocking the supervisor.
Counter is monotonic and thread-safe (AtomicU64).
Sourcepub fn is_subscribed(&self, channel: &Channel, symbol: &str) -> bool
pub fn is_subscribed(&self, channel: &Channel, symbol: &str) -> bool
Returns true iff at least one active subscription matches the
given channel and symbol. Modifier-suffixed forms (:afterhours,
:oddlot) are matched alongside the base form.
Sourcepub fn reconnect(&self) -> Result<(), MarketDataError>
pub fn reconnect(&self) -> Result<(), MarketDataError>
Manually reconnect. Calls disconnect() then connect() — simpler and safer than poking the supervisor.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.
Sourcepub fn send(&self, request: WebSocketRequest) -> Result<(), MarketDataError>
pub fn send(&self, request: WebSocketRequest) -> Result<(), MarketDataError>
Send an arbitrary WebSocket request frame.
§Errors
Returns MarketDataError on transport, protocol, deserialization,
validation, or peer-initiated failures.