This package is automatically generated by the OpenAPI Generator project.
Please do not edit the generated code manually, but rather regenerate it from OpenXAPI.
Product | Module | Sub Products |
---|---|---|
Spot API | binance::spot | ✅ Spot Trading ✅ Margin Trading ✅ Algo Trading ✅ Wallet ✅ Copy Trading ✅ Convert ✅ Sub Account ✅ Binance Link ✅ Futures Data ✅ Portfolio Margin Pro ✅ Staking ✅ Dual Investment ✅ Mining ✅ Crypto Loan ✅ VIP Loan ✅ C2C ✅ Fiat ✅ NFT ✅ Gift Card ✅ Rebate ✅ Simple Earn ✅ Binance Pay History |
USD-M Futures API | binance::umfutures | ✅ USDS Margined Futures ✅ Binance Link |
COIN-M Futures API | binance::cmfutures | ✅ COIN Margined Futures |
Options API | binance::options | ✅ Options |
Portfolio Margin API | binance::pmargin | ✅ Portfolio Margin |
Rust 1.70+
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" }
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::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::spot_trading_api::get_account_v3( &config, spot::spot_trading_api::GetAccountV3Params { 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 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::futures_api::get_klines_v1( &config, umfutures::futures_api::GetKlinesV1Params { symbol: "BTCUSDT".to_string(), interval: "1h".to_string(), ..Default::default() } ).await { Ok(response) => { println!("UMFutures klines:"); println!("{:#?}", response); } Err(e) => { println!("Error calling get_klines_v1: {:?}", e); } } } fn main() { trpl::run(async { test_spot().await; test_umfutures().await; }); }