Account

Trait Account 

Source
pub trait Account: PublicExchange {
    // Required methods
    fn fetch_balance_with_params<'life0, 'async_trait>(
        &'life0 self,
        params: BalanceParams,
    ) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn fetch_my_trades_since<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
        since: Option<i64>,
        limit: Option<u32>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn fetch_balance<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
    fn get_balance<'life0, 'life1, 'async_trait>(
        &'life0 self,
        currency: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<BalanceEntry>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn fetch_my_trades<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn fetch_my_trades_since_u64<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 str,
        since: Option<u64>,
        limit: Option<u32>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Trade>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Trait for account-related operations.

This trait provides methods for fetching account balances and trade history. All methods require authentication and are async.

§Timestamp Format

All timestamp parameters and fields in returned data structures use:

  • Type: i64
  • Unit: Milliseconds since Unix epoch (January 1, 1970, 00:00:00 UTC)
  • Example: 1609459200000 represents January 1, 2021, 00:00:00 UTC

§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 fetch_balance_with_params<'life0, 'async_trait>( &'life0 self, params: BalanceParams, ) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch balance with parameters.

Allows specifying account type and currency filters.

§Arguments
  • params - Balance parameters including account type and currency filters
§Example
use ccxt_core::types::params::BalanceParams;

// Futures balance
let balance = exchange.fetch_balance_with_params(BalanceParams::futures()).await?;

// Specific currencies only
let balance = exchange.fetch_balance_with_params(
    BalanceParams::spot().currencies(&["BTC", "USDT"])
).await?;
Source

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

Fetch trades with pagination.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTC/USDT”)
  • since - Optional start timestamp in milliseconds (i64) since Unix epoch
  • limit - Optional maximum number of trades 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 trades (no timestamp filter)
let trades = exchange.fetch_my_trades_since("BTC/USDT", None, Some(100)).await?;

// Trades from the last 24 hours
let since = chrono::Utc::now().timestamp_millis() - 86400000;
let trades = exchange.fetch_my_trades_since(
    "BTC/USDT",
    Some(since),
    Some(50)
).await?;

Provided Methods§

Source

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

Fetch account balance (default: spot account).

Returns the current balance for all currencies in the account.

§Example
let balance = exchange.fetch_balance().await?;
for (currency, entry) in &balance.currencies {
    println!("{}: free={}, used={}", currency, entry.free, entry.used);
}
Source

fn get_balance<'life0, 'life1, 'async_trait>( &'life0 self, currency: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<BalanceEntry>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get balance for a specific currency.

Convenience method that fetches the full balance and extracts the entry for the specified currency.

§Arguments
  • currency - Currency code (e.g., “BTC”, “USDT”)
§Returns

Returns the balance entry for the currency, or an error if not found.

§Example
let btc = exchange.get_balance("BTC").await?;
println!("BTC: free={}, used={}, total={}", btc.free, btc.used, btc.total);
Source

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

Fetch user’s trade history for a symbol.

Returns the user’s executed trades for the specified symbol.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTC/USDT”)
§Example
let trades = exchange.fetch_my_trades("BTC/USDT").await?;
for trade in trades {
    println!("{}: {} {} @ {}", trade.id, trade.side, trade.amount, trade.price);
}
Source

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

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

Fetch user’s trade history with u64 timestamp filtering (deprecated).

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

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

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

Implementors§