account_example/
account_example.rs

1use bybit_rust_api::rest::account::dto::account_wallet::GetWalletBalanceParams;
2use bybit_rust_api::rest::enums::account_type::AccountType;
3use bybit_rust_api::rest::{AccountClient, ApiKeyPair, RestClient};
4use std::env;
5
6#[tokio::main]
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let api_key = env::var("BYBIT_API_KEY").unwrap_or_else(|_| "YOUR_API_KEY".to_string());
9    let api_secret = env::var("BYBIT_API_SECRET").unwrap_or_else(|_| "YOUR_API_SECRET".to_string());
10
11    // Using testnet by default
12    let base_url = "https://api-testnet.bybit.com".to_string();
13
14    // ApiKeyPair takes (profile_name, key, secret)
15    let key_pair = ApiKeyPair::new("account_demo".to_string(), api_key, api_secret);
16    let client = RestClient::new(key_pair, base_url);
17
18    // AccountClient takes ownership of RestClient
19    let account_client = AccountClient::new(client);
20
21    println!("--- Testing get_wallet_balance ---");
22    let params = GetWalletBalanceParams {
23        account_type: AccountType::UNIFIED,
24        coin: None,
25    };
26
27    match account_client.get_wallet_balance(params).await {
28        Ok(response) => println!("Success: {:?}", response),
29        Err(e) => println!("Error: {:?}", e),
30    }
31
32    println!("\n--- Testing get_fee_rate ---");
33    match account_client.get_fee_rate("spot", None, None).await {
34        Ok(response) => println!("Success: {:?}", response),
35        Err(e) => println!("Error: {:?}", e),
36    }
37
38    Ok(())
39}