WEEX Rust SDK
Production-Grade Rust SDK for WEEX Exchange
Full AI Wars API Coverage • Async/Await • Type-Safe
Installation • Quick Start • API Reference • Examples • Contributing
🎯 Overview
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.
Key Features
| 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 |
🏗️ Architecture
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)]
📦 Installation
Add to your Cargo.toml:
[]
= "0.6"
= { = "1", = ["full"] }
Or install via cargo:
🚀 Quick Start
use WeexClient;
async
📊 API Coverage
Market Data (Public)
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 |
Account (Authenticated)
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 |
Trading (Authenticated)
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 |
AI Wars (Competition)
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 |
📖 Examples
Placing a Market Order
use ;
async
Uploading AI Log
use WeexClient;
use json;
async
Error Handling
use ;
async
🔧 Configuration
Builder Options
let client = builder
.base_url // Required
.api_key // Required
.secret_key // Required
.passphrase // Required
.timeout // Optional
.build?;
📐 Type Reference
use ;
🏆 AI Wars Competition
This SDK is fully compatible with the WEEX AI Wars hackathon requirements:
- ✅ All required API endpoints implemented
- ✅ AI Log upload for competition compliance
- ✅ Maximum 20x leverage support
- ✅ All allowed trading pairs supported
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
# Clone
# Build
# Test
# Run examples
📜 License
MIT License - see LICENSE for details.
🔗 Related
- Fenyr AI Agent - GPT-5.2 trading bot using this SDK
- WEEX Exchange - Official exchange website
- API Documentation - Official API docs
Made with 🦀 by Miny Labs