Expand description
Exchange trait hierarchy for modular capability composition Exchange trait hierarchy for modular capability composition.
This module provides a decomposed trait hierarchy that allows exchanges to implement only the capabilities they support, without requiring stub implementations for unsupported features.
§Trait Hierarchy
PublicExchange (base trait - metadata, capabilities)
│
├── MarketData (public market data)
├── Trading (order management)
├── Account (balance, trade history)
├── Margin (positions, leverage, funding)
└── Funding (deposits, withdrawals, transfers)
FullExchange = PublicExchange + MarketData + Trading + Account + Margin + Funding§Object Safety
All traits are designed to be object-safe, allowing for dynamic dispatch:
ⓘ
use ccxt_core::traits::{BoxedMarketData, BoxedTrading, BoxedFullExchange};
let market_data: BoxedMarketData = Box::new(my_exchange);
let trading: BoxedTrading = Box::new(my_exchange);
let full: BoxedFullExchange = Box::new(my_exchange);§Thread Safety
All traits require Send + Sync bounds for async runtime compatibility.
§Example
ⓘ
use ccxt_core::traits::{PublicExchange, MarketData, Trading};
// Exchange that only supports market data (no trading)
struct ReadOnlyExchange;
impl PublicExchange for ReadOnlyExchange {
fn id(&self) -> &str { "readonly" }
fn name(&self) -> &str { "Read Only Exchange" }
// ...
}
impl MarketData for ReadOnlyExchange {
// Only implement market data methods
}
// Full-featured exchange
struct FullFeaturedExchange;
impl PublicExchange for FullFeaturedExchange { /* ... */ }
impl MarketData for FullFeaturedExchange { /* ... */ }
impl Trading for FullFeaturedExchange { /* ... */ }
impl Account for FullFeaturedExchange { /* ... */ }
impl Margin for FullFeaturedExchange { /* ... */ }
impl Funding for FullFeaturedExchange { /* ... */ }
// Automatically implements FullExchange via blanket implTraits§
- Account
- Trait for account-related operations.
- Full
Exchange - Combined trait for exchanges supporting all capabilities.
- Funding
- Trait for deposit and withdrawal operations.
- Margin
- Trait for margin and futures trading operations.
- Market
Data - Trait for fetching public market data.
- Public
Exchange - Base trait for all exchange implementations.
- Trading
- Trait for order management operations.
Type Aliases§
- ArcAccount
- Type alias for Arc-wrapped Account trait object.
- ArcFull
Exchange - Type alias for Arc-wrapped FullExchange trait object.
- ArcFunding
- Type alias for Arc-wrapped Funding trait object.
- ArcMargin
- Type alias for Arc-wrapped Margin trait object.
- ArcMarket
Data - Type alias for Arc-wrapped MarketData trait object.
- ArcPublic
Exchange - Type alias for Arc-wrapped PublicExchange trait object.
- ArcTrading
- Type alias for Arc-wrapped Trading trait object.
- Boxed
Account - Type alias for boxed Account trait object.
- Boxed
Full Exchange - Type alias for boxed FullExchange trait object.
- Boxed
Funding - Type alias for boxed Funding trait object.
- Boxed
Margin - Type alias for boxed Margin trait object.
- Boxed
Market Data - Type alias for boxed MarketData trait object.
- Boxed
Public Exchange - Type alias for boxed PublicExchange trait object.
- Boxed
Trading - Type alias for boxed Trading trait object.