Skip to main content

xapi_okx/client/
trading.rs

1use crate::{
2    client::Okx,
3    common::{ratelimiter::OkxRateLimitKey, response::OkxRestRespType},
4    data::balance::OkxBalance,
5};
6use nonzero_ext::nonzero;
7use reqwest::Method;
8use xapi_shared::rest::SharedRestClientTrait;
9
10impl Okx {
11    /// Retrieve a list of assets (with non-zero balance), remaining balance, and available amount in the trading account.
12    ///
13    /// <https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance>
14    pub async fn get_balances(&self) -> OkxRestRespType<OkxBalance> {
15        let rate_limit_key = OkxRateLimitKey::new_user_based("/api/v5/account/balance");
16
17        self.executor
18            .call_with_no_payload(
19                &[(rate_limit_key, nonzero!(1u32))],
20                true,
21                Method::GET,
22                self.executor
23                    .get_endpoint()
24                    .build_rest_api_url("/api/v5/account/balance"),
25            )
26            .await
27    }
28}