# Rust client for Binance API
[](https://crates.io/crates/openxapi-binance)
This package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
Please do not edit the generated code manually, but rather regenerate it from [OpenXAPI](https://github.com/openxapi/openxapi).
## Supported APIs
| Product | Module | Sub Products |
|:---------:|-----------|--------|
| [Spot API](docs/spot/README.md) | `binance::spot` | ✅ [Spot Trading](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-api-information) <br> ✅ [Margin Trading](https://developers.binance.com/docs/margin_trading/Introduction) <br> ✅ [Algo Trading](https://developers.binance.com/docs/algo/Introduction) <br> ✅ [Wallet](https://developers.binance.com/docs/wallet/Introduction) <br> ✅ [Copy Trading](https://developers.binance.com/docs/copy_trading/Introduction) <br> ✅ [Convert](https://developers.binance.com/docs/convert/Introduction) <br> ✅ [Sub Account](https://developers.binance.com/docs/sub_account/Introduction) <br>✅ [Binance Link](https://developers.binance.com/docs/binance_link/change-log) <br>✅ [Futures Data](https://developers.binance.com/docs/derivatives/futures-data/general-info) <br> ✅ [Portfolio Margin Pro](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/general-info) <br>✅ [Staking](https://developers.binance.com/docs/staking/Introduction) <br>✅ [Dual Investment](https://developers.binance.com/docs/dual_investment/Introduction) <br>✅ [Mining](https://developers.binance.com/docs/mining/Introduction) <br>✅ [Crypto Loan](https://developers.binance.com/docs/crypto_loan/Introduction) <br>✅ [VIP Loan](https://developers.binance.com/docs/vip_loan/Introduction) <br>✅ [C2C](https://developers.binance.com/docs/c2c/Introduction) <br>✅ [Fiat](https://developers.binance.com/docs/fiat/Introduction) <br>✅ [NFT](https://developers.binance.com/docs/nft/Introduction) <br>✅ [Gift Card](https://developers.binance.com/docs/gift_card/Introduction) <br>✅ [Rebate](https://developers.binance.com/docs/rebate/Introduction) <br>✅ [Simple Earn](https://developers.binance.com/docs/simple_earn/Introduction) <br>✅ [Binance Pay History](https://developers.binance.com/docs/pay/Introduction) |
| [USD-M Futures API](docs/umfutures/README.md) | `binance::umfutures` | ✅ [USDS Margined Futures](https://developers.binance.com/docs/derivatives/usds-margined-futures/general-info) <br> ✅ [Binance Link](https://developers.binance.com/docs/binance_link/link-and-trade/futures) |
| [COIN-M Futures API](docs/cmfutures/README.md) | `binance::cmfutures` | ✅ [COIN Margined Futures](https://developers.binance.com/docs/derivatives/coin-margined-futures/general-info) |
| [Options API](docs/options/README.md) | `binance::options` | ✅ [Options](https://developers.binance.com/docs/derivatives/option/general-info) |
| [Portfolio Margin API](docs/pmargin/README.md) | `binance::pmargin` | ✅ [Portfolio Margin](https://developers.binance.com/docs/derivatives/portfolio-margin/general-info) |
## Requirements
Rust 1.70+
## Installation & Usage
Install the package using cargo:
```bash
cargo add openxapi-binance
```
Or add the following to your `Cargo.toml`:
```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:
```rust
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;
});
}
```