WsExchange

Trait WsExchange 

Source
pub trait WsExchange: Send + Sync {
Show 15 methods // Required methods fn ws_connect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn ws_disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn ws_is_connected(&self) -> bool; fn ws_state(&self) -> WsConnectionState; fn watch_ticker<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Ticker>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn watch_tickers<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Vec<Ticker>>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn watch_order_book<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<OrderBook>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn watch_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Vec<Trade>>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn watch_ohlcv<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, timeframe: Timeframe, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Ohlcv>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn watch_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Balance>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn watch_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Order>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn watch_my_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Trade>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn subscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, channel: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn unsubscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, channel: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn subscriptions(&self) -> Vec<String>;
}
Expand description

WebSocket exchange trait for real-time data streaming

This trait defines the WebSocket API that exchanges can implement for real-time market data and account updates.

§Thread Safety

All implementations must be Send + Sync to allow safe usage across thread boundaries.

§Example

use ccxt_core::ws_exchange::WsExchange;

async fn check_connection(exchange: &dyn WsExchange) {
    if !exchange.ws_is_connected() {
        exchange.ws_connect().await.unwrap();
    }
    println!("Connection state: {:?}", exchange.ws_state());
}

Required Methods§

Source

fn ws_connect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Connect to the WebSocket server

Establishes a WebSocket connection to the exchange. If already connected, this may be a no-op or reconnect.

§Errors

Returns an error if the connection fails.

Source

fn ws_disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disconnect from the WebSocket server

Closes the WebSocket connection gracefully.

§Errors

Returns an error if disconnection fails.

Source

fn ws_is_connected(&self) -> bool

Check if WebSocket is connected

§Returns

True if the WebSocket connection is active.

Source

fn ws_state(&self) -> WsConnectionState

Get WebSocket connection state

§Returns

The current connection state.

Source

fn watch_ticker<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Ticker>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch ticker updates for a symbol

§Arguments
  • symbol - Trading pair symbol (e.g., “BTC/USDT”)
§Returns

A stream of ticker updates.

§Errors

Returns an error if subscription fails.

Source

fn watch_tickers<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Vec<Ticker>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch tickers for multiple symbols

§Arguments
  • symbols - List of trading pair symbols
§Returns

A stream of ticker vectors.

Source

fn watch_order_book<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<OrderBook>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch order book updates

§Arguments
  • symbol - Trading pair symbol
  • limit - Optional depth limit
§Returns

A stream of order book updates.

Source

fn watch_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Vec<Trade>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch public trades

§Arguments
  • symbol - Trading pair symbol
§Returns

A stream of trade vectors.

Source

fn watch_ohlcv<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, timeframe: Timeframe, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Ohlcv>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch OHLCV candlestick updates

§Arguments
  • symbol - Trading pair symbol
  • timeframe - Candlestick timeframe
§Returns

A stream of OHLCV updates.

Source

fn watch_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Balance>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Watch account balance updates

Requires authentication.

§Returns

A stream of balance updates.

§Errors

Returns an error if not authenticated or subscription fails.

Source

fn watch_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Order>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch order updates

Requires authentication.

§Arguments
  • symbol - Optional symbol to filter orders
§Returns

A stream of order updates.

Source

fn watch_my_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<MessageStream<Trade>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Watch user trade updates

Requires authentication.

§Arguments
  • symbol - Optional symbol to filter trades
§Returns

A stream of trade updates.

Source

fn subscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, channel: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Subscribe to a channel

§Arguments
  • channel - Channel name to subscribe to
  • symbol - Optional symbol for the subscription
§Errors

Returns an error if subscription fails.

Source

fn unsubscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, channel: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Unsubscribe from a channel

§Arguments
  • channel - Channel name to unsubscribe from
  • symbol - Optional symbol for the subscription
§Errors

Returns an error if unsubscription fails.

Source

fn subscriptions(&self) -> Vec<String>

Get list of active subscriptions

§Returns

A vector of subscription identifiers.

Implementors§