Skip to content

Repository files navigation

CCXT-Rust

A Rust port of the popular CCXT cryptocurrency exchange trading library.

CICrates.ioDocumentationLicense: MIT

Features

  • 100+ Exchanges - CEX (Binance, Bybit, OKX, ...) and DEX (Hyperliquid, dYdX, Paradex, ...)
  • Unified API - Consistent interface across all exchanges
  • REST & WebSocket - Full support for both protocols
  • Async/Await - Built on Tokio for high-performance operations
  • Type Safety - Strongly typed with Rust's type system

Supported Exchanges

TypeExchanges
CEXBinance, Bybit, OKX, Kraken, KuCoin, Coinbase, Gate.io, Bitget, MEXC, HTX, Upbit, Bithumb, +90 more
DEXHyperliquid, dYdX v4, Paradex, Apex, Defx, Derive, WavesExchange

See docs/exchanges.md for the full list.

Installation

[dependencies]
ccxt-rust = "0.1"tokio = { version = "1.0", features = ["full"] }

Feature Flags

FeatureDefaultDescription
cexCentralized exchange support (Binance, OKX, etc.)
dexDecentralized exchange support (Hyperliquid, dYdX, Paradex) + crypto primitives
nativeNative Rust build with tokio runtime
wasmWebAssembly build for browser environments
fullAll features enabled (native)

Examples

# CEX only (default, smaller binary)ccxt-rust = "0.1"# DEX support (includes EVM, StarkNet, Cosmos crypto)ccxt-rust = { version = "0.1", features = ["dex"] }
# All featuresccxt-rust = { version = "0.1", features = ["full"] }
# DEX only (no CEX)ccxt-rust = { version = "0.1", default-features = false, features = ["dex"] }

WebAssembly (Browser) Support

ccxt-rust can be compiled to WebAssembly for use in browsers.

Build WASM Package

# Install wasm-pack
cargo install wasm-pack
# Build for web
wasm-pack build --target web --no-default-features --features "wasm,cex"

Browser Usage

<scripttype="module">importinit,{WasmBinance,WasmUpbit,version}from'./pkg/ccxt_rust.js';asyncfunctionmain(){awaitinit();console.log('ccxt-rust version:',version());// Create exchange instanceconstbinance=newWasmBinance();// Fetch tickerconstticker=awaitbinance.fetchTicker('BTC/USDT');console.log('BTC/USDT:',ticker.last);// Fetch order bookconstorderbook=awaitbinance.fetchOrderBook('BTC/USDT',10);console.log('Bids:',orderbook.getBids());console.log('Asks:',orderbook.getAsks());}main();</script>

Available WASM Exchanges

ExchangeREST ClassWebSocket ClassREST MethodsWS Methods
BinanceWasmBinanceWasmBinanceWsfetchTicker, fetchOrderBook, fetchMarkets, fetchTickers, fetchTrades, fetchOhlcvwatchTicker, watchOrderBook, watchTrades
UpbitWasmUpbitWasmUpbitWsfetchTicker, fetchOrderBook, fetchMarkets, fetchTickers, fetchTrades, fetchOhlcvwatchTicker, watchOrderBook
BybitWasmBybitWasmBybitWsfetchTicker, fetchOrderBook, fetchMarkets, fetchTickers, fetchTrades, fetchOhlcvwatchTicker, watchOrderBook
OKXWasmOkx-fetchTicker, fetchOrderBook, fetchMarkets, fetchTickers, fetchTrades, fetchOhlcv-
KrakenWasmKraken-fetchTicker, fetchOrderBook, fetchMarkets, fetchTickers, fetchTrades, fetchOhlcv-

WASM WebSocket Example

import{WasmBinanceWs}from'./pkg/ccxt_rust.js';// Create WebSocket clientconstws=newWasmBinanceWs();// Watch ticker with callbackws.watchTicker('BTC/USDT',(msg)=>{if(msg.message_type==='ticker'){constdata=JSON.parse(msg.data);console.log('BTC/USDT:',data.c);// Last price}elseif(msg.message_type==='connected'){console.log('WebSocket connected');}});

WASM Utilities

import{hmacSha256,// HMAC-SHA256 signinghmacSha512,// HMAC-SHA512 signingsha256,// SHA256 hashsha512,// SHA512 hashbase64Encode,// Base64 encodebase64Decode,// Base64 decodeurlEncode,// URL encodegenerateUuid,// Generate UUID v4getCurrentTimestamp,// Current timestamp (ms)getSupportedExchanges// List of supported exchanges}from'./pkg/ccxt_rust.js';

Note: WASM builds have some limitations compared to native builds:

  • No private trading APIs (for security reasons)
  • Subject to CORS restrictions (may need a proxy server)

Quick Start

use ccxt_rust::exchanges::Binance;use ccxt_rust::types::Exchange;use ccxt_rust::ExchangeConfig;#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error>>{let exchange = Binance::new(ExchangeConfig::default())?;// Fetch tickerlet ticker = exchange.fetch_ticker("BTC/USDT").await?;println!("BTC/USDT: {:?}", ticker.last);// Fetch order booklet orderbook = exchange.fetch_order_book("BTC/USDT",Some(5)).await?;println!("Best bid: {}, Best ask: {}",
orderbook.bids[0].price,
orderbook.asks[0].price
);Ok(())}

See examples/ for more examples including WebSocket and trading.

Documentation

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages