Expand description
§CCXT Rust
CCXT Rust is a professional-grade trading toolkit that brings the CCXT unified exchange interface to native Rust projects. It wraps REST and WebSocket APIs for major cryptocurrency exchanges under a single, strongly typed abstraction.
§Features
- Async first: Powered by
tokiowith ergonomic async/await APIs for every call - Unified types: Shared
Exchangetrait and strongly typed market/order models - Performance oriented: Zero-cost abstractions with
rust_decimalfor precise math - Live data: WebSocket clients with automatic reconnection and streamed order books
- Extensible: Builder patterns and configuration hooks for custom environments
§Installation
[dependencies]
ccxt-rust = { version = "0.1", features = ["full"] }Alternatively depend on the workspace members directly when developing inside the repo.
§Quick Start
use ccxt_exchanges::binance::Binance;
use ccxt_rust::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// Prefer testnet when experimenting to avoid hitting live balances.
let exchange = Binance::builder()
.sandbox(true)
.build()?;
if exchange.capabilities().fetch_ticker() {
let ticker = exchange.fetch_ticker("BTC/USDT", ()).await?;
println!("Last price: {:?}", ticker.last);
}
Ok(())
}§Further Reading
See the repository README and the examples/ folder for advanced scenarios
covering authenticated calls, streaming data, and multi-exchange orchestration.
Modules§
- account
- Account configuration type definitions.
- balance
- Balance type definitions
- bid_ask
- Bid-ask (best bid and ask prices) type definitions.
- currency
- Currency type definitions
- default_
type - Default type configuration for exchange operations Default Type Definitions for Exchange Configuration
- endpoint
- Endpoint type for public/private API distinction Endpoint type definitions for exchange API routing
- fee
- Fee-related type definitions
- financial
- Financial types with enhanced type safety (Price, Amount, Cost) Financial calculation type definitions.
- funding_
rate - Funding rate type definitions
- ledger
- Ledger entry types and related structures Ledger entry type definitions.
- margin
- Margin trading related types
- mark_
price - Mark price type definitions.
- market
- Market type definitions
- market_
data - Futures market data type definitions.
- ohlcv
- OHLCV (candlestick) data type definitions.
- ohlcv_
request - OHLCV request types with Builder pattern OHLCV request types with Builder pattern.
- order
- Order type definitions
- order_
request - Order request types with Builder pattern using typestate Order request types with Builder pattern using typestate.
- orderbook
- Orderbook type definitions
- params
- Parameter types for trait methods with builder pattern support Parameter types for trait methods with builder pattern support.
- position
- Position type definitions for futures trading.
- prelude
- Prelude module for convenient imports
- risk
- Risk management and position risk types Risk management type definitions.
- symbol
- Symbol types for unified symbol format Symbol Type Definitions for Unified Symbol Format
- ticker
- Ticker type definitions
- ticker_
params - Strongly typed parameter builder for ticker requests.
- trade
- Trade type definitions
- transaction
- Transaction types for deposits and withdrawals
- transfer
- Transfer-related type definitions.
Structs§
- Account
Config - Account configuration information.
- AggTrade
- Aggregated trade data structure.
- Amount
- Amount type (zero-cost wrapper).
- Backoff
Config - Exponential backoff configuration for reconnection.
- Backoff
Strategy - Calculates retry delay with exponential backoff and jitter.
- Balance
- Balance structure containing all currency balances
- Balance
Entry - Balance entry for a single currency
- Balance
Params - Parameters for fetching account balance.
- Base
Exchange - Base exchange implementation
- Batch
Cancel Result - Batch cancel order result.
- Batch
Order Request - Batch order request payload used by
create_orders. - Batch
Order Result - Batch order result.
- Batch
Order Update - Batch order update request payload used by
edit_orders. - BidAsk
- Best bid and ask prices data structure.
- Binance
- Binance exchange structure.
- Binance
Builder - Builder for creating Binance exchange instances.
- Bitget
- Bitget exchange structure.
- Bitget
Builder - Builder for creating Bitget exchange instances.
- Borrow
Interest - Borrow interest record
- Borrow
Rate - Borrow rate information for margin trading
- Borrow
Rate History - Borrow rate history record
- Bybit
- Bybit exchange structure.
- Bybit
Builder - Builder for creating Bybit exchange instances.
- Cancel
AllOrders Result - Cancel-all orders result payload.
- Cancel
Replace Response - Cancel and replace order response.
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
- Commission
Rate - Commission rate information.
- Cost
- Cost type (zero-cost wrapper).
- Currency
- Currency structure representing a tradable asset
- Currency
Network - Currency network/chain information
- Decimal
Decimalrepresents a 128 bit representation of a fixed-precision decimal number. The finite set of values of typeDecimalare of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.- Deposit
Address - Deposit address information for receiving funds.
- Deposit
Withdraw Fee - Deposit and withdrawal fee information.
- Exchange
Capabilities - Exchange capabilities configuration
- Exchange
Config - Exchange configuration
- Exchange
Config Builder - Builder for
ExchangeConfig - Expiry
Date - Represents a futures contract expiry date in YYMMDD format
- Fee
- Fee information
- FeeFunding
Rate - Funding rate structure.
- FeeFunding
Rate History - Funding rate history structure.
- FeeTrading
Fee - Trading fee structure.
- Funding
Fee - Personal funding fee record.
- Funding
History - Funding fee history record.
- Funding
Rate - Funding rate information.
- Funding
Rate History - Funding rate history record.
- Http
Client - HTTP client with retry and rate limiting support
- Http
Config - HTTP request configuration
- Hyper
Liquid - HyperLiquid exchange structure.
- Hyper
Liquid Builder - Builder for creating HyperLiquid exchange instances.
- Index
Price - Index price information.
- Isolated
Borrow Rate - Isolated borrow rate information for margin trading
- Last
Price - Latest price information.
- Ledger
Entry - Ledger entry structure.
- Leverage
- Leverage configuration for a trading symbol.
- Leverage
Params - Parameters for setting leverage.
- Leverage
Tier - Leverage tier structure.
- Liquidation
- Liquidation order information.
- LogConfig
- Log configuration.
- Margin
Adjustment - Margin adjustment record (transfers between spot and margin accounts)
- Margin
Loan - Margin loan record
- Margin
Repay - Margin repayment record
- Mark
Price - Mark price data structure.
- Market
- Market structure representing a trading pair
- Market
BidAsk - Best bid/ask price information (book ticker).
- Market
Cache - Market data cache structure
- Market
Limits - Market limits for order parameters
- Market
Precision - Market precision settings
- MaxBorrowable
- Maximum borrowable amount information.
- MaxLeverage
- Maximum available leverage information.
- MaxTransferable
- Maximum transferable amount information.
- MinMax
- Min/Max range for limits
- Multi
Tier Rate Limiter - Multi-tier rate limiter for exchanges with multiple rate limit tiers
- Network
Info - Blockchain network information.
- Next
Funding Rate - Next funding rate information.
- OHLCV
- OHLCV data structure (candlestick data).
- OcoOrder
- OCO (One-Cancels-the-Other) order.
- OcoOrder
Info - OCO order info for a single order.
- Ohlcv
- OHLCV (Open, High, Low, Close, Volume) candlestick data
- Ohlcv
Params - Parameters for fetching OHLCV (candlestick) data.
- Ohlcv
Request - OHLCV request configuration built via builder pattern.
- Ohlcv
Request Builder - Builder for OhlcvRequest with validation.
- Okx
- OKX exchange structure.
- OkxBuilder
- Builder for creating OKX exchange instances.
- Open
Interest - Open interest data representing the total number of outstanding derivative contracts.
- Open
Interest History - Historical open interest data.
- Order
- Order structure
- Order
Book - Complete order book structure
- Order
Book Delta - Orderbook delta update message
- Order
Book Entry - Order book entry (price level)
- Order
Book Params - Parameters for fetching order book data.
- Order
Params - Parameters for creating orders.
- Order
Report - OCO order report with detailed status.
- Order
Request - Order request configuration built via builder pattern.
- Order
Request Builder - Builder for OrderRequest with typestate pattern for required fields.
- Parsed
Symbol - Represents a parsed unified symbol with all components
- Position
- Trading position information.
- Premium
Index - Premium index information.
- Price
- Price type (zero-cost wrapper).
- Rate
Limiter - Rate limiter using token bucket algorithm
- Rate
Limiter Config - Rate limiter configuration
- Retry
Config - Retry configuration.
- Retry
Strategy - Retry strategy.
- Server
Time - Server time information.
- Stats24hr
- 24-hour statistics data.
- Subscription
- WebSocket subscription metadata.
- Subscription
Manager - Subscription manager with capacity limits.
- Symbol
Formatter - Symbol formatter for converting ParsedSymbol to unified symbol strings
- Symbol
Parser - Symbol parser for unified symbol strings
- Ticker
- Ticker data structure
- Ticker
Params - Strongly typed parameters accepted by ticker endpoints.
- Ticker
Params Builder - Convenience builder for
TickerParams. - Trade
- Trade data structure
- Trading
Fee - Trading fee information.
- Trading
Limits - Trading limits for a market
- Transaction
- Transaction record for deposits and withdrawals.
- Transaction
Fee - Transaction fee information.
- Transfer
- Transfer record between accounts.
- Transfer
Params - Parameters for transferring funds between accounts.
- Withdraw
Params - Parameters for withdrawing funds.
- WsClient
- Async WebSocket client for exchange streaming APIs.
- WsConfig
- WebSocket connection configuration.
- WsError
- Extended WebSocket error with classification.
- WsStats
- WebSocket connection statistics (lock-free).
- WsStats
Snapshot - Immutable snapshot of WebSocket connection statistics.
Enums§
- Account
Type - Account type for balance queries and transfers.
- Contract
Type - Contract settlement type for derivatives
- Counting
Mode - Precision counting mode.
- Default
SubType - Contract settlement type for derivatives
- Default
Type - Default market type for exchange operations
- Default
Type Error - Error type for DefaultType parsing
- Digest
Format - Output encoding format for cryptographic digests.
- Endpoint
Type - Endpoint type enum for distinguishing between public and private API endpoints.
- Error
- The primary error type for the
ccxt-rustlibrary. - Hash
Algorithm - Supported cryptographic hash algorithms.
- Ledger
Direction - Ledger entry direction.
- Ledger
Entry Type - Ledger entry type (CCXT standardized types).
- LogFormat
- Log format.
- LogLevel
- Log level.
- Margin
Type - Margin type for futures positions.
- Market
Type - Market type enumeration
- Order
Side - Order side (buy or sell)
- Order
Status - Order status
- Order
Type - Order type
- Padding
Mode - Output padding mode.
- Position
Side - Position side for dual-side position mode.
- Precision
Mode - Precision mode for currency operations
- Price
Type - Price type for OHLCV data (futures-specific).
- Retry
Strategy Type - Retry strategy type.
- Rounding
Mode - Rounding mode for precision calculations.
- Symbol
Error - Symbol-related errors
- Symbol
Market Type - Market type derived from symbol structure
- Taker
OrMaker - Whether a trade is maker or taker
- Time
InForce - Time in force - order validity duration
- Timeframe
- Timeframe enum for OHLCV data
- Transaction
Status - Transaction processing status.
- Transaction
Type - Transaction type for deposits and withdrawals.
- Transfer
Type - Transfer type for inter-account transfers.
- WsConnection
State - WebSocket connection state.
- WsError
Kind - WebSocket error classification.
- WsEvent
- WebSocket connection event types.
- WsMessage
- WebSocket message types for exchange communication.
Constants§
- DEFAULT_
MAX_ SUBSCRIPTIONS - Default maximum number of subscriptions.
- DEFAULT_
SHUTDOWN_ TIMEOUT - Default shutdown timeout in milliseconds.
- VERSION
- Library version
Traits§
- Context
Ext - Extension trait for ergonomic error context attachment.
- Deserialize
- A data structure that can be deserialized from any data format supported by Serde.
- Error
Context Deprecated - Helper trait for adding context to errors (legacy alias for ContextExt).
- Exchange
- Core Exchange trait - the unified interface for all exchanges
- Exchange
Ext - Extension trait providing access to modular sub-traits from Exchange.
- Full
Exchange - Combined trait for exchanges that support both REST and WebSocket
- Into
Ticker Params - Trait for values convertible into
TickerParams. - Serialize
- A data structure that can be serialized into any data format supported by Serde.
- WsExchange
- WebSocket exchange trait for real-time data streaming
Functions§
- base64_
to_ base64url - Converts standard Base64 to Base64 URL format.
- base64url_
decode - Decodes a Base64 URL-encoded string.
- decimal_
to_ precision - Formats a decimal to a specific precision with configurable rounding and counting modes.
- eddsa_
sign - Generates an EdDSA signature using Ed25519.
- hash
- Computes a cryptographic hash (one-way, keyless).
- hmac_
sign - Generates an HMAC signature for a message.
- init_
logging - Initializes the logging system.
- iso8601
- Converts a timestamp in milliseconds to an ISO 8601 formatted string
- jwt_
sign - Generates a JWT (JSON Web Token).
- microseconds
- Returns the current time in microseconds since the Unix epoch
- milliseconds
- Returns the current time in milliseconds since the Unix epoch
- number_
to_ string - Converts a decimal number to string, handling scientific notation.
- parse_
date - Parses a date string and returns the timestamp in milliseconds since Unix epoch
- parse_
iso8601 - Parses an ISO 8601 date string and returns the timestamp in milliseconds
- precision_
from_ string - Extracts precision (number of decimal places) from a string representation.
- resolve_
market_ type - Resolves the effective market type for an API call
- seconds
- Returns the current time in seconds since the Unix epoch
- try_
init_ logging - Attempts to initialize the logging system, ignoring duplicate initialization errors.
- ymd
- Alias for
yyyymmddfunction - ymdhms
- Formats a timestamp as “yyyy-MM-dd HH:mm:ss”
- yymmdd
- Formats a timestamp as “yy-MM-dd”
- yyyymmdd
- Formats a timestamp as “yyyy-MM-dd”
Type Aliases§
- ArcExchange
- Type alias for an Arc-wrapped Exchange trait object
- Boxed
Exchange - Type alias for a boxed Exchange trait object
- Margin
Mode - Margin mode for futures trading.
- Message
Stream - WebSocket message stream type
- Order
Book Side - Order book side (bids or asks)
- Result
- Result type alias for all CCXT operations.
- Symbol
- Type alias for trading symbols (e.g., “BTC/USDT”)
- Timestamp
- Type alias for timestamps (milliseconds since Unix epoch)