1use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::account::*;
6use crate::models::*;
7
8impl BybitClient {
9 pub async fn get_wallet_balance(&self, account_type: AccountType) -> Result<WalletBalance> {
14 let account_type_str = account_type.to_string();
15 let params = vec![("accountType", account_type_str.as_str())];
16
17 self.get("/v5/account/wallet-balance", ¶ms).await
18 }
19
20 pub async fn get_account_info(&self) -> Result<AccountInfo> {
22 self.get("/v5/account/info", &[]).await
23 }
24
25 pub async fn get_fee_rate(&self, category: Category, symbol: Option<&str>) -> Result<FeeRates> {
31 let cat_str = category.to_string();
32 let mut params = vec![("category", cat_str.as_str())];
33
34 if let Some(s) = symbol {
35 params.push(("symbol", s));
36 }
37
38 self.get("/v5/account/fee-rate", ¶ms).await
39 }
40
41 pub async fn get_transaction_log(
47 &self,
48 category: Option<Category>,
49 limit: Option<u32>,
50 ) -> Result<TransactionLogs> {
51 let limit_str = limit.unwrap_or(20).to_string();
52 let mut params = vec![("limit", limit_str.as_str())];
53
54 let cat_str;
55 if let Some(c) = category {
56 cat_str = c.to_string();
57 params.push(("category", cat_str.as_str()));
58 }
59
60 self.get("/v5/account/transaction-log", ¶ms).await
61 }
62
63 pub async fn set_margin_mode(&self, margin_mode: MarginMode) -> Result<serde_json::Value> {
71 let params = SetMarginModeParams {
72 set_margin_mode: margin_mode.to_string(),
73 };
74
75 self.post("/v5/account/set-margin-mode", ¶ms).await
76 }
77
78 pub async fn get_collateral_info(&self, currency: Option<&str>) -> Result<CollateralInfo> {
83 let mut params = vec![];
84
85 if let Some(c) = currency {
86 params.push(("currency", c));
87 }
88
89 self.get("/v5/account/collateral-info", ¶ms).await
90 }
91
92 pub async fn get_borrow_history(
98 &self,
99 currency: Option<&str>,
100 limit: Option<u32>,
101 ) -> Result<BorrowHistory> {
102 let limit_str = limit.unwrap_or(20).to_string();
103 let mut params = vec![("limit", limit_str.as_str())];
104
105 if let Some(c) = currency {
106 params.push(("currency", c));
107 }
108
109 self.get("/v5/account/borrow-history", ¶ms).await
110 }
111
112 pub async fn batch_set_collateral(
113 &self,
114 params: BatchSetCollateralParams,
115 ) -> Result<BatchSetCollateralResponse> {
116 self.post("/v5/account/set-collateral-switch-batch", ¶ms)
117 .await
118 }
119
120 pub async fn get_account_instruments(
121 &self,
122 category: Category,
123 symbol: Option<&str>,
124 limit: Option<u32>,
125 cursor: Option<&str>,
126 ) -> Result<GetAccountInstrumentsResponse> {
127 let cat_str = category.to_string();
128 let limit_str;
129 let mut params = vec![("category", cat_str.as_str())];
130 if let Some(s) = symbol {
131 params.push(("symbol", s));
132 }
133 if let Some(l) = limit {
134 limit_str = l.to_string();
135 params.push(("limit", limit_str.as_str()));
136 }
137 if let Some(c) = cursor {
138 params.push(("cursor", c));
139 }
140 self.get("/v5/account/instruments-info", ¶ms).await
141 }
142
143 pub async fn get_coin_greeks(&self, base_coin: Option<&str>) -> Result<GetCoinGreeksResponse> {
144 let mut params = vec![];
145 if let Some(b) = base_coin {
146 params.push(("baseCoin", b));
147 }
148 self.get("/v5/asset/coin-greeks", ¶ms).await
149 }
150
151 pub async fn get_dcp_info(&self) -> Result<GetDcpInfoResponse> {
152 self.get("/v5/account/query-dcp-info", &[]).await
153 }
154
155 pub async fn get_group_fee_rate(
156 &self,
157 product_type: &str,
158 group_id: Option<&str>,
159 ) -> Result<GetGroupFeeRateResponse> {
160 let mut params = vec![("productType", product_type)];
161 if let Some(g) = group_id {
162 params.push(("groupId", g));
163 }
164 self.get_public("/v5/market/fee-group-info", ¶ms).await
165 }
166
167 pub async fn get_mmp_state(&self, base_coin: &str) -> Result<GetMmpStateResponse> {
168 let params = vec![("baseCoin", base_coin)];
169 self.get("/v5/account/mmp-state", ¶ms).await
170 }
171
172 pub async fn get_smp_group(&self) -> Result<GetSmpGroupResponse> {
173 self.get("/v5/account/smp-group", &[]).await
174 }
175
176 pub async fn get_transferable_amount(
177 &self,
178 coin_name: &str,
179 ) -> Result<GetTransferableAmountResponse> {
180 let params = vec![("coinName", coin_name)];
181 self.get("/v5/account/withdrawal", ¶ms).await
182 }
183
184 pub async fn get_user_settings(&self) -> Result<GetUserSettingsResponse> {
185 self.get("/v5/account/user-setting-config", &[]).await
186 }
187
188 pub async fn manual_borrow(&self, params: ManualBorrowParams) -> Result<ManualBorrowResponse> {
189 self.post("/v5/account/borrow", ¶ms).await
190 }
191
192 pub async fn manual_repay(&self, params: ManualRepayParams) -> Result<ManualRepayResponse> {
193 self.post("/v5/account/repay", ¶ms).await
194 }
195
196 pub async fn no_convert_repay(
197 &self,
198 params: NoConvertRepayParams,
199 ) -> Result<NoConvertRepayResponse> {
200 self.post("/v5/account/no-convert-repay", ¶ms).await
201 }
202
203 pub async fn one_click_repay(
204 &self,
205 params: OneClickRepayParams,
206 ) -> Result<OneClickRepayResponse> {
207 self.post("/v5/account/quick-repayment", ¶ms).await
208 }
209
210 pub async fn reset_mmp(&self, params: ResetMmpParams) -> Result<ResetMmpResponse> {
211 self.post("/v5/account/mmp-reset", ¶ms).await
212 }
213
214 pub async fn set_collateral_coin(
218 &self,
219 params: SetCollateralCoinParams,
220 ) -> Result<serde_json::Value> {
221 self.post("/v5/account/set-collateral-switch", ¶ms)
222 .await
223 }
224
225 pub async fn set_mmp(&self, params: SetMmpParams) -> Result<SetMmpResponse> {
226 self.post("/v5/account/mmp-modify", ¶ms).await
227 }
228
229 pub async fn set_price_limit(
230 &self,
231 params: SetPriceLimitParams,
232 ) -> Result<SetPriceLimitResponse> {
233 self.post("/v5/account/set-limit-px-action", ¶ms).await
234 }
235
236 pub async fn set_spot_hedging(
237 &self,
238 params: SetSpotHedgingParams,
239 ) -> Result<SetSpotHedgingResponse> {
240 self.post("/v5/account/set-hedging-mode", ¶ms).await
241 }
242
243 pub async fn upgrade_to_uta_pro(&self) -> Result<UpgradeToUtaProResponse> {
244 self.post("/v5/account/upgrade-to-uta", &serde_json::json!({}))
245 .await
246 }
247}