| Crates.io | weex_rust_sdk |
| lib.rs | weex_rust_sdk |
| version | 0.6.1 |
| created_at | 2025-12-31 13:13:05.710589+00 |
| updated_at | 2026-01-02 16:13:37.241814+00 |
| description | Professional Rust SDK for WEEX Exchange - AI Wars ready with full API coverage, AI Log upload, Futures trading |
| homepage | |
| repository | https://github.com/akash-mondal/weex-rust-sdk |
| max_upload_size | |
| id | 2014665 |
| size | 165,610 |
Production-Grade Rust SDK for WEEX Exchange
Full AI Wars API Coverage • Async/Await • Type-Safe
Installation • Quick Start • API Reference • Examples • Contributing
The official Rust SDK for WEEX Exchange, providing complete API coverage for spot trading, futures, and the AI Wars competition. Built with async/await for high performance and type safety.
| Feature | Description |
|---|---|
| 🚀 Async/Await | Built on Tokio for high-performance async operations |
| 🔐 Secure Auth | HMAC-SHA256 signing with automatic header generation |
| 📊 Full API Coverage | 45+ endpoints for Market, Account, and Trade APIs |
| 🤖 AI Wars Ready | Built-in AI Log upload for competition compliance |
| 🛡️ Type Safe | Strongly typed requests and responses |
| ⚡ Rate Limiting | Built-in rate limiter to prevent API throttling |
| 🔄 Retry Logic | Automatic retry with exponential backoff |
graph TB
subgraph Client["WeexClient"]
B[Builder Pattern]
A[Authentication]
R[Rate Limiter]
RT[Retry Middleware]
end
subgraph Endpoints["API Endpoints"]
M[Market Data]
AC[Account]
T[Trade]
AI[AI Log]
end
subgraph Transport["HTTP Layer"]
REQ[Reqwest Client]
SIG[HMAC Signing]
end
B --> A
A --> R
R --> RT
RT --> REQ
REQ --> SIG
M --> Client
AC --> Client
T --> Client
AI --> Client
SIG --> WEEX[(WEEX API)]
Add to your Cargo.toml:
[dependencies]
weex_rust_sdk = "0.6"
tokio = { version = "1", features = ["full"] }
Or install via cargo:
cargo add weex_rust_sdk tokio --features tokio/full
use weex_rust_sdk::WeexClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client
let client = WeexClient::builder()
.base_url("https://api-contract.weex.com")
.api_key("your_api_key")
.secret_key("your_secret_key")
.passphrase("your_passphrase")
.build()?;
// Get BTC ticker
let ticker = client.get_ticker("cmt_btcusdt").await?;
println!("BTC Price: ${}", ticker.last);
// Get account assets
let assets = client.get_assets().await?;
println!("Balance: {}", assets);
Ok(())
}
flowchart LR
subgraph Market["📊 Market Endpoints"]
T[get_ticker]
AT[get_all_tickers]
D[get_depth]
K[get_klines]
TR[get_trades]
C[get_contracts]
FR[get_funding_rate]
OI[get_open_interest]
end
| Method | Endpoint | Description |
|---|---|---|
get_server_time() |
/capi/v2/market/time |
Server timestamp |
get_contracts() |
/capi/v2/market/contracts |
Contract info |
get_ticker(symbol) |
/capi/v2/market/ticker |
Single ticker |
get_all_tickers() |
/capi/v2/market/tickers |
All tickers |
get_depth(symbol) |
/capi/v2/market/depth |
Orderbook |
get_klines(symbol, interval) |
/capi/v2/market/candles |
Candlesticks |
get_trades(symbol) |
/capi/v2/market/trades |
Recent trades |
get_funding_rate(symbol) |
/capi/v2/market/fundingRate |
Funding rate |
get_open_interest(symbol) |
/capi/v2/market/openInterest |
Open interest |
flowchart LR
subgraph Account["🔐 Account Endpoints"]
A[get_assets]
P[get_positions]
B[get_bills]
L[set_leverage]
M[set_margin_mode]
end
| Method | Endpoint | Description |
|---|---|---|
get_assets() |
/capi/v2/account/assets |
Account balance |
get_position(symbol) |
/capi/v2/account/position/singlePosition |
Single position |
get_all_positions() |
/capi/v2/account/position/allPosition |
All positions |
get_bills(symbol) |
/capi/v2/account/bills |
Account ledger |
set_leverage(symbol, leverage) |
/capi/v2/account/leverage |
Set leverage |
set_margin_mode(symbol, mode) |
/capi/v2/account/setMarginMode |
Margin mode |
adjust_margin(symbol, amount) |
/capi/v2/account/adjustPositionMargin |
Adjust margin |
flowchart LR
subgraph Trade["⚡ Trade Endpoints"]
PO[place_futures_order]
CO[cancel_futures_order]
CA[cancel_all_orders]
TO[place_trigger_order]
TP[place_tpsl]
end
| Method | Endpoint | Description |
|---|---|---|
place_futures_order(...) |
/capi/v2/order/placeOrder |
Place order |
cancel_futures_order(...) |
/capi/v2/order/cancelOrder |
Cancel order |
cancel_all_orders(symbol) |
/capi/v2/order/cancelAllOrders |
Cancel all |
get_order_detail(...) |
/capi/v2/order/detail |
Order info |
get_order_history(symbol) |
/capi/v2/order/history |
Order history |
get_current_orders(symbol) |
/capi/v2/order/current |
Open orders |
get_fills(symbol) |
/capi/v2/order/fills |
Trade fills |
place_trigger_order(...) |
/capi/v2/order/placeTriggerOrder |
Trigger order |
place_tpsl(...) |
/capi/v2/order/placeTPSL |
TP/SL order |
close_all_positions(symbol) |
/capi/v2/order/closeAllPositions |
Close all |
flowchart LR
AI[upload_ai_log] --> WEEX[(WEEX API)]
WEEX --> COMP[Competition Compliance]
| Method | Endpoint | Description |
|---|---|---|
upload_ai_log(...) |
/capi/v2/order/uploadAiLog |
Upload AI reasoning log |
use weex_rust_sdk::{WeexClient, Side, OrderType};
async fn place_order(client: &WeexClient) -> Result<(), Box<dyn std::error::Error>> {
let result = client.place_futures_order(
"cmt_btcusdt",
"0.001",
Side::Buy,
OrderType::Market,
None, // price (not needed for market)
Some("my_order_123"), // client order id
).await?;
println!("Order placed: {}", result);
Ok(())
}
use weex_rust_sdk::WeexClient;
use serde_json::json;
async fn upload_ai_log(client: &WeexClient) -> Result<(), Box<dyn std::error::Error>> {
let result = client.upload_ai_log(
Some(12345), // order_id (optional)
"Strategy Generation",
"gpt-5.2",
json!({"market_data": {"price": 88000, "rsi": 45}}),
json!({"signal": "BUY", "confidence": 0.85}),
"RSI indicates oversold conditions with bullish divergence."
).await?;
println!("AI Log uploaded: {}", result);
Ok(())
}
use weex_rust_sdk::{WeexClient, WeexError};
async fn safe_request(client: &WeexClient) {
match client.get_ticker("cmt_btcusdt").await {
Ok(ticker) => println!("Price: {}", ticker.last),
Err(WeexError::Api { code, msg }) => {
eprintln!("API Error {}: {}", code, msg);
}
Err(WeexError::Network(e)) => {
eprintln!("Network error: {}", e);
}
Err(e) => eprintln!("Other error: {:?}", e),
}
}
let client = WeexClient::builder()
.base_url("https://api-contract.weex.com") // Required
.api_key("your_key") // Required
.secret_key("your_secret") // Required
.passphrase("your_passphrase") // Required
.timeout(Duration::from_secs(30)) // Optional
.build()?;
use weex_rust_sdk::{
// Core
WeexClient,
WeexClientBuilder,
WeexError,
// Types
Side, // Buy, Sell
OrderType, // Limit, Market, Trigger
TimeInForce, // Gtc, Ioc, Fok
MarginMode, // Crossed, Isolated
PositionSide, // Long, Short
TriggerType, // FillPrice, MarkPrice
AILogStage, // StrategyGeneration, DecisionMaking, etc.
};
This SDK is fully compatible with the WEEX AI Wars hackathon requirements:
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
# Clone
git clone https://github.com/Miny-Labs/weex-rust-sdk.git
# Build
cargo build
# Test
cargo test
# Run examples
cargo run --example full_test
MIT License - see LICENSE for details.
Made with 🦀 by Miny Labs