python-binance-rs is a python-binance-inspired async Rust client for Binance Spot REST APIs.
This repository focuses on the most valuable Spot REST surface first instead of attempting full parity with the Python package in one pass.
Run tests first:
cargo testRun the example against Binance Spot:
BINANCE_API_KEY=... BINANCE_API_SECRET=... cargo run --example spot_restAdd it as a dependency:
[dependencies]
python-binance-rs = { path = "." }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }src/
client.rs core REST client
ws.rs websocket helpers and typed events
types.rs request/response models
error.rs library error types
examples/
spot_rest.rs
tests/
client_contract.rs
websocket_contract.rs
Today this crate is strongest on:
- Binance Spot REST support
- signed request handling
- async
reqwesttransport withrustls - Spot websocket helpers, typed event parsing, and WS API request/response models
It is not yet aiming for full python-binance parity.
- Public REST endpoints
pingserver_timeexchange_infosymbol_infoticker_pricebook_tickerbook_tickersrecent_tradeshistorical_tradesaggregate_tradesaverage_priceticker_24hrticker_24hr_allorder_bookklinesui_klines
- Signed REST endpoints
accountasset_balanceall_ordersmy_tradescurrent_order_countopen_order_listsorder_listall_order_listscancel_order_listcancel_open_orderscommission_ratesprevented_matchesorder_amendmentssymbol_filtersopen_orderscreate_oco_ordercancel_replace_ordercreate_ordercancel_orderget_order
- Binance-compatible request signing
- Async
reqwesttransport withrustls - Spot websocket support
- raw and combined market stream URL builders
- websocket connection helpers
- typed parsing for trade, bookTicker, kline, and core user-data events
- websocket API base client and request/response envelopes
- helpers for
userDataStream.subscribeanduserDataStream.subscribe.listenToken - signed WS API request builder for flows like
session.logon
use python_binance_rs::{BinanceClient, CreateOrderRequest, OrderSide, TimeInForce};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = BinanceClient::builder()
.api_key(std::env::var("BINANCE_API_KEY")?)
.api_secret(std::env::var("BINANCE_API_SECRET")?)
.build()?;
let time = client.server_time().await?;
println!("server time: {}", time.server_time);
let order = client
.create_order(&CreateOrderRequest::limit(
"BTCUSDT",
OrderSide::Buy,
"0.00100000",
"50000.00",
TimeInForce::Gtc,
))
.await?;
println!("new order id: {}", order.order_id);
Ok(())
}- The client targets the Binance Spot REST API hosted at
https://api.binance.comby default. - Signed endpoints require both API key and API secret.
exchange_infois returned asserde_json::Valuefor now to keep the initial implementation compact.- The current library does not yet cover websocket streams, futures/margin APIs, or the entire
python-binancesurface.