Trading

Trait Trading 

Source
pub trait Trading: PublicExchange {
    // Required methods
    fn create_order<'life0, 'async_trait>(
        &'life0 self,
        params: OrderParams,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn cancel_order<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
        symbol: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn cancel_all_orders<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn fetch_order<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
        symbol: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn fetch_open_orders<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: Option<&'life1 str>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: '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>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn market_buy<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
        amount: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn market_sell<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
        amount: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn limit_buy<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
        amount: Decimal,
        price: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn limit_sell<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
        amount: Decimal,
        price: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn fetch_closed_orders_u64<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: Option<&'life1 str>,
        since: Option<u64>,
        limit: Option<u32>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Order>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Trait for order management operations.

This trait provides methods for creating, canceling, and fetching orders. All methods require authentication and are async.

§Supertrait

Requires PublicExchange as a supertrait to access exchange metadata and capabilities.

§Thread Safety

This trait requires Send + Sync bounds (inherited from PublicExchange) to ensure safe usage across thread boundaries in async contexts.

Required Methods§

Source

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

Create a new order using OrderParams builder.

This is the primary method for creating orders. Use the OrderParams builder for ergonomic order construction.

§Arguments
  • params - Order parameters including symbol, side, type, amount, price
§Example
use ccxt_core::types::params::OrderParams;
use rust_decimal_macros::dec;

// Market buy
let order = exchange.create_order(
    OrderParams::market_buy("BTC/USDT", dec!(0.01))
).await?;

// Limit sell with custom options
let order = exchange.create_order(
    OrderParams::limit_sell("BTC/USDT", dec!(0.01), dec!(50000))
        .time_in_force(TimeInForce::IOC)
        .client_id("my-order-123")
).await?;
Source

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

Cancel an existing order.

§Arguments
  • id - Order ID to cancel
  • symbol - Trading pair symbol (required for most exchanges)
§Example
let cancelled = exchange.cancel_order("12345", "BTC/USDT").await?;
println!("Cancelled order: {}", cancelled.id);
Source

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

Cancel all orders for a symbol.

§Arguments
  • symbol - Trading pair symbol
§Returns

Returns a vector of cancelled orders.

Source

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

Fetch a specific order by ID.

§Arguments
  • id - Order ID
  • symbol - Trading pair symbol (required for most exchanges)
§Example
let order = exchange.fetch_order("12345", "BTC/USDT").await?;
println!("Order status: {:?}", order.status);
Source

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

Fetch open orders.

§Arguments
  • symbol - Optional trading pair symbol. If None, returns all open orders.
§Example
// All open orders
let orders = exchange.fetch_open_orders(None).await?;

// Open orders for specific symbol
let orders = exchange.fetch_open_orders(Some("BTC/USDT")).await?;
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>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch closed orders with pagination.

§Arguments
  • symbol - Optional trading pair symbol
  • since - Optional start timestamp in milliseconds (i64) since Unix epoch
  • limit - Optional maximum number of orders to return
§Timestamp Format

The since parameter uses i64 milliseconds since Unix epoch:

  • 1609459200000 = January 1, 2021, 00:00:00 UTC
  • chrono::Utc::now().timestamp_millis() = Current time
  • chrono::Utc::now().timestamp_millis() - 86400000 = 24 hours ago
§Example
// Recent closed orders
let orders = exchange.fetch_closed_orders(Some("BTC/USDT"), None, Some(100)).await?;

// Closed orders since timestamp
let orders = exchange.fetch_closed_orders(
    Some("BTC/USDT"),
    Some(1609459200000i64),
    Some(50)
).await?;

Provided Methods§

Source

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

Convenience method for market buy order.

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

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

Convenience method for market sell order.

§Arguments
  • symbol - Trading pair symbol
  • amount - Order amount
Source

fn limit_buy<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, amount: Decimal, price: Decimal, ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Convenience method for limit buy order.

§Arguments
  • symbol - Trading pair symbol
  • amount - Order amount
  • price - Limit price
Source

fn limit_sell<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, amount: Decimal, price: Decimal, ) -> Pin<Box<dyn Future<Output = Result<Order>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Convenience method for limit sell order.

§Arguments
  • symbol - Trading pair symbol
  • amount - Order amount
  • price - Limit price
Source

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

👎Deprecated since 0.1.0: Use fetch_closed_orders with i64 timestamps. Convert using TimestampUtils::u64_to_i64()

Fetch closed orders with u64 timestamp filtering (deprecated).

DEPRECATED: Use fetch_closed_orders with i64 timestamps instead. This method is provided for backward compatibility during migration.

§Migration
// Old code (deprecated)
let orders = exchange.fetch_closed_orders_u64(Some("BTC/USDT"), Some(1609459200000u64), Some(100)).await?;

// New code (recommended)
let orders = exchange.fetch_closed_orders(Some("BTC/USDT"), Some(1609459200000i64), Some(100)).await?;

Implementors§