bpx_api_client/routes/
account.rs1use crate::BpxClient;
2use crate::error::Result;
3use bpx_api_types::account::{
4 AccountMaxBorrow, AccountMaxWithdrawal, AccountSettings, ConvertDustPayload,
5 UpdateAccountPayload,
6};
7
8#[doc(hidden)]
9pub const API_ACCOUNT: &str = "/api/v1/account";
10#[doc(hidden)]
11pub const API_ACCOUNT_MAX_BORROW: &str = "/api/v1/account/limits/borrow";
12#[doc(hidden)]
13pub const API_ACCOUNT_MAX_WITHDRAWAL: &str = "/api/v1/account/limits/withdrawal";
14#[doc(hidden)]
15pub const API_ACCOUNT_CONVERT_DUST: &str = "/api/v1/account/convertDust";
16
17impl BpxClient {
18 pub async fn get_account(&self) -> Result<AccountSettings> {
20 let url = self.base_url.join(API_ACCOUNT)?;
21 let res = self.get(url).await?;
22 res.json().await.map_err(Into::into)
23 }
24
25 pub async fn get_account_max_borrow(&self, symbol: &str) -> Result<AccountMaxBorrow> {
27 let mut url = self.base_url.join(API_ACCOUNT_MAX_BORROW)?;
28 url.query_pairs_mut().append_pair("symbol", symbol);
29 let res = self.get(url).await?;
30 res.json().await.map_err(Into::into)
31 }
32
33 pub async fn get_account_max_withdrawal(
35 &self,
36 symbol: &str,
37 auto_borrow: Option<bool>,
38 auto_lend_redeem: Option<bool>,
39 ) -> Result<AccountMaxWithdrawal> {
40 let mut url = self.base_url.join(API_ACCOUNT_MAX_WITHDRAWAL)?;
41 {
42 let mut query = url.query_pairs_mut();
43 query.append_pair("symbol", symbol);
44 if let Some(auto_borrow) = auto_borrow {
45 query.append_pair("autoBorrow", &auto_borrow.to_string());
46 }
47 if let Some(auto_lend_redeem) = auto_lend_redeem {
48 query.append_pair("autoLendRedeem", &auto_lend_redeem.to_string());
49 }
50 }
51 let res = self.get(url).await?;
52 res.json().await.map_err(Into::into)
53 }
54
55 pub async fn update_account(&self, payload: UpdateAccountPayload) -> Result<()> {
57 let url = self.base_url.join(API_ACCOUNT)?;
58 self.patch(url, payload).await?;
59
60 Ok(())
61 }
62
63 pub async fn convert_dust_balance(&self, payload: ConvertDustPayload) -> Result<()> {
66 let url = self.base_url.join(API_ACCOUNT_CONVERT_DUST)?;
67 self.post(url, payload).await?;
68
69 Ok(())
70 }
71}