Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)45k · #6386

ccxt-rust

Skill này làm gì

Skill này là hướng dẫn xây dựng tính năng sàn tiền mã hóa trong dự án Rust bằng các crate CCXT. Nó dành cho lập trình viên xây bot giao dịch hoặc dịch vụ độ trễ thấp bằng Rust.

Khi nào nên dùng

  • ✓Khi bạn đang viết một service Rust đọc dữ liệu thị trường tiền mã hóa.
  • ✓Khi bạn cần đặt hoặc kiểm tra lệnh từ một bot giao dịch Rust.
  • ✓Khi bạn muốn cập nhật WebSocket trực tiếp trong một dự án Rust.

Liên kết skill

https://github.com/ccxt/ccxt/blob/master/.claude/skills/ccxt-rust/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/ccxt/ccxt/blob/master/.claude/skills/ccxt-rust/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Viết một chương trình Rust in ticker BTC/USDT của Binance.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI thêm crate ccxt cùng tokio, tạo một đối tượng sàn có kiểu rõ ràng và await từng phương thức. Mỗi phương thức trả về kết quả có kiểu hoặc lỗi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.
  • ccxt alone is enough for REST. Add ccxt-pro only when you need watch_*; 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
Câu hỏi thường gặp

Có API đồng bộ không?

Không. Skill nói mọi phương thức thống nhất đều là async và không có API đồng bộ.

Tôi có cần crate WebSocket không?

Chỉ khi bạn cần truyền dữ liệu trực tiếp. Skill nói crate ccxt-pro tách riêng và cần cho các hàm watch.

Cần runtime nào?

Skill yêu cầu runtime tokio và phiên bản Rust ổn định, edition 2021 trở lên.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
45k
Vị trí xếp hạng
#6386
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự