Skip to main content

DataSocketConnection

Struct DataSocketConnection 

Source
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>
where S: Stream<Item = Result<Message, Error>> + Sink<Message, Error = Error> + Unpin,

Source

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.

Source

pub const fn config(&self) -> &DataSocketConfig

Manager configuration.

Source

pub const fn socket(&self) -> &ManagedSocket<S, DataSocketEvent>

Underlying generic socket manager.

Source

pub const fn socket_mut(&mut self) -> &mut ManagedSocket<S, DataSocketEvent>

Mutable access to the underlying generic socket manager.

Source

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.

Source

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.

Source

pub async fn unsubscribe( &mut self, request: &DataUnsubscribeRequest, ) -> Result<()>

Unsubscribe from symbol or depth updates.

Source

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.

Source

pub async fn next_event(&mut self) -> Result<Option<DataSocketEvent>>

Receive the next typed market-data event.

Source

pub const fn ack_count(&self) -> u32

Server-advertised ack threshold from field 2 of the auth response. Zero until the first auth ack is processed.

Source

pub async fn close(&mut self) -> Result<()>

Close the socket.

Trait Implementations§

Source§

impl<S: Debug> Debug for DataSocketConnection<S>

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