2 unstable releases
new 0.2.0 | May 5, 2025 |
---|---|
0.1.2 | Apr 30, 2025 |
#821 in Magic Beans
108 downloads per month
4MB
67K
SLoC
Rust client for Binance API
This package is automatically generated by the OpenAPI Generator project.
Please do not edit the generated code manually, but rather regenerate it from OpenXAPI.
- API version: 0.1.2
- Package version: 0.1.2
Requirements.
Rust 1.70+
Installation & Usage
Install the package using cargo:
cargo add openxapi-binance
Or add the following to your Cargo.toml
:
[dependencies]
openxapi-binance = { git = "https://github.com/openxapi/binance-rs" }
Getting Started
In your own code, to use this library to connect and interact with spot
and umfutures
, you can run the following:
use binance::spot;
use binance::derivatives::umfutures;
use std::env;
use std::time::{SystemTime, UNIX_EPOCH};
async fn test_spot() {
let auth = spot::BinanceAuth::new_with_private_key_path(
env::var("BINANCE_API_KEY").unwrap().as_str(),
"/path/to/your/private/key.pem",
None
).unwrap();
let mut config = spot::Configuration::new();
config.binance_auth = Some(auth);
match spot::account_api::spot_get_account_v3(
&config,
spot::account_api::SpotGetAccountV3Params {
timestamp: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as i64,
..Default::default()
}
).await {
Ok(response) => {
println!("Spot account information:");
println!("{:#?}", response);
}
Err(e) => {
println!("Error calling spot_get_account_v3: {:?}", e);
}
}
}
async fn test_umfutures() {
let auth = spot::BinanceAuth::new_with_secret_key(
env::var("BINANCE_API_KEY").unwrap().as_str(),
env::var("BINANCE_SECRET_KEY").unwrap().as_str()
).unwrap();
let mut config = umfutures::Configuration::new();
config.binance_auth = Some(auth);
match umfutures::market_data_api::umfutures_get_klines_v1(
&config,
umfutures::market_data_api::UmfuturesGetKlinesV1Params {
symbol: "BTCUSDT".to_string(),
interval: "1h".to_string(),
..Default::default()
}
).await {
Ok(response) => {
println!("UMFutures klines:");
println!("{:#?}", response);
}
Err(e) => {
println!("Error calling umfutures_get_klines_v1: {:?}", e);
}
}
}
fn main() {
trpl::run(async {
test_spot().await;
test_umfutures().await;
});
}
Supported APIs
Product | Supported | Module | Documentation |
---|---|---|---|
Spot | ✅ | binance::spot | Spot API |
USD-M Futures | ✅ | binance::derivatives::umfutures | USD-M Futures API |
COIN-M Futures | ✅ | binance::derivatives::cmfutures | COIN-M Futures API |
Options | ✅ | binance::derivatives::options | Options API |
Porfolio Margin | ✅ | binance::derivatives::pmargin | Portfolio Margin API |
Porfolio Margin Pro | ✅ | binance::derivatives::pmarginpro | Portfolio Margin Pro API |
Futures Data | ✅ | binance.derivatives.futuresdata | Futures Data API |
Margin | ✅ | binance::margin | Margin API |
Algo | ✅ | binance::algo | Algo API |
Wallet | ✅ | binance::wallet | Wallet API |
Copy Trading | ✅ | binance::copytrading | Copy Trading API |
Sub-Account | ✅ | binance::subaccount | Sub-Account API |
Dependencies
~8–25MB
~335K SLoC