rust-okx is an unofficial OKX client focused on typed request/response models,
clear error handling, demo trading support, regional API hosts, and optional
WebSocket streams.
Status: early
0.6.x. The REST surface is usable and still expanding. Public API details may change before1.0.
Installation
[]
= "0.6.0"
= { = "1", = ["rt-multi-thread", "macros"] }
The default feature enables the built-in reqwest transport. Disable default
features only when you provide your own Transport implementation.
[]
= { = "0.6.0", = false }
Enable optional WebSocket support when you need streaming market, business, or private account channels.
= { = "0.6.0", = ["websocket"] }
Quick start
Public market data does not require credentials.
use ;
async
Authenticated REST
Authenticated endpoints require an OKX API key, secret, and passphrase.
use ;
async
Demo trading
OKX demo trading uses separate credentials. The builder sends
x-simulated-trading: 1 for demo requests.
use ;
let credentials = new;
let client = builder
.credentials
.demo_trading
.build;
Regional API hosts
The default host is the global OKX API domain. Regional accounts can select the
matching domain through OkxRegion.
use ;
let client = builder
.region
.build;
What is included
- Typed REST accessors for
market,public_data,account,funding,convert,finance, andtrade. - Optional typed WebSocket client behind the
websocketfeature. - Demo trading mode and regional API domain selection.
- Matchable two-level errors:
RestError,WsError, and shared request validation errors. - Lossless numeric strings through
NumberString, with optionalrust-decimalconversion. - Swappable
Transportfor tests, proxies, retry layers, request recording, or custom HTTP stacks.
Feature flags
| Feature | Default | Purpose |
|---|---|---|
reqwest |
yes | Built-in HTTPS transport. |
websocket |
no | Typed OKX WebSocket clients and events. |
rust-decimal |
no | Convert NumberString values to rust_decimal::Decimal. |
Examples
Testing
Most tests run offline with mock transports. Network and credential-dependent tests skip automatically when the required environment variables are missing.
For live account, demo trading, asset mutation, advanced trade, convert, or
finance tests, see .env.example. Mutation tests are disabled
unless the matching OKX_ENABLE_*_MUTATION=1 switch is set.
Roadmap
Current coverage includes market data, public data, account, funding, convert, finance, trade, and optional WebSocket support. The next major areas are SubAccount, RFQ/block trading, grid/copy trading, spread trading, trading-data analytics, and status endpoints.
See TODO.md for the detailed backlog.
Contributing
See CONTRIBUTING.md for how to add a new API endpoint, including the required doc comment format, unit test and integration test conventions, and the per-PR checklist.
Disclaimer
This is an unofficial SDK and is not affiliated with OKX. Trading involves financial risk. Test your flows against the demo environment before using live credentials.
License
Licensed under MIT.