O2WebSocket

Struct O2WebSocket 

Source
pub struct O2WebSocket {
    url: String,
    config: WsConfig,
    inner: Arc<Mutex<WsInner>>,
    connected: Arc<AtomicBool>,
    should_run: Arc<AtomicBool>,
    last_pong: Arc<Mutex<Instant>>,
    lifecycle_tx: Arc<Sender<WsLifecycleEvent>>,
    reader_handle: Option<JoinHandle<()>>,
    ping_handle: Option<JoinHandle<()>>,
}
Expand description

WebSocket client for O2 Exchange real-time data.

Supports auto-reconnect, subscription tracking, heartbeat, and per-subscription channels for safe concurrent access.

Fields§

§url: String§config: WsConfig§inner: Arc<Mutex<WsInner>>§connected: Arc<AtomicBool>§should_run: Arc<AtomicBool>§last_pong: Arc<Mutex<Instant>>§lifecycle_tx: Arc<Sender<WsLifecycleEvent>>§reader_handle: Option<JoinHandle<()>>§ping_handle: Option<JoinHandle<()>>

Implementations§

Source§

impl O2WebSocket

Source

pub async fn connect(url: &str) -> Result<Self, O2Error>

Connect to the O2 WebSocket endpoint.

Source

pub async fn connect_with_config( url: &str, config: WsConfig, ) -> Result<Self, O2Error>

Connect with custom configuration.

Source

async fn do_connect(&mut self) -> Result<(), O2Error>

Source

async fn read_loop( stream: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>, inner: Arc<Mutex<WsInner>>, connected: Arc<AtomicBool>, should_run: Arc<AtomicBool>, last_pong: Arc<Mutex<Instant>>, )

Source

async fn ping_loop( inner: Arc<Mutex<WsInner>>, connected: Arc<AtomicBool>, should_run: Arc<AtomicBool>, last_pong: Arc<Mutex<Instant>>, ping_interval: Duration, pong_timeout: Duration, )

Source

async fn reconnect_loop( url: &str, config: &WsConfig, inner: Arc<Mutex<WsInner>>, connected: Arc<AtomicBool>, should_run: Arc<AtomicBool>, last_pong: Arc<Mutex<Instant>>, lifecycle_tx: Arc<Sender<WsLifecycleEvent>>, )

Source

pub fn subscribe_lifecycle(&self) -> Receiver<WsLifecycleEvent>

Subscribe to lifecycle/reconnect events.

Source

async fn send_json(&self, value: Value) -> Result<(), O2Error>

Source

fn add_subscription(inner: &mut WsInner, sub: Value)

Source

pub fn is_connected(&self) -> bool

Check if the WebSocket is currently connected.

Source

pub async fn stream_depth( &self, market_id: &str, precision: &DepthPrecision, ) -> Result<TypedStream<DepthUpdate>, O2Error>

Subscribe to order book depth. Returns a stream of Result<DepthUpdate, O2Error>.

precision is a level index as a string (e.g. "1" for finest). Valid range: "1""18". The SDK sends 10^precision on the wire, matching the internal backend convention. All levels support live delta streaming.

Note: Prefer [O2Client::stream_depth] which validates precision and resolves market IDs by name.

Source

pub async fn stream_orders( &self, identities: &[Identity], ) -> Result<TypedStream<OrderUpdate>, O2Error>

Subscribe to order updates. Returns a stream of Result<OrderUpdate, O2Error>.

Source

pub async fn stream_trades( &self, market_id: &str, ) -> Result<TypedStream<TradeUpdate>, O2Error>

Subscribe to trades. Returns a stream of Result<TradeUpdate, O2Error>.

Source

pub async fn stream_balances( &self, identities: &[Identity], ) -> Result<TypedStream<BalanceUpdate>, O2Error>

Subscribe to balance updates. Returns a stream of Result<BalanceUpdate, O2Error>.

Source

pub async fn stream_nonce( &self, identities: &[Identity], ) -> Result<TypedStream<NonceUpdate>, O2Error>

Subscribe to nonce updates. Returns a stream of Result<NonceUpdate, O2Error>.

Source

pub async fn unsubscribe_depth(&self, market_id: &str) -> Result<(), O2Error>

Unsubscribe from depth updates.

Source

pub async fn unsubscribe_orders(&self) -> Result<(), O2Error>

Unsubscribe from order updates.

Source

pub async fn unsubscribe_trades(&self, market_id: &str) -> Result<(), O2Error>

Unsubscribe from trade updates.

Source

pub async fn unsubscribe_balances( &self, identities: &[Identity], ) -> Result<(), O2Error>

Unsubscribe from balance updates.

Source

pub async fn unsubscribe_nonce( &self, identities: &[Identity], ) -> Result<(), O2Error>

Unsubscribe from nonce updates.

Source

pub fn is_terminated(&self) -> bool

Check if the WebSocket has been permanently terminated (max reconnect attempts exhausted or explicitly stopped).

Source

pub async fn disconnect(&self) -> Result<(), O2Error>

Close the WebSocket connection and stop all tasks.

Trait Implementations§

Source§

impl Drop for O2WebSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

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
§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more