1use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::crypto_loan::*;
6
7impl BybitClient {
8 pub async fn adjust_ltv(&self, params: AdjustLtvParams) -> Result<AdjustLtvResponse> {
10 self.post("/v5/crypto-loan-common/adjust-ltv", ¶ms)
11 .await
12 }
13
14 pub async fn calculate_max_loan(
16 &self,
17 params: CalculateMaxLoanParams,
18 ) -> Result<CalculateMaxLoanResponse> {
19 self.post("/v5/crypto-loan-common/max-loan", ¶ms).await
20 }
21
22 pub async fn cancel_fixed_borrow_order(
24 &self,
25 params: CancelFixedBorrowOrderParams,
26 ) -> Result<CancelFixedBorrowOrderResponse> {
27 self.post("/v5/crypto-loan-fixed/borrow-order-cancel", ¶ms)
28 .await
29 }
30
31 pub async fn create_fixed_borrow(
33 &self,
34 params: CreateFixedBorrowParams,
35 ) -> Result<CreateFixedBorrowResponse> {
36 self.post("/v5/crypto-loan-fixed/borrow", ¶ms).await
37 }
38
39 pub async fn fully_repay_fixed_loan(
41 &self,
42 params: FullyRepayFixedLoanParams,
43 ) -> Result<FullyRepayFixedLoanResponse> {
44 self.post("/v5/crypto-loan-fixed/fully-repay", ¶ms)
45 .await
46 }
47
48 pub async fn get_adjustment_history(
50 &self,
51 adjust_id: Option<i64>,
52 collateral_currency: Option<&str>,
53 limit: Option<i64>,
54 cursor: Option<i64>,
55 ) -> Result<GetAdjustmentHistoryResponse> {
56 let adjust_id_str = adjust_id.map(|v| v.to_string());
57 let limit_str = limit.map(|v| v.to_string());
58 let cursor_str = cursor.map(|v| v.to_string());
59 let mut params: Vec<(&str, &str)> = vec![];
60 if let Some(ref s) = adjust_id_str {
61 params.push(("adjustId", s.as_str()));
62 }
63 if let Some(s) = collateral_currency {
64 params.push(("collateralCurrency", s));
65 }
66 if let Some(ref s) = limit_str {
67 params.push(("limit", s.as_str()));
68 }
69 if let Some(ref s) = cursor_str {
70 params.push(("cursor", s.as_str()));
71 }
72 self.get("/v5/crypto-loan-common/adjustment-history", ¶ms)
73 .await
74 }
75
76 pub async fn get_collateral_data(
78 &self,
79 currency: Option<&str>,
80 ) -> Result<GetCollateralDataResponse> {
81 let mut params: Vec<(&str, &str)> = vec![];
82 if let Some(s) = currency {
83 params.push(("currency", s));
84 }
85 self.get_public("/v5/crypto-loan-common/collateral-data", ¶ms)
86 .await
87 }
88
89 pub async fn get_fixed_repayment_history(&self) -> Result<serde_json::Value> {
94 self.get("/v5/crypto-loan-fixed/repayment-history", &[])
95 .await
96 }
97
98 pub async fn get_fixed_supply_contract_info(&self) -> Result<serde_json::Value> {
103 self.get("/v5/crypto-loan-fixed/supply-contract-info", &[])
104 .await
105 }
106
107 pub async fn get_fixed_supply_order_info(&self) -> Result<serde_json::Value> {
112 self.get("/v5/crypto-loan-fixed/supply-order-info", &[])
113 .await
114 }
115
116 pub async fn get_fixed_supply_order_quote(
118 &self,
119 ) -> Result<GetCryptoLoanFixedSupplyOrderQuoteResponse> {
120 self.get_public("/v5/crypto-loan-fixed/supply-order-quote", &[])
121 .await
122 }
123
124 pub async fn get_flexible_borrow_history(
126 &self,
127 ) -> Result<GetCryptoLoanFlexibleBorrowHistoryResponse> {
128 self.get("/v5/crypto-loan-flexible/borrow-history", &[])
129 .await
130 }
131
132 pub async fn get_flexible_ongoing_coin(&self) -> Result<serde_json::Value> {
137 self.get("/v5/crypto-loan-flexible/ongoing-coin", &[]).await
138 }
139
140 pub async fn get_flexible_repayment_history(
142 &self,
143 ) -> Result<GetCryptoLoanFlexibleRepaymentHistoryResponse> {
144 self.get("/v5/crypto-loan-flexible/repayment-history", &[])
145 .await
146 }
147
148 pub async fn get_fixed_borrow_contract_info(
153 &self,
154 order_id: Option<&str>,
155 loan_id: Option<&str>,
156 order_currency: Option<&str>,
157 term: Option<&str>,
158 limit: Option<i64>,
159 cursor: Option<i64>,
160 ) -> Result<serde_json::Value> {
161 let limit_str = limit.map(|v| v.to_string());
162 let cursor_str = cursor.map(|v| v.to_string());
163 let mut params: Vec<(&str, &str)> = vec![];
164 if let Some(s) = order_id {
165 params.push(("orderId", s));
166 }
167 if let Some(s) = loan_id {
168 params.push(("loanId", s));
169 }
170 if let Some(s) = order_currency {
171 params.push(("orderCurrency", s));
172 }
173 if let Some(s) = term {
174 params.push(("term", s));
175 }
176 if let Some(ref s) = limit_str {
177 params.push(("limit", s.as_str()));
178 }
179 if let Some(ref s) = cursor_str {
180 params.push(("cursor", s.as_str()));
181 }
182 self.get("/v5/crypto-loan-fixed/borrow-contract-info", ¶ms)
183 .await
184 }
185
186 pub async fn get_fixed_borrow_order_info(
191 &self,
192 order_id: Option<&str>,
193 order_currency: Option<&str>,
194 state: Option<&str>,
195 term: Option<&str>,
196 limit: Option<i64>,
197 cursor: Option<i64>,
198 ) -> Result<serde_json::Value> {
199 let limit_str = limit.map(|v| v.to_string());
200 let cursor_str = cursor.map(|v| v.to_string());
201 let mut params: Vec<(&str, &str)> = vec![];
202 if let Some(s) = order_id {
203 params.push(("orderId", s));
204 }
205 if let Some(s) = order_currency {
206 params.push(("orderCurrency", s));
207 }
208 if let Some(s) = state {
209 params.push(("state", s));
210 }
211 if let Some(s) = term {
212 params.push(("term", s));
213 }
214 if let Some(ref s) = limit_str {
215 params.push(("limit", s.as_str()));
216 }
217 if let Some(ref s) = cursor_str {
218 params.push(("cursor", s.as_str()));
219 }
220 self.get("/v5/crypto-loan-fixed/borrow-order-info", ¶ms)
221 .await
222 }
223
224 pub async fn get_fixed_borrow_order_quote(
226 &self,
227 order_currency: Option<&str>,
228 term: Option<&str>,
229 order_by: Option<&str>,
230 sort: Option<i64>,
231 limit: Option<i64>,
232 ) -> Result<GetFixedBorrowOrderQuoteResponse> {
233 let sort_str = sort.map(|v| v.to_string());
234 let limit_str = limit.map(|v| v.to_string());
235 let mut params: Vec<(&str, &str)> = vec![];
236 if let Some(s) = order_currency {
237 params.push(("orderCurrency", s));
238 }
239 if let Some(s) = term {
240 params.push(("term", s));
241 }
242 if let Some(s) = order_by {
243 params.push(("orderBy", s));
244 }
245 if let Some(ref s) = sort_str {
246 params.push(("sort", s.as_str()));
247 }
248 if let Some(ref s) = limit_str {
249 params.push(("limit", s.as_str()));
250 }
251 self.get_public("/v5/crypto-loan-fixed/borrow-order-quote", ¶ms)
252 .await
253 }
254
255 pub async fn get_fixed_renew_info(
260 &self,
261 order_id: Option<&str>,
262 order_currency: Option<&str>,
263 limit: Option<i64>,
264 cursor: Option<i64>,
265 ) -> Result<serde_json::Value> {
266 let limit_str = limit.map(|v| v.to_string());
267 let cursor_str = cursor.map(|v| v.to_string());
268 let mut params: Vec<(&str, &str)> = vec![];
269 if let Some(s) = order_id {
270 params.push(("orderId", s));
271 }
272 if let Some(s) = order_currency {
273 params.push(("orderCurrency", s));
274 }
275 if let Some(ref s) = limit_str {
276 params.push(("limit", s.as_str()));
277 }
278 if let Some(ref s) = cursor_str {
279 params.push(("cursor", s.as_str()));
280 }
281 self.get("/v5/crypto-loan-fixed/renew-info", ¶ms).await
282 }
283
284 pub async fn get_loan_position(&self) -> Result<GetLoanPositionResponse> {
286 self.get("/v5/crypto-loan-common/position", &[]).await
287 }
288
289 pub async fn get_loanable_data(
291 &self,
292 currency: Option<&str>,
293 vip_level: Option<&str>,
294 ) -> Result<GetLoanableDataResponse> {
295 let mut params: Vec<(&str, &str)> = vec![];
296 if let Some(s) = currency {
297 params.push(("currency", s));
298 }
299 if let Some(s) = vip_level {
300 params.push(("vipLevel", s));
301 }
302 self.get_public("/v5/crypto-loan-common/loanable-data", ¶ms)
305 .await
306 }
307
308 pub async fn get_max_collateral_amount(
310 &self,
311 currency: &str,
312 ) -> Result<GetMaxCollateralAmountResponse> {
313 let params = vec![("currency", currency)];
314 self.get("/v5/crypto-loan-common/max-collateral-amount", ¶ms)
315 .await
316 }
317
318 pub async fn repay_fixed_collateral(
320 &self,
321 params: PostCryptoLoanFixedRepayCollateralParams,
322 ) -> Result<PostCryptoLoanFixedRepayCollateralResponse> {
323 self.post("/v5/crypto-loan-fixed/repay-collateral", ¶ms)
324 .await
325 }
326
327 pub async fn create_fixed_supply(
332 &self,
333 params: PostCryptoLoanFixedSupplyParams,
334 ) -> Result<serde_json::Value> {
335 self.post("/v5/crypto-loan-fixed/supply", ¶ms).await
336 }
337
338 pub async fn cancel_fixed_supply_order(
340 &self,
341 params: PostCryptoLoanFixedSupplyOrderCancelParams,
342 ) -> Result<PostCryptoLoanFixedSupplyOrderCancelResponse> {
343 self.post("/v5/crypto-loan-fixed/supply-order-cancel", ¶ms)
344 .await
345 }
346
347 pub async fn create_flexible_borrow(
349 &self,
350 params: PostCryptoLoanFlexibleBorrowParams,
351 ) -> Result<PostCryptoLoanFlexibleBorrowResponse> {
352 self.post("/v5/crypto-loan-flexible/borrow", ¶ms).await
353 }
354
355 pub async fn repay_flexible_loan(
360 &self,
361 params: PostCryptoLoanFlexibleRepayParams,
362 ) -> Result<serde_json::Value> {
363 self.post("/v5/crypto-loan-flexible/repay", ¶ms).await
364 }
365
366 pub async fn repay_flexible_collateral(
368 &self,
369 params: PostCryptoLoanFlexibleRepayCollateralParams,
370 ) -> Result<PostCryptoLoanFlexibleRepayCollateralResponse> {
371 self.post("/v5/crypto-loan-flexible/repay-collateral", ¶ms)
372 .await
373 }
374
375 pub async fn renew_fixed_loan(
380 &self,
381 params: RenewFixedLoanParams,
382 ) -> Result<serde_json::Value> {
383 self.post("/v5/crypto-loan-fixed/renew", ¶ms).await
384 }
385}