ccxt-rust
它能做什么
这个技能是在 Rust 项目中使用 CCXT crates 构建加密交易所功能的指南。适合用 Rust 开发交易机器人或低延迟服务的开发者。
适用场景
- ✓当你正在构建读取加密货币市场数据的 Rust 服务的时候。
- ✓当你需要从 Rust 交易机器人下单或查询订单的时候。
- ✓当你想在 Rust 项目中接收实时 WebSocket 更新的时候。
技能链接
https://github.com/ccxt/ccxt/blob/master/.claude/skills/ccxt-rust/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请编写一个 Rust 程序,打印 Binance 的 BTC/USDT 行情?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会添加带有 tokio 的 ccxt crate,创建有类型的交易所对象,并等待每个方法返回有类型的结果或错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
CCXT for Rust
A comprehensive guide to using CCXT in Rust projects for cryptocurrency exchange integration.
Every exchange has a typed wrapper (ccxt::Binance, ccxt::Kraken, …) exposing the unified
CCXT API with native Rust return types — Ticker, Order, OrderBook, Market — instead of a
dynamic value. All methods are async and return Result<T, ExchangeError>.
Installation
REST API
cargo add ccxt tokio --features tokio/full
WebSocket API (ccxt.pro)
cargo add ccxt-pro
Prediction markets
cargo add ccxt-prediction
Cargo.toml
[dependencies]
ccxt = "4.5.75" # REST exchanges (typed) — required
ccxt-pro = "4.5.75" # WebSocket (watch*) exchanges — only if you stream
ccxt-prediction = "4.5.75" # prediction markets — only if you trade them
tokio = { version = "1", features = ["full"] }
Requirements
- Rust stable, edition 2021 or later.
- A tokio runtime — every unified method is
async. There is no sync API. ccxtalone is enough for REST. Addccxt-proonly when you needwatch_*; it is a separate crate so a REST-only build does not compile the whole WebSocket surface.
Quick Start
REST API
use ccxt::{Binance, Params};
#[tokio::main]
async fn main() -> Result<(), ccxt::ExchangeError> {
let mut exchange = Binance::new(None);
exchange.load_markets(false).await;
let ticker = exchange.fetch_ticker("BTC/USDT", Params::none()).await?;
println!("{} last={:?} bid={:?} ask={:?}", ticker.symbol, ticker.last, ticker.bid, ticker.ask);
Ok(())
}
WebSocket API — real-time updates
use ccxt::Params;
use ccxt_pro::Binance;
#[tokio::main]
async fn main() -> Result<(), ccxt::ExchangeError> {
let mut exchange = Binance::new(None);
exchange.try_load_markets(false).await?;
loop {
let ticker = exchange.watch_ticker("BTC/USDT", Params::none()).await?;
println!("{:?}", ticker.last); // live updates
}
}
Each watch_* call resolves to one decoded update, so consuming a stream is just calling it in
a loop.
Crate layout
| Crate | Contains | Use when |
|---|---|---|
ccxt |
Typed REST wrappers (ccxt::Binance, …), Params, Config, types::*, TypedExchange. Re-exports the whole engine at its root. |
Always |
ccxt-pro |
Typed WebSocket wrappers (ccxt_pro::Binance, …) with watch_* |
Streaming |
ccxt-prediction |
Typed prediction-market wrappers (ccxt_prediction::Kalshi, …) |
Prediction markets |
ccxt-base |
The untyped engine (Value, HTTP, crypto, rate limiter, Cores, WS infra) |
Rarely direct — ccxt re-exports it |
ccxt re-exports ccxt-base at its root, so ccxt::Value, ccxt::runtime::…,
ccxt::exchanges::binance::BinanceCore resolve alongside the typed ccxt::Binance.
Coverage today: 105 typed REST venues, 76 typed WebSocket venues, 7 prediction venues.
REST vs WebSocket
| Feature | REST API | WebSocket API |
|---|---|---|
| Use for | One-time queries, placing orders | Real-time monitoring, live price feeds |
| Crate | ccxt |
ccxt-pro |
| Import | use ccxt::Binance; |
use ccxt_pro::Binance; |
| Methods | fetch_* (fetch_ticker, fetch_order_book) |
watch_* (watch_ticker, watch_order_book) |
| Speed | Slower (HTTP request/response) | Faster (persistent connection) |
| Rate limits | Strict (1–2 req/sec) | More lenient (continuous stream) |
| Best for | Trading, account management | Price monitoring, arbitrage detection |
Both crates expose a type named Binance. When you use both in one file, alias one of them:
use ccxt::Binance as BinanceRest;
use ccxt_pro::Binance as BinanceWs;
Runtime setup
Two settings matter in real programs and are easy to miss:
fn main() {
// 1. The transpiled core signals errors by panicking across an internal
// catch_unwind; the typed layer turns that back into `Result`. Silencing
// the default hook stops caught panics from printing to stderr.
// Set CCXT_SHOW_PANICS=1 to see them while debugging.
if std::env::var("CCXT_SHOW_PANICS").is_err() {
std::panic::set_hook(Box::new(|_| {}));
}
// 2. The generated exchange code is deeply nested — give worker threads a
// large stack. The default 2 MB can overflow on some venues.
let rt = tokio::runtime::Builder::new_multi_th
常见问题
它有同步 API 吗?
没有。技能说明,所有统一方法都是异步的,没有同步 API。
我需要 WebSocket crate 吗?
只有在需要实时数据流时才需要。技能说明,ccxt-pro crate 是独立的,watch 函数需要它。
需要什么运行时?
技能要求 tokio 运行时和稳定版 Rust,edition 2021 或更高。
详情
作者的原始描述
CCXT cryptocurrency exchange library for Rust developers. Covers both REST API (standard) and WebSocket API (real-time). Helps install CCXT, connect to exchanges, fetch market data, place orders, stream live tickers/orderbooks, handle authentication, and manage errors in Rust projects. Use when working with crypto exchanges in Rust applications, trading bots, or low-latency services. Async (tokio), typed wrappers returning Result<T, ExchangeError>.
repo: ccxt/ccxt
热度
- GitHub 星标
- 45k
- 排名
- #6386
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
binance-agentic-wallet
45k帮你的智能体通过 baw 命令行管理 Binance Web3 钱包,包括登录、查询余额、转账、代币兑换和限价订单。
binance-sports-ai-analyzer
45k帮你的智能体查询世界杯比赛的预测、AI 分析和新闻洞察,并在你调整信号后重新计算胜率。
binance-tokenized-securities-info
45k帮你的智能体在 Binance Web3 上查询 Ondo 代币化美股,包括代币列表、公司信息、交易状态和链上价格。
binance
45k帮你的智能体通过 binance-cli 工具使用 Binance 现货、USD-M 合约和 Convert 功能。使用前需先完成身份验证设置。