openxapi-binance 0.2.0

Rust client for Binance API
Documentation
# Rust client for Binance API

[![Crates.io Version](https://img.shields.io/crates/v/openxapi-binance)](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 <br> ✅ Margin Trading <br> ✅ Algo Trading <br> ✅ Wallet <br> ✅ Copy Trading <br> ✅ Convert <br> ✅ Sub Account <br>✅ Binance Link <br>✅ Futures Data <br> ✅ Portfolio Margin Pro |
| [USD-M Futures API]docs/umfutures/README.md | `binance::umfutures` | ✅ USDS Margined Futures |
| [COIN-M Futures API]docs/cmfutures/README.md | `binance::cmfutures` | ✅ COIN Margined Futures |
| [Options API]docs/options/README.md | `binance::options` | ✅ Options |
| [Portfolio Margin API]docs/pmargin/README.md | `binance::pmargin` | ✅ Porfolio Margin |

## 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::usds_margined_futures_api::get_klines_v1(
        &config,
        umfutures::usds_margined_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;
    });
}
```