pub struct DataSocketConnection<S = LiveWebSocket> { /* private fields */ }Expand description
Typed market-data WebSocket manager.
§Reconnect (manual)
Auto-reconnect is not implemented. crate::models::ws::DataSocketConfig
accepts reconnect and reconnect_retry fields and they’re stored on the
connection, but no internal loop consumes them — next_event returns
Ok(None) on disconnect and stays closed.
To recover from a disconnect, drop the connection and build a new one:
loop {
let mut socket = client.data_socket().connect().await?;
socket.subscribe(&request).await?;
while let Some(event) = socket.next_event().await? {
// handle event
}
// disconnected — loop and reconnect from scratch.
// The HSM-token resolver runs again inside subscribe(), so this
// recovers correctly even if topic IDs have rotated.
}Subscribe state from the previous session is held in
Self::resubscribe_frames for inspection, but it’s the user-facing
JSON of the original DataSubscribeRequest values, not the binary
frames sent on the wire — the binary frames carry freshly resolved HSM
tokens that must be re-fetched.
Implementations§
Source§impl<S> DataSocketConnection<S>
impl<S> DataSocketConnection<S>
Sourcepub fn from_stream(
stream: S,
client: FyersClient,
config: DataSocketConfig,
) -> Result<Self>
pub fn from_stream( stream: S, client: FyersClient, config: DataSocketConfig, ) -> Result<Self>
Create a manager from an already connected stream and a client.
client must have an access token configured — its JWT payload is
decoded immediately to extract the hsm_key claim used by the binary
auth frame.
Sourcepub const fn config(&self) -> &DataSocketConfig
pub const fn config(&self) -> &DataSocketConfig
Manager configuration.
Sourcepub const fn socket(&self) -> &ManagedSocket<S, DataSocketEvent>
pub const fn socket(&self) -> &ManagedSocket<S, DataSocketEvent>
Underlying generic socket manager.
Sourcepub const fn socket_mut(&mut self) -> &mut ManagedSocket<S, DataSocketEvent>
pub const fn socket_mut(&mut self) -> &mut ManagedSocket<S, DataSocketEvent>
Mutable access to the underlying generic socket manager.
Sourcepub async fn handshake(&mut self) -> Result<()>
pub async fn handshake(&mut self) -> Result<()>
Send the documented auth + mode + channel-resume handshake frames.
The mode (full vs lite) is taken from DataSocketConfig::lite_mode.
Each frame is sent without waiting for the corresponding ack — acks
arrive as DataSocketEvent::Connected / DataSocketEvent::Mode
events the next time Self::next_event is polled.
Sourcepub async fn subscribe(&mut self, request: &DataSubscribeRequest) -> Result<()>
pub async fn subscribe(&mut self, request: &DataSubscribeRequest) -> Result<()>
Subscribe to symbol or depth updates.
Resolves each symbol against /data/symbol-token, builds the binary
subscribe frame, and sends it. The subscribe ack arrives later as
DataSocketEvent::Subscribed.
Sourcepub async fn unsubscribe(
&mut self,
request: &DataUnsubscribeRequest,
) -> Result<()>
pub async fn unsubscribe( &mut self, request: &DataUnsubscribeRequest, ) -> Result<()>
Unsubscribe from symbol or depth updates.
Sourcepub fn resubscribe_frames(&self) -> Result<Vec<String>>
pub fn resubscribe_frames(&self) -> Result<Vec<String>>
Active subscribe commands, returned for resubscribe-after-reconnect flows.
These are JSON-serialized representations of the user-facing
DataSubscribeRequest values, not the binary frames sent on the
wire — the binary frames depend on freshly resolved HSM tokens that
must be re-fetched after a reconnect.
Sourcepub async fn next_event(&mut self) -> Result<Option<DataSocketEvent>>
pub async fn next_event(&mut self) -> Result<Option<DataSocketEvent>>
Receive the next typed market-data event.