Skip to main content

Module traits

Module traits 

Source
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 impl

Traits§

Account
Trait for account-related operations.
FullExchange
Combined trait for exchanges supporting all capabilities.
Funding
Trait for deposit and withdrawal operations.
Margin
Trait for margin and futures trading operations.
MarketData
Trait for fetching public market data.
PublicExchange
Base trait for all exchange implementations.
Trading
Trait for order management operations.

Type Aliases§

ArcAccount
Type alias for Arc-wrapped Account trait object.
ArcFullExchange
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.
ArcMarketData
Type alias for Arc-wrapped MarketData trait object.
ArcPublicExchange
Type alias for Arc-wrapped PublicExchange trait object.
ArcTrading
Type alias for Arc-wrapped Trading trait object.
BoxedAccount
Type alias for boxed Account trait object.
BoxedFullExchange
Type alias for boxed FullExchange trait object.
BoxedFunding
Type alias for boxed Funding trait object.
BoxedMargin
Type alias for boxed Margin trait object.
BoxedMarketData
Type alias for boxed MarketData trait object.
BoxedPublicExchange
Type alias for boxed PublicExchange trait object.
BoxedTrading
Type alias for boxed Trading trait object.