o2-sdk-0.0.1 has been yanked.
Installation
Add to your Cargo.toml:
[]
= { = "https://github.com/o2-exchange/sdks.git", = "sdks/rust" }
= { = "1", = ["full"] }
MSRV: Rust 1.75
Quick Start
use ;
async
Features
- Trading — Place, cancel, and manage orders with automatic price/quantity scaling
- Market Data — Fetch order book depth, recent trades, OHLCV candles, and ticker data
- WebSocket Streams — Real-time depth, order, trade, balance, and nonce updates via
Stream - Wallet Support — Fuel-native and EVM wallets with session-based signing
- Batch Actions — Submit up to 5 actions per request (cancel + settle + create in one call)
- Async Runtime — Built on
tokiowithreqwestfor HTTP andtokio-tungstenitefor WebSocket - Type Safety — Strongly typed responses with
serdedeserialization andthiserrorerrors
API Overview
| Method | Description |
|---|---|
generate_wallet() / load_wallet(hex) |
Create or load a Fuel wallet |
generate_evm_wallet() / load_evm_wallet(hex) |
Create or load an EVM wallet |
setup_account(&wallet) |
Idempotent account setup |
create_session(&wallet, markets, days) |
Create a trading session |
create_order(&mut session, market, side, price, qty, ...) |
Place an order |
cancel_order(&mut session, order_id, market) |
Cancel a specific order |
cancel_all_orders(&mut session, market) |
Cancel all open orders |
settle_balance(&mut session, market) |
Settle filled order proceeds |
batch_actions(&mut session, actions, calls, collect) |
Submit raw action batch |
get_markets() / get_market(name) |
Fetch market info |
get_depth(market, precision) / get_trades(market, count) |
Order book and trade data |
get_balances(trade_account_id) / get_orders(id, market, ...) |
Account data |
stream_depth(market_id, precision) |
Real-time order book stream |
stream_orders(identities) / stream_trades(market_id) |
Real-time updates |
See AGENTS.md for the complete API reference with all parameters and types.
Guides
| Guide | Description |
|---|---|
| Trading | Order types, batch actions, cancel/replace, and market maker patterns |
| Market Data | Fetching depth, trades, candles, tickers, and balances |
| WebSocket Streams | Real-time data with TypedStream and reconnection handling |
| Error Handling | Error types, recovery patterns, and robust trading loops |
| External Signers | Integrating KMS/HSM via the SignableWallet trait |
Examples
| Example | Description |
|---|---|
quickstart.rs |
Connect, create a wallet, place your first order |
market_maker.rs |
Two-sided quoting loop with cancel/replace |
taker_bot.rs |
Monitor depth and take liquidity |
portfolio.rs |
Multi-market balance tracking and management |
Run an example:
Testing
Unit tests (no network required):
Integration tests (requires O2_PRIVATE_KEY env var):
O2_PRIVATE_KEY=0x...
The --test-threads=1 flag avoids nonce race conditions during integration tests.
AI Agent Integration
See AGENTS.md for an LLM-optimized reference covering all methods, types, error codes, and common patterns.