CCXT-Rust
A professional-grade Rust implementation of the CCXT (CryptoCurrency eXchange Trading) library, providing unified, type-safe access to Major cryptocurrency exchanges with high-performance async operations.
๐ฏ Supported Exchanges
| Exchange | Public API (Market Data) | Private API (Trading) | WebSocket |
|---|---|---|---|
| Binance | โ | โ | โ |
| Bitget | โ | โ | โ |
| Hyperliquid | โ | โ | โ |
| OKX | โ | โ | โ |
| Bybit | โ | โ | โ |
Legend: โ Supported, ๐ง In Progress, ๐ Planned
๐ Features
Core Capabilities
- โ Type-Safe Trading Operations - Leverage Rust's strong type system for compile-time safety
- โ Async/Await Architecture - Built on Tokio for efficient, non-blocking I/O operations
- โ
Precise Financial Calculations - Using
rust_decimalfor accurate monetary computations - โ Comprehensive Error Handling - Structured error types with full context propagation
- โ REST API Support - Complete REST API implementation for exchange operations
- โ WebSocket Real-Time Data - Live market data streaming with automatic reconnection
- โ Multi-Exchange Support - Unified interface across multiple cryptocurrency exchanges
Advanced Features
-
Market Data Operations
- Fetch tickers, order books, and OHLCV data
- Real-time market data streaming via WebSocket
- Advanced market data with depth and aggregation
-
Order Management
- Create, cancel, and modify orders
- Support for market, limit, and conditional orders
- OCO (One-Cancels-Other) order support
- Batch order operations
-
Account Management
- Balance inquiries and account information
- Deposit and withdrawal operations
- Transaction history and ledger access
- Fee management and calculation
-
Trading Features
- Spot trading
- Margin trading (cross and isolated)
- Futures trading with position management
- Leverage and margin management
-
WebSocket Features
- Real-time order book updates
- Live trade streaming
- Account balance updates
- Order status updates
- Position updates for futures
๐๏ธ Architecture
The project follows a clean, modular workspace architecture with a unified Exchange trait:
ccxt-rust/
โโโ ccxt-core/ # Core types, traits, and error handling
โ โโโ types/ # Market, Order, Trade, Ticker, etc.
โ โโโ exchange.rs # Unified Exchange trait
โ โโโ ws_exchange.rs # WebSocket Exchange trait
โ โโโ error.rs # Comprehensive error types
โ โโโ base_exchange.rs # Base exchange functionality
โโโ ccxt-exchanges/ # Exchange-specific implementations
โ โโโ binance/ # Binance exchange implementation
โ โโโ mod.rs # Main Binance struct
โ โโโ builder.rs # BinanceBuilder
โ โโโ exchange_impl.rs # Exchange trait implementation
โ โโโ ws_exchange_impl.rs # WsExchange trait implementation
โ โโโ rest/ # REST API client modules
โ โโโ ws.rs # WebSocket client
โ โโโ parser.rs # Response parsing
โ โโโ auth.rs # Authentication
โโโ examples/ # Comprehensive usage examples
โโโ tests/ # Integration tests
โโโ docs/ # Detailed documentation
Unified Exchange Trait
The Exchange trait in ccxt-core provides a unified interface for all exchanges:
use ;
// Use any exchange through the unified interface
async
// Use multiple exchanges polymorphically
async
WebSocket Streaming
The WsExchange trait provides real-time data streaming:
use ;
use StreamExt;
async
๐ Quick Start
Prerequisites
- Rust 1.91+ or later
- Cargo (latest stable)
Installation
Add via command line:
Or add to your Cargo.toml:
[]
= { = "ccxt-core" }
= { = "ccxt-exchanges" }
= { = "1.35", = ["full"] }
= "1.39"
= "0.3"
Basic Usage with Builder Pattern
use Binance;
use Exchange;
async
Using Exchanges Polymorphically
use ;
use Arc;
async
WebSocket Streaming
use Binance;
use WsExchange;
use StreamExt;
async
๐ Examples
The project includes comprehensive examples covering all major features:
basic_usage.rs- Getting started with the librarybinance_market_data_example.rs- Market data operationsbinance_order_management_example.rs- Order creation and managementbinance_account_example.rs- Account operationsbinance_margin_example.rs- Margin tradingbinance_futures_example.rs- Futures tradingbinance_ws_example.rs- WebSocket streamingbinance_conditional_orders_example.rs- Conditional ordersbinance_deposit_withdrawal_example.rs- Deposit/withdrawal operations
Run any example:
๐ฉ Feature Flags
Optimize your build by selecting only the features you need in Cargo.toml:
default: Enablesrest,websocket, andrustls-tls.rest: Enables REST API support.websocket: Enables WebSocket support.rustls-tls: Usesrustlsfor TLS (default, recommended).native-tls: Uses platform-native TLS (OpenSSL/Schannel/Secure Transport).compression: Enables GZIP compression for HTTP requests.full: Enables all features.
๐ง Configuration
Environment Variables
Create a .env file from the template:
Key configuration options:
# API Credentials
BINANCE_API_KEY=your_api_key_here
BINANCE_API_SECRET=your_secret_here
# Testing
ENABLE_PRIVATE_TESTS=false
ENABLE_INTEGRATION_TESTS=false
USE_MOCK_DATA=true
TEST_SYMBOL=BTC/USDT
# Logging
RUST_LOG=info
๐งช Testing
# Run all tests
# Run tests with output
# Run specific test suite
# Run integration tests
# Run with live API (requires credentials)
ENABLE_INTEGRATION_TESTS=true
๐ Documentation
- API Documentation - Detailed API reference
- Testing Guide - Comprehensive testing documentation
- Implementation Plans - Feature implementation roadmaps
- Comparison Analysis - Go vs Rust implementation
Generate local documentation:
๐ ๏ธ Development
Building
# Debug build
# Release build (optimized)
# Build specific package
Code Quality
# Format code
# Run linter
# Strict linting (no warnings)
# Check compilation
๐ Security
- Never commit API keys or secrets - Always use environment variables
- Secure credential storage - Use system keychains or encrypted vaults
- Rate limiting - Built-in rate limiting to prevent API bans
- Input validation - All inputs are validated before API calls
- HTTPS only - All communications use TLS encryption
๐ค Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow Rust best practices and project conventions
- Add tests for new features
- Ensure all tests pass (
cargo test) - Run formatting and linting (
cargo fmt && cargo clippy) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Conventions
- Code Style: Rust 2024 edition, 100-character line width
- Testing: Minimum 80% test coverage
- Documentation: All public APIs must have documentation
- Error Handling: Use
thiserrorfor custom errors,anyhowfor context
๐ Performance
Built for high performance:
- Async I/O: Non-blocking operations using Tokio
- Zero-copy parsing: Efficient JSON deserialization
- Connection pooling: Reused HTTP connections
- Optimized builds: LTO and single codegen unit for releases
- Benchmarks: Criterion-based performance benchmarks
๐ Troubleshooting
Common Issues
-
Compilation errors
- Ensure Rust 1.91+ is installed:
rustc --version - Update dependencies:
cargo update - Clean build:
cargo clean && cargo build
- Ensure Rust 1.91+ is installed:
-
API authentication failures
- Verify API keys in
.envfile - Check API key permissions on exchange
- Ensure system clock is synchronized
- Verify API keys in
-
Rate limiting
- Reduce request frequency
- Use WebSocket for real-time data
- Check exchange-specific rate limits
For more help, see documentation or open an issue.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by the original CCXT library
- Built with amazing Rust ecosystem libraries
- Community contributors and testers
๐ Contact & Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Project Docs
Status: ๐ง Active Development | Version: 0.1.1 | Updated: 2025-12
โ ๏ธ Note: This library is under active development. APIs may change before v1.0. Not recommended for production use yet.