WsEvent

Enum WsEvent 

Source
pub enum WsEvent {
    Connecting,
    Connected,
    Disconnected,
    Reconnecting {
        attempt: u32,
        delay: Duration,
        error: Option<String>,
    },
    ReconnectSuccess,
    ReconnectFailed {
        attempt: u32,
        error: String,
        is_permanent: bool,
    },
    ReconnectExhausted {
        total_attempts: u32,
        last_error: String,
    },
    SubscriptionRestored,
    PermanentError {
        error: String,
    },
    Shutdown,
}
Expand description

WebSocket connection event types.

These events are emitted during the WebSocket connection lifecycle to notify listeners about state changes, reconnection attempts, and errors.

§Example

use ccxt_core::ws_client::WsEvent;
use std::time::Duration;

fn handle_event(event: WsEvent) {
    match event {
        WsEvent::Connecting => println!("Connecting..."),
        WsEvent::Connected => println!("Connected!"),
        WsEvent::Disconnected => println!("Disconnected"),
        WsEvent::Reconnecting { attempt, delay, error } => {
            println!("Reconnecting (attempt {}), delay: {:?}, error: {:?}",
                     attempt, delay, error);
        }
        WsEvent::ReconnectSuccess => println!("Reconnected successfully"),
        WsEvent::ReconnectFailed { attempt, error, is_permanent } => {
            println!("Reconnect failed (attempt {}): {}, permanent: {}",
                     attempt, error, is_permanent);
        }
        WsEvent::ReconnectExhausted { total_attempts, last_error } => {
            println!("All {} reconnect attempts exhausted: {}",
                     total_attempts, last_error);
        }
        WsEvent::SubscriptionRestored => println!("Subscriptions restored"),
        WsEvent::PermanentError { error } => {
            println!("Permanent error (no retry): {}", error);
        }
        WsEvent::Shutdown => println!("Shutdown complete"),
    }
}

Variants§

§

Connecting

Connection attempt started.

Emitted when the client begins establishing a WebSocket connection.

§

Connected

Connection established successfully.

Emitted when the WebSocket handshake completes and the connection is ready.

§

Disconnected

Connection closed.

Emitted when the WebSocket connection is closed, either gracefully or due to an error.

§

Reconnecting

Reconnection in progress.

Emitted before each reconnection attempt with details about the attempt.

Fields

§attempt: u32

Current reconnection attempt number (1-indexed).

§delay: Duration

Delay before this reconnection attempt (calculated by backoff strategy).

§error: Option<String>

Error that triggered the reconnection (if any).

§

ReconnectSuccess

Reconnection succeeded.

Emitted when a reconnection attempt successfully establishes a new connection.

§

ReconnectFailed

Single reconnection attempt failed.

Emitted when a reconnection attempt fails. More attempts may follow unless is_permanent is true or max attempts is reached.

Fields

§attempt: u32

The attempt number that failed (1-indexed).

§error: String

Error message describing the failure.

§is_permanent: bool

Whether this is a permanent error that should not be retried.

If true, no further reconnection attempts will be made.

§

ReconnectExhausted

All reconnection attempts exhausted.

Emitted when the maximum number of reconnection attempts has been reached without successfully reconnecting. No further automatic reconnection will occur.

Fields

§total_attempts: u32

Total number of reconnection attempts made.

§last_error: String

The last error encountered.

§

SubscriptionRestored

Subscriptions restored after reconnection.

Emitted after a successful reconnection when all previous subscriptions have been re-established.

§

PermanentError

Permanent error occurred (no retry).

Emitted when a permanent error is encountered that cannot be recovered through retries (e.g., authentication failure, invalid credentials).

Fields

§error: String

Error message describing the permanent failure.

§

Shutdown

Shutdown completed.

Emitted when the WebSocket client has completed its graceful shutdown process, including cancelling pending operations and closing connections.

Implementations§

Source§

impl WsEvent

Source

pub fn is_connecting(&self) -> bool

Returns true if this is a Connecting event.

Source

pub fn is_connected(&self) -> bool

Returns true if this is a Connected event.

Source

pub fn is_disconnected(&self) -> bool

Returns true if this is a Disconnected event.

Source

pub fn is_reconnecting(&self) -> bool

Returns true if this is a Reconnecting event.

Source

pub fn is_reconnect_success(&self) -> bool

Returns true if this is a ReconnectSuccess event.

Source

pub fn is_reconnect_failed(&self) -> bool

Returns true if this is a ReconnectFailed event.

Source

pub fn is_reconnect_exhausted(&self) -> bool

Returns true if this is a ReconnectExhausted event.

Source

pub fn is_subscription_restored(&self) -> bool

Returns true if this is a SubscriptionRestored event.

Source

pub fn is_permanent_error(&self) -> bool

Returns true if this is a PermanentError event.

Source

pub fn is_shutdown(&self) -> bool

Returns true if this is a Shutdown event.

Source

pub fn is_error(&self) -> bool

Returns true if this event indicates an error condition.

This includes ReconnectFailed, ReconnectExhausted, and PermanentError.

Source

pub fn is_terminal(&self) -> bool

Returns true if this event indicates a terminal state.

Terminal states are those where no further automatic recovery will occur: ReconnectExhausted, PermanentError, and Shutdown.

Trait Implementations§

Source§

impl Clone for WsEvent

Source§

fn clone(&self) -> WsEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WsEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for WsEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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