cefi_rs_bybit/rest/
account.rs

1use std::collections::HashMap;
2
3use crate::{
4    errors::BybitResult,
5    http::BybitHttp,
6    types::{BybitAccountInfo, GetWalletBalanceResponse},
7};
8
9impl BybitHttp {
10    pub async fn get_wallet_balance(&self) -> BybitResult<GetWalletBalanceResponse> {
11        let mut params = HashMap::new();
12        params.insert("accountType", "UNIFIED");
13
14        self.send_get_request::<GetWalletBalanceResponse>("v5/account/wallet-balance", params, true)
15            .await
16    }
17
18    pub async fn get_account_info(&self) -> BybitResult<BybitAccountInfo> {
19        self.send_get_request::<BybitAccountInfo>("v5/account/info", HashMap::new(), true)
20            .await
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use dotenv::dotenv;
28
29    #[tokio::test]
30    async fn test_get_wallet_balance() {
31        dotenv().ok();
32        let api_key = std::env::var("BYBIT_API_KEY").expect("BYBIT_API_KEY");
33        let api_secret = std::env::var("BYBIT_API_SECRET").expect("BYBIT_API_SECRET");
34        let client = BybitHttp::new(api_key, api_secret);
35        let balance = client.get_wallet_balance().await.unwrap();
36        println!("{:?}", balance);
37    }
38
39    #[tokio::test]
40    async fn test_get_account_info() {
41        dotenv().ok();
42        let api_key = std::env::var("BYBIT_API_KEY").expect("BYBIT_API_KEY");
43        let api_secret = std::env::var("BYBIT_API_SECRET").expect("BYBIT_API_SECRET");
44        let client = BybitHttp::new(api_key, api_secret);
45        let account_info = client.get_account_info().await.unwrap();
46        println!("{:?}", account_info);
47    }
48}