ccxt-rust 0.1.4

Cryptocurrency exchange trading library in Rust
Documentation

CCXT-Rust


Rust License Rust CI Documentation

A professional-grade, type-safe Rust implementation of the CCXT library for cryptocurrency trading, providing unified access to major exchanges.

English | įŽ€äŊ“中文

đŸŽ¯ Supported Exchanges

Exchange Market Data Trading WebSocket
Binance ✅ ✅ ✅
Bitget ✅ ✅ ✅
Hyperliquid ✅ ✅ ✅
OKX ✅ ✅ ✅
Bybit ✅ ✅ ✅

Legend: ✅ Supported, 🚧 In Progress

🌟 Key Features

  • đŸ›Ąī¸ Type-Safe & Async: Built on Tokio and rust_decimal for safe, high-performance financial operations.
  • 🔄 Unified Interface: Consistent Exchange trait across all supported exchanges.
  • ⚡ Real-Time: Robust WebSocket support with automatic reconnection.
  • đŸ“Ļ Comprehensive Capability:
    • Market Data: Tickers, Order Books, OHLCV, Trades.
    • Trading: Spot, Margin, Futures, Batched Orders, OCO.
    • Account: Balances, Transactions, Leverage management.

🚀 Quick Start

Installation

cargo add ccxt-rust

Basic Usage

use ccxt_exchanges::binance::Binance;
use ccxt_core::exchange::Exchange;
use rust_decimal_macros::dec;
use ccxt_core::types::{OrderType, OrderSide};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  // 1. Initialize (using env vars recommended)
    let exchange = Binance::builder()
            .api_key(std::env::var("BINANCE_API_KEY").ok())
            .secret(std::env::var("BINANCE_SECRET").ok())
        .build()?;

  // 2. Fetch Market Data
    let ticker = exchange.fetch_ticker("BTC/USDT").await?;
    println!("BTC/USDT Price: {:?}", ticker.last);

  // 3. Place Order (if credentials provided)
  if exchange.has_private_api() {
    let order = exchange.create_order(
      "BTC/USDT",
      OrderType::Limit,
      OrderSide::Buy,
      dec!(0.001),
      Some(dec!(50000)),
    ).await?;
    println!("Order placed: {}", order.id);
    }

    Ok(())
}

For WebSocket examples and advanced usage (polymorphism), see the examples/ directory.

đŸ—ī¸ Architecture

The project is structured as a workspace:

  • ccxt-core: Defines the unified Exchange and WsExchange traits, standard types, and error handling logic.
  • ccxt-exchanges: Contains specific implementations (Binance, OKX, etc.).

🚩 Feature Flags

Flag Description Default
rest REST API support ✅
websocket WebSocket support ✅
rustls-tls Use RustLS (recommended) ✅
native-tls Use OpenSSL/Native TLS ❌

đŸ› ī¸ Development

# Run tests
cargo test

# Check code quality
cargo clippy --all-targets -- -D warnings

# Build documentation
cargo doc --open

📝 License & Support

MIT License. See LICENSE.

âš ī¸ Disclaimer

This project is for educational and research purposes only. The authors and contributors are not responsible for any financial losses or damages arising from the use of this software. Cryptocurrency trading involves high risk; please trade responsibly.


Status: 🚧 Active Development (v0.1.4) | Donations (BSC): 0x8e5d858f92938b028065d39450421d0e080d15f7