ndaxrs
Unofficial Rust bindings for the NDAX exchange WebSocket API.
NDAX API Docs | Project NDAX notes | Examples
This library provides a Rust client for NDAX market data and trading over WebSockets, with a synchronous API surface that is easy to integrate into CLI apps, bots, and services.
- Strongly typed requests and responses via
serde - WebSocket transport via
tokio-tungstenite - NDAX HMAC authentication support for private endpoints
- Decimal-safe price/quantity handling via
rust_decimal - Builder-based config for feeds, auth, depth, and gateway URL
- Logging support via
log .envloading support viadotenvy
Both public and private APIs are supported. Current coverage focuses on the endpoints needed for market data, account balances, open orders, placing orders, and canceling orders.
If something you need is missing, patches are welcome.
Capabilities
ndaxrs currently includes:
- Public market data subscriptions:
- Level1 (ticker)
- Level2 (order book)
- Trades
- Private/authenticated workflows:
- Authenticate user
- Subscribe account events
- Get account positions
- Get open orders
- Send order
- Cancel order
Threading
NdaxWsAPI is a blocking/synchronous interface that spawns an internal worker thread and drives an async WebSocket client behind the scenes.
Architecture:
User Code
|
v
NdaxWsAPI (sync)
|
v mpsc channel
Worker Thread (tokio runtime)
|
v
NdaxWsClient (async)
|
v
NDAX WebSocket Gateway
This keeps application code simple for most use-cases while still using async I/O internally.
Quick Start
Add dependency:
[]
= "0.1.0" # or: { path = "../ndaxrs" }
Public market data
use ;
use ;
Authenticated trading
use create_limit_order;
use ;
use ;
use Decimal;
use FromStr;
Environment Variables
For authenticated APIs, NdaxCredentials::from_env() reads:
NDAX_API_KEYNDAX_API_SECRETNDAX_USER_ID
For private account operations and the trading example:
NDAX_ACCOUNT_ID
Examples
Library examples:
cargo run --example public_datacargo run --example trading
The trading example performs real authenticated operations and submits a test order. Use a funded account with caution.
TUI example app:
ndax-tui shows:
- Live Level2 order book
- Price chart driven by Level1 updates
- Latest market trades
- Latest user trades (when authenticated)
Disclaimer
Use at your own risk. If you build trading software with this library and incur losses due to bugs, connectivity issues, or exchange behavior, you are responsible for validating and monitoring your system.