oanda-rs
A complete, asynchronous Rust SDK for the OANDA v20 REST and streaming API, built for multi-threaded tokio environments.
Highlights
- Complete — all 35 v20 operations (accounts, instruments, orders, trades, positions, pricing, transactions) plus both streaming endpoints. See the coverage table.
- One shared client —
Clientis cheap to clone andSend + Sync; all clones share a connection pool and a built-in rate limiter that keeps you under OANDA's per-IP limits (100 of 120 REST req/s, 2 connections/s). No accidental 429s. - Self-managing streams — pricing and transaction streams detect stale connections via heartbeats, reconnect with capped exponential backoff (outage-safe: at most one attempt per 5 minutes during e.g. weekend maintenance), and back-fill missed transactions via
sinceidwith deduplication. Consuming them is just awhile letloop. - Typed, faithful models — every request/response type is
Debug + Clone + Serialize + Deserialize. Decimals arerust_decimal::Decimalnewtypes (never floats). The 36-variantTransactionand 8-variantOrderunions are internally tagged enums with losslessUnknownfallbacks, so schema drift never breaks deserialization. - Lightweight builders — optional parameters via fluent per-endpoint builders; typed order requests (
MarketOrderRequest::new("EUR_USD", 100).stop_loss_on_fill(...)). - Typed instruments —
InstrumentNameenumerates all known OANDA symbols (with anOtherescape hatch), while every API still accepts plain"EUR_USD"strings.
Installation
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
= "0.3"
Quickstart
use StreamExt;
use *;
async
More runnable examples in examples/: list_accounts, candles, market_order, pricing_stream, transaction_stream.
Feature flags
| Feature | Default | Description |
|---|---|---|
tracing |
off | DEBUG-level instrumentation of requests and stream reconnection. |
Documentation
- Getting started — tokens, client configuration, error handling
- Endpoint coverage — all 35 operations → SDK methods
- Streaming guide — heartbeats, reconnection, back-fill, tuning
- Rate limiting — OANDA's limits and the built-in limiter
- Testing guide — test layers, wiremock patterns, live tests, coverage
- API reference
Testing
~90 tests cover every endpoint (wiremock), every Transaction/Order variant (byte-exact serde round-trips), NDJSON framing edge cases, and the reconnect state machine under paused tokio time. An opt-in live suite validates against fxPractice:
Disclaimer
This is an unofficial SDK, not affiliated with or endorsed by OANDA. Trading foreign exchange carries a high level of risk. Develop against the fxTrade Practice environment until you are confident in your integration.
License
BSD 3-Clause — see LICENSE.