Exchange

Trait Exchange 

Source
pub trait Exchange: Send + Sync {
Show 26 methods // Required methods fn id(&self) -> &str; fn name(&self) -> &str; fn capabilities(&self) -> ExchangeCapabilities; fn fetch_markets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Market>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; fn load_markets<'life0, 'async_trait>( &'life0 self, reload: bool, ) -> Pin<Box<dyn Future<Output = Result<Arc<HashMap<String, Arc<Market>>>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; fn fetch_ticker<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Ticker, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_tickers<'life0, 'life1, 'async_trait>( &'life0 self, symbols: Option<&'life1 [String]>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ticker>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_order_book<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<OrderBook, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_ohlcv<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, timeframe: Timeframe, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ohlcv>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn create_order<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, order_type: OrderType, side: OrderSide, amount: Amount, price: Option<Price>, ) -> Pin<Box<dyn Future<Output = Result<Order, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn cancel_order<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Order, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait; fn cancel_all_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_order<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, symbol: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Order, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait; fn fetch_open_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_closed_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn fetch_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Balance, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; fn fetch_my_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn market<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Arc<Market>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn markets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Arc<HashMap<String, Arc<Market>>>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; // Provided methods fn version(&self) -> &'static str { ... } fn certified(&self) -> bool { ... } fn has_websocket(&self) -> bool { ... } fn timeframes(&self) -> Vec<Timeframe> { ... } fn rate_limit(&self) -> u32 { ... } fn is_symbol_active<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait { ... }
}
Expand description

Core Exchange trait - the unified interface for all exchanges

This trait defines the standard API that all exchange implementations must provide. It is designed to be object-safe for dynamic dispatch, allowing exchanges to be used polymorphically via dyn Exchange.

§Relationship to Modular Traits

The Exchange trait provides a unified interface that combines functionality from the modular trait hierarchy:

  • PublicExchange: Metadata and capabilities (id, name, capabilities, etc.)
  • MarketData: Public market data (fetch_markets, fetch_ticker, etc.)
  • Trading: Order management (create_order, cancel_order, etc.)
  • Account: Account operations (fetch_balance, fetch_my_trades)
  • Margin: Margin/futures operations (available via separate trait)
  • Funding: Deposit/withdrawal operations (available via separate trait)

For new implementations, consider implementing the modular traits instead, which allows for more granular capability composition. Types implementing all modular traits automatically satisfy the requirements for Exchange.

§Thread Safety

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

§Backward Compatibility

This trait maintains full backward compatibility with existing code. All methods from the original monolithic trait are still available. Existing implementations continue to work without modification.

§Example

use ccxt_core::exchange::Exchange;

async fn print_exchange_info(exchange: &dyn Exchange) {
    println!("Exchange: {} ({})", exchange.name(), exchange.id());
    println!("Version: {}", exchange.version());
    println!("Certified: {}", exchange.certified());
}

Required Methods§

Source

fn id(&self) -> &str

Returns the exchange identifier (e.g., “binance”, “coinbase”)

This is a lowercase, URL-safe identifier used internally.

Source

fn name(&self) -> &str

Returns the human-readable exchange name (e.g., “Binance”, “Coinbase”)

Source

fn capabilities(&self) -> ExchangeCapabilities

Returns the exchange capabilities

Use this to check which features are supported before calling methods.

Source

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

Fetch all available markets

§Returns

A vector of Market structs containing market definitions.

§Errors

Returns an error if the request fails or the exchange is unavailable.

Source

fn load_markets<'life0, 'async_trait>( &'life0 self, reload: bool, ) -> Pin<Box<dyn Future<Output = Result<Arc<HashMap<String, Arc<Market>>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Load markets and cache them

§Arguments
  • reload - If true, force reload even if markets are cached
§Returns

A HashMap of markets indexed by symbol.

Source

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

Fetch ticker for a single symbol

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

The ticker data for the specified symbol.

Source

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

Fetch tickers for multiple symbols (or all if None)

§Arguments
  • symbols - Optional list of symbols to fetch. If None, fetches all.
§Returns

A vector of tickers.

Source

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

Fetch order book for a symbol

§Arguments
  • symbol - Trading pair symbol
  • limit - Optional limit on the number of orders per side
§Returns

The order book containing bids and asks.

Source

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

Fetch recent public trades

§Arguments
  • symbol - Trading pair symbol
  • limit - Optional limit on the number of trades
§Returns

A vector of recent trades.

Source

fn fetch_ohlcv<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, timeframe: Timeframe, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ohlcv>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Fetch OHLCV candlestick data

§Arguments
  • symbol - Trading pair symbol
  • timeframe - Candlestick timeframe
  • since - Optional start timestamp in milliseconds
  • limit - Optional limit on the number of candles
§Returns

A vector of OHLCV candles.

Source

fn create_order<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, order_type: OrderType, side: OrderSide, amount: Amount, price: Option<Price>, ) -> Pin<Box<dyn Future<Output = Result<Order, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Create a new order

§Arguments
  • symbol - Trading pair symbol
  • order_type - Order type (limit, market, etc.)
  • side - Order side (buy or sell)
  • amount - Order amount (type-safe Amount wrapper)
  • price - Optional price (required for limit orders, type-safe Price wrapper)
§Returns

The created order.

§Errors

Returns an error if authentication fails or the order is invalid.

Source

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

Cancel an existing order

§Arguments
  • id - Order ID to cancel
  • symbol - Optional symbol (required by some exchanges)
§Returns

The canceled order.

Source

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

Cancel all orders (optionally for a specific symbol)

§Arguments
  • symbol - Optional symbol to cancel orders for
§Returns

A vector of canceled orders.

Source

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

Fetch a specific order by ID

§Arguments
  • id - Order ID
  • symbol - Optional symbol (required by some exchanges)
§Returns

The order details.

Source

fn fetch_open_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Fetch all open orders

§Arguments
  • symbol - Optional symbol to filter by
  • since - Optional start timestamp
  • limit - Optional limit on results
§Returns

A vector of open orders.

Source

fn fetch_closed_orders<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Fetch closed orders

§Arguments
  • symbol - Optional symbol to filter by
  • since - Optional start timestamp
  • limit - Optional limit on results
§Returns

A vector of closed orders.

Source

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

Fetch account balance

§Returns

The account balance containing all currencies.

Source

fn fetch_my_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, since: Option<i64>, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Fetch user’s trade history

§Arguments
  • symbol - Optional symbol to filter by
  • since - Optional start timestamp
  • limit - Optional limit on results
§Returns

A vector of user’s trades.

Source

fn market<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Arc<Market>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Get a specific market by symbol

§Arguments
  • symbol - Trading pair symbol
§Returns

The market definition.

§Errors

Returns an error if the market is not found or markets are not loaded.

Source

fn markets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Arc<HashMap<String, Arc<Market>>>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Get all cached markets

§Returns

A HashMap of all markets indexed by symbol.

Provided Methods§

Source

fn version(&self) -> &'static str

Returns the API version string

Source

fn certified(&self) -> bool

Returns whether this exchange is CCXT certified

Certified exchanges have been thoroughly tested and verified.

Source

fn has_websocket(&self) -> bool

Returns whether this exchange supports WebSocket (pro features)

Source

fn timeframes(&self) -> Vec<Timeframe>

Returns supported timeframes for OHLCV data

Source

fn rate_limit(&self) -> u32

Returns the rate limit (requests per second)

Source

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

Check if a symbol is valid and active

§Arguments
  • symbol - Trading pair symbol
§Returns

True if the symbol exists and is active.

Implementors§