Skip to main content

binance_sdk/crypto_loan/rest_api/apis/
flexible_rate_api.rs

1/*
2 * Binance Crypto Loan REST API
3 *
4 * OpenAPI Specification for the Binance Crypto Loan REST API
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 *
9 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
10 * https://openapi-generator.tech
11 * Do not edit the class manually.
12 */
13
14#![allow(unused_imports)]
15use async_trait::async_trait;
16use derive_builder::Builder;
17use reqwest;
18use rust_decimal::prelude::*;
19use serde::{Deserialize, Serialize};
20use serde_json::{Value, json};
21use std::collections::BTreeMap;
22
23use crate::common::{
24    config::ConfigurationRestApi,
25    models::{ParamBuildError, RestApiResponse},
26    utils::send_request,
27};
28use crate::crypto_loan::rest_api::models;
29
30const HAS_TIME_UNIT: bool = false;
31
32#[async_trait]
33pub trait FlexibleRateApi: Send + Sync {
34    async fn check_collateral_repay_rate(
35        &self,
36        params: CheckCollateralRepayRateParams,
37    ) -> anyhow::Result<RestApiResponse<models::CheckCollateralRepayRateResponse>>;
38    async fn flexible_loan_adjust_ltv(
39        &self,
40        params: FlexibleLoanAdjustLtvParams,
41    ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanAdjustLtvResponse>>;
42    async fn flexible_loan_borrow(
43        &self,
44        params: FlexibleLoanBorrowParams,
45    ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanBorrowResponse>>;
46    async fn flexible_loan_repay(
47        &self,
48        params: FlexibleLoanRepayParams,
49    ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanRepayResponse>>;
50    async fn get_flexible_loan_assets_data(
51        &self,
52        params: GetFlexibleLoanAssetsDataParams,
53    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanAssetsDataResponse>>;
54    async fn get_flexible_loan_borrow_history(
55        &self,
56        params: GetFlexibleLoanBorrowHistoryParams,
57    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanBorrowHistoryResponse>>;
58    async fn get_flexible_loan_collateral_assets_data(
59        &self,
60        params: GetFlexibleLoanCollateralAssetsDataParams,
61    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanCollateralAssetsDataResponse>>;
62    async fn get_flexible_loan_interest_rate_history(
63        &self,
64        params: GetFlexibleLoanInterestRateHistoryParams,
65    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanInterestRateHistoryResponse>>;
66    async fn get_flexible_loan_liquidation_history(
67        &self,
68        params: GetFlexibleLoanLiquidationHistoryParams,
69    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanLiquidationHistoryResponse>>;
70    async fn get_flexible_loan_ltv_adjustment_history(
71        &self,
72        params: GetFlexibleLoanLtvAdjustmentHistoryParams,
73    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanLtvAdjustmentHistoryResponse>>;
74    async fn get_flexible_loan_ongoing_orders(
75        &self,
76        params: GetFlexibleLoanOngoingOrdersParams,
77    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanOngoingOrdersResponse>>;
78    async fn get_flexible_loan_repayment_history(
79        &self,
80        params: GetFlexibleLoanRepaymentHistoryParams,
81    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanRepaymentHistoryResponse>>;
82}
83
84#[derive(Debug, Clone)]
85pub struct FlexibleRateApiClient {
86    configuration: ConfigurationRestApi,
87}
88
89impl FlexibleRateApiClient {
90    pub fn new(configuration: ConfigurationRestApi) -> Self {
91        Self { configuration }
92    }
93}
94
95/// Request parameters for the [`check_collateral_repay_rate`] operation.
96///
97/// This struct holds all of the inputs you can pass when calling
98/// [`check_collateral_repay_rate`](#method.check_collateral_repay_rate).
99#[derive(Clone, Debug, Builder)]
100#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
101pub struct CheckCollateralRepayRateParams {
102    ///
103    /// The `loan_coin` parameter.
104    ///
105    /// This field is **required.
106    #[builder(setter(into))]
107    pub loan_coin: String,
108    ///
109    /// The `collateral_coin` parameter.
110    ///
111    /// This field is **required.
112    #[builder(setter(into))]
113    pub collateral_coin: String,
114    ///
115    /// The `recv_window` parameter.
116    ///
117    /// This field is **optional.
118    #[builder(setter(into), default)]
119    pub recv_window: Option<i64>,
120}
121
122impl CheckCollateralRepayRateParams {
123    /// Create a builder for [`check_collateral_repay_rate`].
124    ///
125    /// Required parameters:
126    ///
127    /// * `loan_coin` — String
128    /// * `collateral_coin` — String
129    ///
130    #[must_use]
131    pub fn builder(
132        loan_coin: String,
133        collateral_coin: String,
134    ) -> CheckCollateralRepayRateParamsBuilder {
135        CheckCollateralRepayRateParamsBuilder::default()
136            .loan_coin(loan_coin)
137            .collateral_coin(collateral_coin)
138    }
139}
140/// Request parameters for the [`flexible_loan_adjust_ltv`] operation.
141///
142/// This struct holds all of the inputs you can pass when calling
143/// [`flexible_loan_adjust_ltv`](#method.flexible_loan_adjust_ltv).
144#[derive(Clone, Debug, Builder)]
145#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
146pub struct FlexibleLoanAdjustLtvParams {
147    ///
148    /// The `loan_coin` parameter.
149    ///
150    /// This field is **required.
151    #[builder(setter(into))]
152    pub loan_coin: String,
153    ///
154    /// The `collateral_coin` parameter.
155    ///
156    /// This field is **required.
157    #[builder(setter(into))]
158    pub collateral_coin: String,
159    ///
160    /// The `adjustment_amount` parameter.
161    ///
162    /// This field is **required.
163    #[builder(setter(into))]
164    pub adjustment_amount: rust_decimal::Decimal,
165    /// "ADDITIONAL", "REDUCED"
166    ///
167    /// This field is **required.
168    #[builder(setter(into))]
169    pub direction: String,
170    ///
171    /// The `recv_window` parameter.
172    ///
173    /// This field is **optional.
174    #[builder(setter(into), default)]
175    pub recv_window: Option<i64>,
176}
177
178impl FlexibleLoanAdjustLtvParams {
179    /// Create a builder for [`flexible_loan_adjust_ltv`].
180    ///
181    /// Required parameters:
182    ///
183    /// * `loan_coin` — String
184    /// * `collateral_coin` — String
185    /// * `adjustment_amount` — `rust_decimal::Decimal`
186    /// * `direction` — \"ADDITIONAL\", \"REDUCED\"
187    ///
188    #[must_use]
189    pub fn builder(
190        loan_coin: String,
191        collateral_coin: String,
192        adjustment_amount: rust_decimal::Decimal,
193        direction: String,
194    ) -> FlexibleLoanAdjustLtvParamsBuilder {
195        FlexibleLoanAdjustLtvParamsBuilder::default()
196            .loan_coin(loan_coin)
197            .collateral_coin(collateral_coin)
198            .adjustment_amount(adjustment_amount)
199            .direction(direction)
200    }
201}
202/// Request parameters for the [`flexible_loan_borrow`] operation.
203///
204/// This struct holds all of the inputs you can pass when calling
205/// [`flexible_loan_borrow`](#method.flexible_loan_borrow).
206#[derive(Clone, Debug, Builder)]
207#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
208pub struct FlexibleLoanBorrowParams {
209    ///
210    /// The `loan_coin` parameter.
211    ///
212    /// This field is **required.
213    #[builder(setter(into))]
214    pub loan_coin: String,
215    ///
216    /// The `collateral_coin` parameter.
217    ///
218    /// This field is **required.
219    #[builder(setter(into))]
220    pub collateral_coin: String,
221    /// Mandatory when collateralAmount is empty
222    ///
223    /// This field is **optional.
224    #[builder(setter(into), default)]
225    pub loan_amount: Option<rust_decimal::Decimal>,
226    /// Mandatory when loanAmount is empty
227    ///
228    /// This field is **optional.
229    #[builder(setter(into), default)]
230    pub collateral_amount: Option<rust_decimal::Decimal>,
231    ///
232    /// The `recv_window` parameter.
233    ///
234    /// This field is **optional.
235    #[builder(setter(into), default)]
236    pub recv_window: Option<i64>,
237}
238
239impl FlexibleLoanBorrowParams {
240    /// Create a builder for [`flexible_loan_borrow`].
241    ///
242    /// Required parameters:
243    ///
244    /// * `loan_coin` — String
245    /// * `collateral_coin` — String
246    ///
247    #[must_use]
248    pub fn builder(loan_coin: String, collateral_coin: String) -> FlexibleLoanBorrowParamsBuilder {
249        FlexibleLoanBorrowParamsBuilder::default()
250            .loan_coin(loan_coin)
251            .collateral_coin(collateral_coin)
252    }
253}
254/// Request parameters for the [`flexible_loan_repay`] operation.
255///
256/// This struct holds all of the inputs you can pass when calling
257/// [`flexible_loan_repay`](#method.flexible_loan_repay).
258#[derive(Clone, Debug, Builder)]
259#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
260pub struct FlexibleLoanRepayParams {
261    ///
262    /// The `loan_coin` parameter.
263    ///
264    /// This field is **required.
265    #[builder(setter(into))]
266    pub loan_coin: String,
267    ///
268    /// The `collateral_coin` parameter.
269    ///
270    /// This field is **required.
271    #[builder(setter(into))]
272    pub collateral_coin: String,
273    /// repay amount of loanCoin
274    ///
275    /// This field is **required.
276    #[builder(setter(into))]
277    pub repay_amount: rust_decimal::Decimal,
278    /// Default: TRUE. TRUE: Return extra collateral to spot account; FALSE: Keep extra collateral in the order, and lower LTV.
279    ///
280    /// This field is **optional.
281    #[builder(setter(into), default)]
282    pub collateral_return: Option<bool>,
283    /// Default: FALSE. TRUE: Full repayment; FALSE: Partial repayment, based on loanAmount
284    ///
285    /// This field is **optional.
286    #[builder(setter(into), default)]
287    pub full_repayment: Option<bool>,
288    /// Default: 1. 1: Repayment with loan asset; 2: Repayment with collateral
289    ///
290    /// This field is **optional.
291    #[builder(setter(into), default)]
292    pub repayment_type: Option<i64>,
293    ///
294    /// The `recv_window` parameter.
295    ///
296    /// This field is **optional.
297    #[builder(setter(into), default)]
298    pub recv_window: Option<i64>,
299}
300
301impl FlexibleLoanRepayParams {
302    /// Create a builder for [`flexible_loan_repay`].
303    ///
304    /// Required parameters:
305    ///
306    /// * `loan_coin` — String
307    /// * `collateral_coin` — String
308    /// * `repay_amount` — repay amount of loanCoin
309    ///
310    #[must_use]
311    pub fn builder(
312        loan_coin: String,
313        collateral_coin: String,
314        repay_amount: rust_decimal::Decimal,
315    ) -> FlexibleLoanRepayParamsBuilder {
316        FlexibleLoanRepayParamsBuilder::default()
317            .loan_coin(loan_coin)
318            .collateral_coin(collateral_coin)
319            .repay_amount(repay_amount)
320    }
321}
322/// Request parameters for the [`get_flexible_loan_assets_data`] operation.
323///
324/// This struct holds all of the inputs you can pass when calling
325/// [`get_flexible_loan_assets_data`](#method.get_flexible_loan_assets_data).
326#[derive(Clone, Debug, Builder, Default)]
327#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
328pub struct GetFlexibleLoanAssetsDataParams {
329    ///
330    /// The `loan_coin` parameter.
331    ///
332    /// This field is **optional.
333    #[builder(setter(into), default)]
334    pub loan_coin: Option<String>,
335    ///
336    /// The `recv_window` parameter.
337    ///
338    /// This field is **optional.
339    #[builder(setter(into), default)]
340    pub recv_window: Option<i64>,
341}
342
343impl GetFlexibleLoanAssetsDataParams {
344    /// Create a builder for [`get_flexible_loan_assets_data`].
345    ///
346    #[must_use]
347    pub fn builder() -> GetFlexibleLoanAssetsDataParamsBuilder {
348        GetFlexibleLoanAssetsDataParamsBuilder::default()
349    }
350}
351/// Request parameters for the [`get_flexible_loan_borrow_history`] operation.
352///
353/// This struct holds all of the inputs you can pass when calling
354/// [`get_flexible_loan_borrow_history`](#method.get_flexible_loan_borrow_history).
355#[derive(Clone, Debug, Builder, Default)]
356#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
357pub struct GetFlexibleLoanBorrowHistoryParams {
358    ///
359    /// The `loan_coin` parameter.
360    ///
361    /// This field is **optional.
362    #[builder(setter(into), default)]
363    pub loan_coin: Option<String>,
364    ///
365    /// The `collateral_coin` parameter.
366    ///
367    /// This field is **optional.
368    #[builder(setter(into), default)]
369    pub collateral_coin: Option<String>,
370    ///
371    /// The `start_time` parameter.
372    ///
373    /// This field is **optional.
374    #[builder(setter(into), default)]
375    pub start_time: Option<i64>,
376    ///
377    /// The `end_time` parameter.
378    ///
379    /// This field is **optional.
380    #[builder(setter(into), default)]
381    pub end_time: Option<i64>,
382    /// Current querying page. Start from 1; default: 1; max: 1000
383    ///
384    /// This field is **optional.
385    #[builder(setter(into), default)]
386    pub current: Option<i64>,
387    /// Default: 10; max: 100
388    ///
389    /// This field is **optional.
390    #[builder(setter(into), default)]
391    pub limit: Option<i64>,
392    ///
393    /// The `recv_window` parameter.
394    ///
395    /// This field is **optional.
396    #[builder(setter(into), default)]
397    pub recv_window: Option<i64>,
398}
399
400impl GetFlexibleLoanBorrowHistoryParams {
401    /// Create a builder for [`get_flexible_loan_borrow_history`].
402    ///
403    #[must_use]
404    pub fn builder() -> GetFlexibleLoanBorrowHistoryParamsBuilder {
405        GetFlexibleLoanBorrowHistoryParamsBuilder::default()
406    }
407}
408/// Request parameters for the [`get_flexible_loan_collateral_assets_data`] operation.
409///
410/// This struct holds all of the inputs you can pass when calling
411/// [`get_flexible_loan_collateral_assets_data`](#method.get_flexible_loan_collateral_assets_data).
412#[derive(Clone, Debug, Builder, Default)]
413#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
414pub struct GetFlexibleLoanCollateralAssetsDataParams {
415    ///
416    /// The `collateral_coin` parameter.
417    ///
418    /// This field is **optional.
419    #[builder(setter(into), default)]
420    pub collateral_coin: Option<String>,
421    ///
422    /// The `recv_window` parameter.
423    ///
424    /// This field is **optional.
425    #[builder(setter(into), default)]
426    pub recv_window: Option<i64>,
427}
428
429impl GetFlexibleLoanCollateralAssetsDataParams {
430    /// Create a builder for [`get_flexible_loan_collateral_assets_data`].
431    ///
432    #[must_use]
433    pub fn builder() -> GetFlexibleLoanCollateralAssetsDataParamsBuilder {
434        GetFlexibleLoanCollateralAssetsDataParamsBuilder::default()
435    }
436}
437/// Request parameters for the [`get_flexible_loan_interest_rate_history`] operation.
438///
439/// This struct holds all of the inputs you can pass when calling
440/// [`get_flexible_loan_interest_rate_history`](#method.get_flexible_loan_interest_rate_history).
441#[derive(Clone, Debug, Builder)]
442#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
443pub struct GetFlexibleLoanInterestRateHistoryParams {
444    ///
445    /// The `coin` parameter.
446    ///
447    /// This field is **required.
448    #[builder(setter(into))]
449    pub coin: String,
450    ///
451    /// The `recv_window` parameter.
452    ///
453    /// This field is **required.
454    #[builder(setter(into))]
455    pub recv_window: i64,
456    ///
457    /// The `start_time` parameter.
458    ///
459    /// This field is **optional.
460    #[builder(setter(into), default)]
461    pub start_time: Option<i64>,
462    ///
463    /// The `end_time` parameter.
464    ///
465    /// This field is **optional.
466    #[builder(setter(into), default)]
467    pub end_time: Option<i64>,
468    /// Current querying page. Start from 1; default: 1; max: 1000
469    ///
470    /// This field is **optional.
471    #[builder(setter(into), default)]
472    pub current: Option<i64>,
473    /// Default: 10; max: 100
474    ///
475    /// This field is **optional.
476    #[builder(setter(into), default)]
477    pub limit: Option<i64>,
478}
479
480impl GetFlexibleLoanInterestRateHistoryParams {
481    /// Create a builder for [`get_flexible_loan_interest_rate_history`].
482    ///
483    /// Required parameters:
484    ///
485    /// * `coin` — String
486    /// * `recv_window` — i64
487    ///
488    #[must_use]
489    pub fn builder(
490        coin: String,
491        recv_window: i64,
492    ) -> GetFlexibleLoanInterestRateHistoryParamsBuilder {
493        GetFlexibleLoanInterestRateHistoryParamsBuilder::default()
494            .coin(coin)
495            .recv_window(recv_window)
496    }
497}
498/// Request parameters for the [`get_flexible_loan_liquidation_history`] operation.
499///
500/// This struct holds all of the inputs you can pass when calling
501/// [`get_flexible_loan_liquidation_history`](#method.get_flexible_loan_liquidation_history).
502#[derive(Clone, Debug, Builder, Default)]
503#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
504pub struct GetFlexibleLoanLiquidationHistoryParams {
505    ///
506    /// The `loan_coin` parameter.
507    ///
508    /// This field is **optional.
509    #[builder(setter(into), default)]
510    pub loan_coin: Option<String>,
511    ///
512    /// The `collateral_coin` parameter.
513    ///
514    /// This field is **optional.
515    #[builder(setter(into), default)]
516    pub collateral_coin: Option<String>,
517    ///
518    /// The `start_time` parameter.
519    ///
520    /// This field is **optional.
521    #[builder(setter(into), default)]
522    pub start_time: Option<i64>,
523    ///
524    /// The `end_time` parameter.
525    ///
526    /// This field is **optional.
527    #[builder(setter(into), default)]
528    pub end_time: Option<i64>,
529    /// Current querying page. Start from 1; default: 1; max: 1000
530    ///
531    /// This field is **optional.
532    #[builder(setter(into), default)]
533    pub current: Option<i64>,
534    /// Default: 10; max: 100
535    ///
536    /// This field is **optional.
537    #[builder(setter(into), default)]
538    pub limit: Option<i64>,
539    ///
540    /// The `recv_window` parameter.
541    ///
542    /// This field is **optional.
543    #[builder(setter(into), default)]
544    pub recv_window: Option<i64>,
545}
546
547impl GetFlexibleLoanLiquidationHistoryParams {
548    /// Create a builder for [`get_flexible_loan_liquidation_history`].
549    ///
550    #[must_use]
551    pub fn builder() -> GetFlexibleLoanLiquidationHistoryParamsBuilder {
552        GetFlexibleLoanLiquidationHistoryParamsBuilder::default()
553    }
554}
555/// Request parameters for the [`get_flexible_loan_ltv_adjustment_history`] operation.
556///
557/// This struct holds all of the inputs you can pass when calling
558/// [`get_flexible_loan_ltv_adjustment_history`](#method.get_flexible_loan_ltv_adjustment_history).
559#[derive(Clone, Debug, Builder, Default)]
560#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
561pub struct GetFlexibleLoanLtvAdjustmentHistoryParams {
562    ///
563    /// The `loan_coin` parameter.
564    ///
565    /// This field is **optional.
566    #[builder(setter(into), default)]
567    pub loan_coin: Option<String>,
568    ///
569    /// The `collateral_coin` parameter.
570    ///
571    /// This field is **optional.
572    #[builder(setter(into), default)]
573    pub collateral_coin: Option<String>,
574    ///
575    /// The `start_time` parameter.
576    ///
577    /// This field is **optional.
578    #[builder(setter(into), default)]
579    pub start_time: Option<i64>,
580    ///
581    /// The `end_time` parameter.
582    ///
583    /// This field is **optional.
584    #[builder(setter(into), default)]
585    pub end_time: Option<i64>,
586    /// Current querying page. Start from 1; default: 1; max: 1000
587    ///
588    /// This field is **optional.
589    #[builder(setter(into), default)]
590    pub current: Option<i64>,
591    /// Default: 10; max: 100
592    ///
593    /// This field is **optional.
594    #[builder(setter(into), default)]
595    pub limit: Option<i64>,
596    ///
597    /// The `recv_window` parameter.
598    ///
599    /// This field is **optional.
600    #[builder(setter(into), default)]
601    pub recv_window: Option<i64>,
602}
603
604impl GetFlexibleLoanLtvAdjustmentHistoryParams {
605    /// Create a builder for [`get_flexible_loan_ltv_adjustment_history`].
606    ///
607    #[must_use]
608    pub fn builder() -> GetFlexibleLoanLtvAdjustmentHistoryParamsBuilder {
609        GetFlexibleLoanLtvAdjustmentHistoryParamsBuilder::default()
610    }
611}
612/// Request parameters for the [`get_flexible_loan_ongoing_orders`] operation.
613///
614/// This struct holds all of the inputs you can pass when calling
615/// [`get_flexible_loan_ongoing_orders`](#method.get_flexible_loan_ongoing_orders).
616#[derive(Clone, Debug, Builder, Default)]
617#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
618pub struct GetFlexibleLoanOngoingOrdersParams {
619    ///
620    /// The `loan_coin` parameter.
621    ///
622    /// This field is **optional.
623    #[builder(setter(into), default)]
624    pub loan_coin: Option<String>,
625    ///
626    /// The `collateral_coin` parameter.
627    ///
628    /// This field is **optional.
629    #[builder(setter(into), default)]
630    pub collateral_coin: Option<String>,
631    /// Current querying page. Start from 1; default: 1; max: 1000
632    ///
633    /// This field is **optional.
634    #[builder(setter(into), default)]
635    pub current: Option<i64>,
636    /// Default: 10; max: 100
637    ///
638    /// This field is **optional.
639    #[builder(setter(into), default)]
640    pub limit: Option<i64>,
641    ///
642    /// The `recv_window` parameter.
643    ///
644    /// This field is **optional.
645    #[builder(setter(into), default)]
646    pub recv_window: Option<i64>,
647}
648
649impl GetFlexibleLoanOngoingOrdersParams {
650    /// Create a builder for [`get_flexible_loan_ongoing_orders`].
651    ///
652    #[must_use]
653    pub fn builder() -> GetFlexibleLoanOngoingOrdersParamsBuilder {
654        GetFlexibleLoanOngoingOrdersParamsBuilder::default()
655    }
656}
657/// Request parameters for the [`get_flexible_loan_repayment_history`] operation.
658///
659/// This struct holds all of the inputs you can pass when calling
660/// [`get_flexible_loan_repayment_history`](#method.get_flexible_loan_repayment_history).
661#[derive(Clone, Debug, Builder, Default)]
662#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
663pub struct GetFlexibleLoanRepaymentHistoryParams {
664    ///
665    /// The `loan_coin` parameter.
666    ///
667    /// This field is **optional.
668    #[builder(setter(into), default)]
669    pub loan_coin: Option<String>,
670    ///
671    /// The `collateral_coin` parameter.
672    ///
673    /// This field is **optional.
674    #[builder(setter(into), default)]
675    pub collateral_coin: Option<String>,
676    ///
677    /// The `start_time` parameter.
678    ///
679    /// This field is **optional.
680    #[builder(setter(into), default)]
681    pub start_time: Option<i64>,
682    ///
683    /// The `end_time` parameter.
684    ///
685    /// This field is **optional.
686    #[builder(setter(into), default)]
687    pub end_time: Option<i64>,
688    /// Current querying page. Start from 1; default: 1; max: 1000
689    ///
690    /// This field is **optional.
691    #[builder(setter(into), default)]
692    pub current: Option<i64>,
693    /// Default: 10; max: 100
694    ///
695    /// This field is **optional.
696    #[builder(setter(into), default)]
697    pub limit: Option<i64>,
698    ///
699    /// The `recv_window` parameter.
700    ///
701    /// This field is **optional.
702    #[builder(setter(into), default)]
703    pub recv_window: Option<i64>,
704}
705
706impl GetFlexibleLoanRepaymentHistoryParams {
707    /// Create a builder for [`get_flexible_loan_repayment_history`].
708    ///
709    #[must_use]
710    pub fn builder() -> GetFlexibleLoanRepaymentHistoryParamsBuilder {
711        GetFlexibleLoanRepaymentHistoryParamsBuilder::default()
712    }
713}
714
715#[async_trait]
716impl FlexibleRateApi for FlexibleRateApiClient {
717    async fn check_collateral_repay_rate(
718        &self,
719        params: CheckCollateralRepayRateParams,
720    ) -> anyhow::Result<RestApiResponse<models::CheckCollateralRepayRateResponse>> {
721        let CheckCollateralRepayRateParams {
722            loan_coin,
723            collateral_coin,
724            recv_window,
725        } = params;
726
727        let mut query_params = BTreeMap::new();
728        let body_params = BTreeMap::new();
729
730        query_params.insert("loanCoin".to_string(), json!(loan_coin));
731
732        query_params.insert("collateralCoin".to_string(), json!(collateral_coin));
733
734        if let Some(rw) = recv_window {
735            query_params.insert("recvWindow".to_string(), json!(rw));
736        }
737
738        send_request::<models::CheckCollateralRepayRateResponse>(
739            &self.configuration,
740            "/sapi/v2/loan/flexible/repay/rate",
741            reqwest::Method::GET,
742            query_params,
743            body_params,
744            if HAS_TIME_UNIT {
745                self.configuration.time_unit
746            } else {
747                None
748            },
749            true,
750        )
751        .await
752    }
753
754    async fn flexible_loan_adjust_ltv(
755        &self,
756        params: FlexibleLoanAdjustLtvParams,
757    ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanAdjustLtvResponse>> {
758        let FlexibleLoanAdjustLtvParams {
759            loan_coin,
760            collateral_coin,
761            adjustment_amount,
762            direction,
763            recv_window,
764        } = params;
765
766        let mut query_params = BTreeMap::new();
767        let body_params = BTreeMap::new();
768
769        query_params.insert("loanCoin".to_string(), json!(loan_coin));
770
771        query_params.insert("collateralCoin".to_string(), json!(collateral_coin));
772
773        query_params.insert("adjustmentAmount".to_string(), json!(adjustment_amount));
774
775        query_params.insert("direction".to_string(), json!(direction));
776
777        if let Some(rw) = recv_window {
778            query_params.insert("recvWindow".to_string(), json!(rw));
779        }
780
781        send_request::<models::FlexibleLoanAdjustLtvResponse>(
782            &self.configuration,
783            "/sapi/v2/loan/flexible/adjust/ltv",
784            reqwest::Method::POST,
785            query_params,
786            body_params,
787            if HAS_TIME_UNIT {
788                self.configuration.time_unit
789            } else {
790                None
791            },
792            true,
793        )
794        .await
795    }
796
797    async fn flexible_loan_borrow(
798        &self,
799        params: FlexibleLoanBorrowParams,
800    ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanBorrowResponse>> {
801        let FlexibleLoanBorrowParams {
802            loan_coin,
803            collateral_coin,
804            loan_amount,
805            collateral_amount,
806            recv_window,
807        } = params;
808
809        let mut query_params = BTreeMap::new();
810        let body_params = BTreeMap::new();
811
812        query_params.insert("loanCoin".to_string(), json!(loan_coin));
813
814        if let Some(rw) = loan_amount {
815            query_params.insert("loanAmount".to_string(), json!(rw));
816        }
817
818        query_params.insert("collateralCoin".to_string(), json!(collateral_coin));
819
820        if let Some(rw) = collateral_amount {
821            query_params.insert("collateralAmount".to_string(), json!(rw));
822        }
823
824        if let Some(rw) = recv_window {
825            query_params.insert("recvWindow".to_string(), json!(rw));
826        }
827
828        send_request::<models::FlexibleLoanBorrowResponse>(
829            &self.configuration,
830            "/sapi/v2/loan/flexible/borrow",
831            reqwest::Method::POST,
832            query_params,
833            body_params,
834            if HAS_TIME_UNIT {
835                self.configuration.time_unit
836            } else {
837                None
838            },
839            true,
840        )
841        .await
842    }
843
844    async fn flexible_loan_repay(
845        &self,
846        params: FlexibleLoanRepayParams,
847    ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanRepayResponse>> {
848        let FlexibleLoanRepayParams {
849            loan_coin,
850            collateral_coin,
851            repay_amount,
852            collateral_return,
853            full_repayment,
854            repayment_type,
855            recv_window,
856        } = params;
857
858        let mut query_params = BTreeMap::new();
859        let body_params = BTreeMap::new();
860
861        query_params.insert("loanCoin".to_string(), json!(loan_coin));
862
863        query_params.insert("collateralCoin".to_string(), json!(collateral_coin));
864
865        query_params.insert("repayAmount".to_string(), json!(repay_amount));
866
867        if let Some(rw) = collateral_return {
868            query_params.insert("collateralReturn".to_string(), json!(rw));
869        }
870
871        if let Some(rw) = full_repayment {
872            query_params.insert("fullRepayment".to_string(), json!(rw));
873        }
874
875        if let Some(rw) = repayment_type {
876            query_params.insert("repaymentType".to_string(), json!(rw));
877        }
878
879        if let Some(rw) = recv_window {
880            query_params.insert("recvWindow".to_string(), json!(rw));
881        }
882
883        send_request::<models::FlexibleLoanRepayResponse>(
884            &self.configuration,
885            "/sapi/v2/loan/flexible/repay",
886            reqwest::Method::POST,
887            query_params,
888            body_params,
889            if HAS_TIME_UNIT {
890                self.configuration.time_unit
891            } else {
892                None
893            },
894            true,
895        )
896        .await
897    }
898
899    async fn get_flexible_loan_assets_data(
900        &self,
901        params: GetFlexibleLoanAssetsDataParams,
902    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanAssetsDataResponse>> {
903        let GetFlexibleLoanAssetsDataParams {
904            loan_coin,
905            recv_window,
906        } = params;
907
908        let mut query_params = BTreeMap::new();
909        let body_params = BTreeMap::new();
910
911        if let Some(rw) = loan_coin {
912            query_params.insert("loanCoin".to_string(), json!(rw));
913        }
914
915        if let Some(rw) = recv_window {
916            query_params.insert("recvWindow".to_string(), json!(rw));
917        }
918
919        send_request::<models::GetFlexibleLoanAssetsDataResponse>(
920            &self.configuration,
921            "/sapi/v2/loan/flexible/loanable/data",
922            reqwest::Method::GET,
923            query_params,
924            body_params,
925            if HAS_TIME_UNIT {
926                self.configuration.time_unit
927            } else {
928                None
929            },
930            true,
931        )
932        .await
933    }
934
935    async fn get_flexible_loan_borrow_history(
936        &self,
937        params: GetFlexibleLoanBorrowHistoryParams,
938    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanBorrowHistoryResponse>> {
939        let GetFlexibleLoanBorrowHistoryParams {
940            loan_coin,
941            collateral_coin,
942            start_time,
943            end_time,
944            current,
945            limit,
946            recv_window,
947        } = params;
948
949        let mut query_params = BTreeMap::new();
950        let body_params = BTreeMap::new();
951
952        if let Some(rw) = loan_coin {
953            query_params.insert("loanCoin".to_string(), json!(rw));
954        }
955
956        if let Some(rw) = collateral_coin {
957            query_params.insert("collateralCoin".to_string(), json!(rw));
958        }
959
960        if let Some(rw) = start_time {
961            query_params.insert("startTime".to_string(), json!(rw));
962        }
963
964        if let Some(rw) = end_time {
965            query_params.insert("endTime".to_string(), json!(rw));
966        }
967
968        if let Some(rw) = current {
969            query_params.insert("current".to_string(), json!(rw));
970        }
971
972        if let Some(rw) = limit {
973            query_params.insert("limit".to_string(), json!(rw));
974        }
975
976        if let Some(rw) = recv_window {
977            query_params.insert("recvWindow".to_string(), json!(rw));
978        }
979
980        send_request::<models::GetFlexibleLoanBorrowHistoryResponse>(
981            &self.configuration,
982            "/sapi/v2/loan/flexible/borrow/history",
983            reqwest::Method::GET,
984            query_params,
985            body_params,
986            if HAS_TIME_UNIT {
987                self.configuration.time_unit
988            } else {
989                None
990            },
991            true,
992        )
993        .await
994    }
995
996    async fn get_flexible_loan_collateral_assets_data(
997        &self,
998        params: GetFlexibleLoanCollateralAssetsDataParams,
999    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanCollateralAssetsDataResponse>> {
1000        let GetFlexibleLoanCollateralAssetsDataParams {
1001            collateral_coin,
1002            recv_window,
1003        } = params;
1004
1005        let mut query_params = BTreeMap::new();
1006        let body_params = BTreeMap::new();
1007
1008        if let Some(rw) = collateral_coin {
1009            query_params.insert("collateralCoin".to_string(), json!(rw));
1010        }
1011
1012        if let Some(rw) = recv_window {
1013            query_params.insert("recvWindow".to_string(), json!(rw));
1014        }
1015
1016        send_request::<models::GetFlexibleLoanCollateralAssetsDataResponse>(
1017            &self.configuration,
1018            "/sapi/v2/loan/flexible/collateral/data",
1019            reqwest::Method::GET,
1020            query_params,
1021            body_params,
1022            if HAS_TIME_UNIT {
1023                self.configuration.time_unit
1024            } else {
1025                None
1026            },
1027            true,
1028        )
1029        .await
1030    }
1031
1032    async fn get_flexible_loan_interest_rate_history(
1033        &self,
1034        params: GetFlexibleLoanInterestRateHistoryParams,
1035    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanInterestRateHistoryResponse>> {
1036        let GetFlexibleLoanInterestRateHistoryParams {
1037            coin,
1038            recv_window,
1039            start_time,
1040            end_time,
1041            current,
1042            limit,
1043        } = params;
1044
1045        let mut query_params = BTreeMap::new();
1046        let body_params = BTreeMap::new();
1047
1048        query_params.insert("coin".to_string(), json!(coin));
1049
1050        if let Some(rw) = start_time {
1051            query_params.insert("startTime".to_string(), json!(rw));
1052        }
1053
1054        if let Some(rw) = end_time {
1055            query_params.insert("endTime".to_string(), json!(rw));
1056        }
1057
1058        if let Some(rw) = current {
1059            query_params.insert("current".to_string(), json!(rw));
1060        }
1061
1062        if let Some(rw) = limit {
1063            query_params.insert("limit".to_string(), json!(rw));
1064        }
1065
1066        query_params.insert("recvWindow".to_string(), json!(recv_window));
1067
1068        send_request::<models::GetFlexibleLoanInterestRateHistoryResponse>(
1069            &self.configuration,
1070            "/sapi/v2/loan/interestRateHistory",
1071            reqwest::Method::GET,
1072            query_params,
1073            body_params,
1074            if HAS_TIME_UNIT {
1075                self.configuration.time_unit
1076            } else {
1077                None
1078            },
1079            true,
1080        )
1081        .await
1082    }
1083
1084    async fn get_flexible_loan_liquidation_history(
1085        &self,
1086        params: GetFlexibleLoanLiquidationHistoryParams,
1087    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanLiquidationHistoryResponse>> {
1088        let GetFlexibleLoanLiquidationHistoryParams {
1089            loan_coin,
1090            collateral_coin,
1091            start_time,
1092            end_time,
1093            current,
1094            limit,
1095            recv_window,
1096        } = params;
1097
1098        let mut query_params = BTreeMap::new();
1099        let body_params = BTreeMap::new();
1100
1101        if let Some(rw) = loan_coin {
1102            query_params.insert("loanCoin".to_string(), json!(rw));
1103        }
1104
1105        if let Some(rw) = collateral_coin {
1106            query_params.insert("collateralCoin".to_string(), json!(rw));
1107        }
1108
1109        if let Some(rw) = start_time {
1110            query_params.insert("startTime".to_string(), json!(rw));
1111        }
1112
1113        if let Some(rw) = end_time {
1114            query_params.insert("endTime".to_string(), json!(rw));
1115        }
1116
1117        if let Some(rw) = current {
1118            query_params.insert("current".to_string(), json!(rw));
1119        }
1120
1121        if let Some(rw) = limit {
1122            query_params.insert("limit".to_string(), json!(rw));
1123        }
1124
1125        if let Some(rw) = recv_window {
1126            query_params.insert("recvWindow".to_string(), json!(rw));
1127        }
1128
1129        send_request::<models::GetFlexibleLoanLiquidationHistoryResponse>(
1130            &self.configuration,
1131            "/sapi/v2/loan/flexible/liquidation/history",
1132            reqwest::Method::GET,
1133            query_params,
1134            body_params,
1135            if HAS_TIME_UNIT {
1136                self.configuration.time_unit
1137            } else {
1138                None
1139            },
1140            true,
1141        )
1142        .await
1143    }
1144
1145    async fn get_flexible_loan_ltv_adjustment_history(
1146        &self,
1147        params: GetFlexibleLoanLtvAdjustmentHistoryParams,
1148    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanLtvAdjustmentHistoryResponse>> {
1149        let GetFlexibleLoanLtvAdjustmentHistoryParams {
1150            loan_coin,
1151            collateral_coin,
1152            start_time,
1153            end_time,
1154            current,
1155            limit,
1156            recv_window,
1157        } = params;
1158
1159        let mut query_params = BTreeMap::new();
1160        let body_params = BTreeMap::new();
1161
1162        if let Some(rw) = loan_coin {
1163            query_params.insert("loanCoin".to_string(), json!(rw));
1164        }
1165
1166        if let Some(rw) = collateral_coin {
1167            query_params.insert("collateralCoin".to_string(), json!(rw));
1168        }
1169
1170        if let Some(rw) = start_time {
1171            query_params.insert("startTime".to_string(), json!(rw));
1172        }
1173
1174        if let Some(rw) = end_time {
1175            query_params.insert("endTime".to_string(), json!(rw));
1176        }
1177
1178        if let Some(rw) = current {
1179            query_params.insert("current".to_string(), json!(rw));
1180        }
1181
1182        if let Some(rw) = limit {
1183            query_params.insert("limit".to_string(), json!(rw));
1184        }
1185
1186        if let Some(rw) = recv_window {
1187            query_params.insert("recvWindow".to_string(), json!(rw));
1188        }
1189
1190        send_request::<models::GetFlexibleLoanLtvAdjustmentHistoryResponse>(
1191            &self.configuration,
1192            "/sapi/v2/loan/flexible/ltv/adjustment/history",
1193            reqwest::Method::GET,
1194            query_params,
1195            body_params,
1196            if HAS_TIME_UNIT {
1197                self.configuration.time_unit
1198            } else {
1199                None
1200            },
1201            true,
1202        )
1203        .await
1204    }
1205
1206    async fn get_flexible_loan_ongoing_orders(
1207        &self,
1208        params: GetFlexibleLoanOngoingOrdersParams,
1209    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanOngoingOrdersResponse>> {
1210        let GetFlexibleLoanOngoingOrdersParams {
1211            loan_coin,
1212            collateral_coin,
1213            current,
1214            limit,
1215            recv_window,
1216        } = params;
1217
1218        let mut query_params = BTreeMap::new();
1219        let body_params = BTreeMap::new();
1220
1221        if let Some(rw) = loan_coin {
1222            query_params.insert("loanCoin".to_string(), json!(rw));
1223        }
1224
1225        if let Some(rw) = collateral_coin {
1226            query_params.insert("collateralCoin".to_string(), json!(rw));
1227        }
1228
1229        if let Some(rw) = current {
1230            query_params.insert("current".to_string(), json!(rw));
1231        }
1232
1233        if let Some(rw) = limit {
1234            query_params.insert("limit".to_string(), json!(rw));
1235        }
1236
1237        if let Some(rw) = recv_window {
1238            query_params.insert("recvWindow".to_string(), json!(rw));
1239        }
1240
1241        send_request::<models::GetFlexibleLoanOngoingOrdersResponse>(
1242            &self.configuration,
1243            "/sapi/v2/loan/flexible/ongoing/orders",
1244            reqwest::Method::GET,
1245            query_params,
1246            body_params,
1247            if HAS_TIME_UNIT {
1248                self.configuration.time_unit
1249            } else {
1250                None
1251            },
1252            true,
1253        )
1254        .await
1255    }
1256
1257    async fn get_flexible_loan_repayment_history(
1258        &self,
1259        params: GetFlexibleLoanRepaymentHistoryParams,
1260    ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanRepaymentHistoryResponse>> {
1261        let GetFlexibleLoanRepaymentHistoryParams {
1262            loan_coin,
1263            collateral_coin,
1264            start_time,
1265            end_time,
1266            current,
1267            limit,
1268            recv_window,
1269        } = params;
1270
1271        let mut query_params = BTreeMap::new();
1272        let body_params = BTreeMap::new();
1273
1274        if let Some(rw) = loan_coin {
1275            query_params.insert("loanCoin".to_string(), json!(rw));
1276        }
1277
1278        if let Some(rw) = collateral_coin {
1279            query_params.insert("collateralCoin".to_string(), json!(rw));
1280        }
1281
1282        if let Some(rw) = start_time {
1283            query_params.insert("startTime".to_string(), json!(rw));
1284        }
1285
1286        if let Some(rw) = end_time {
1287            query_params.insert("endTime".to_string(), json!(rw));
1288        }
1289
1290        if let Some(rw) = current {
1291            query_params.insert("current".to_string(), json!(rw));
1292        }
1293
1294        if let Some(rw) = limit {
1295            query_params.insert("limit".to_string(), json!(rw));
1296        }
1297
1298        if let Some(rw) = recv_window {
1299            query_params.insert("recvWindow".to_string(), json!(rw));
1300        }
1301
1302        send_request::<models::GetFlexibleLoanRepaymentHistoryResponse>(
1303            &self.configuration,
1304            "/sapi/v2/loan/flexible/repay/history",
1305            reqwest::Method::GET,
1306            query_params,
1307            body_params,
1308            if HAS_TIME_UNIT {
1309                self.configuration.time_unit
1310            } else {
1311                None
1312            },
1313            true,
1314        )
1315        .await
1316    }
1317}
1318
1319#[cfg(all(test, feature = "crypto_loan"))]
1320mod tests {
1321    use super::*;
1322    use crate::TOKIO_SHARED_RT;
1323    use crate::{errors::ConnectorError, models::DataFuture, models::RestApiRateLimit};
1324    use async_trait::async_trait;
1325    use std::collections::HashMap;
1326
1327    struct DummyRestApiResponse<T> {
1328        inner: Box<dyn FnOnce() -> DataFuture<Result<T, ConnectorError>> + Send + Sync>,
1329        status: u16,
1330        headers: HashMap<String, String>,
1331        rate_limits: Option<Vec<RestApiRateLimit>>,
1332    }
1333
1334    impl<T> From<DummyRestApiResponse<T>> for RestApiResponse<T> {
1335        fn from(dummy: DummyRestApiResponse<T>) -> Self {
1336            Self {
1337                data_fn: dummy.inner,
1338                status: dummy.status,
1339                headers: dummy.headers,
1340                rate_limits: dummy.rate_limits,
1341            }
1342        }
1343    }
1344
1345    struct MockFlexibleRateApiClient {
1346        force_error: bool,
1347    }
1348
1349    #[async_trait]
1350    impl FlexibleRateApi for MockFlexibleRateApiClient {
1351        async fn check_collateral_repay_rate(
1352            &self,
1353            _params: CheckCollateralRepayRateParams,
1354        ) -> anyhow::Result<RestApiResponse<models::CheckCollateralRepayRateResponse>> {
1355            if self.force_error {
1356                return Err(ConnectorError::ConnectorClientError {
1357                    msg: "ResponseError".to_string(),
1358                    code: None,
1359                }
1360                .into());
1361            }
1362
1363            let resp_json: Value = serde_json::from_str(
1364                r#"{"loanCoin":"BUSD","collateralCoin":"BNB","rate":"300.36781234"}"#,
1365            )
1366            .unwrap();
1367            let dummy_response: models::CheckCollateralRepayRateResponse =
1368                serde_json::from_value(resp_json.clone())
1369                    .expect("should parse into models::CheckCollateralRepayRateResponse");
1370
1371            let dummy = DummyRestApiResponse {
1372                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1373                status: 200,
1374                headers: HashMap::new(),
1375                rate_limits: None,
1376            };
1377
1378            Ok(dummy.into())
1379        }
1380
1381        async fn flexible_loan_adjust_ltv(
1382            &self,
1383            _params: FlexibleLoanAdjustLtvParams,
1384        ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanAdjustLtvResponse>> {
1385            if self.force_error {
1386                return Err(ConnectorError::ConnectorClientError {
1387                    msg: "ResponseError".to_string(),
1388                    code: None,
1389                }
1390                .into());
1391            }
1392
1393            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","collateralCoin":"BNB","direction":"ADDITIONAL","adjustmentAmount":"5.235","currentLTV":"0.52","status":"Succeeds"}"#).unwrap();
1394            let dummy_response: models::FlexibleLoanAdjustLtvResponse =
1395                serde_json::from_value(resp_json.clone())
1396                    .expect("should parse into models::FlexibleLoanAdjustLtvResponse");
1397
1398            let dummy = DummyRestApiResponse {
1399                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1400                status: 200,
1401                headers: HashMap::new(),
1402                rate_limits: None,
1403            };
1404
1405            Ok(dummy.into())
1406        }
1407
1408        async fn flexible_loan_borrow(
1409            &self,
1410            _params: FlexibleLoanBorrowParams,
1411        ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanBorrowResponse>> {
1412            if self.force_error {
1413                return Err(ConnectorError::ConnectorClientError {
1414                    msg: "ResponseError".to_string(),
1415                    code: None,
1416                }
1417                .into());
1418            }
1419
1420            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","loanAmount":"100.5","collateralCoin":"BNB","collateralAmount":"50.5","status":"Succeeds"}"#).unwrap();
1421            let dummy_response: models::FlexibleLoanBorrowResponse =
1422                serde_json::from_value(resp_json.clone())
1423                    .expect("should parse into models::FlexibleLoanBorrowResponse");
1424
1425            let dummy = DummyRestApiResponse {
1426                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1427                status: 200,
1428                headers: HashMap::new(),
1429                rate_limits: None,
1430            };
1431
1432            Ok(dummy.into())
1433        }
1434
1435        async fn flexible_loan_repay(
1436            &self,
1437            _params: FlexibleLoanRepayParams,
1438        ) -> anyhow::Result<RestApiResponse<models::FlexibleLoanRepayResponse>> {
1439            if self.force_error {
1440                return Err(ConnectorError::ConnectorClientError {
1441                    msg: "ResponseError".to_string(),
1442                    code: None,
1443                }
1444                .into());
1445            }
1446
1447            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","collateralCoin":"BNB","remainingDebt":"100.5","remainingCollateral":"5.253","fullRepayment":false,"currentLTV":"0.25","repayStatus":"REPAID"}"#).unwrap();
1448            let dummy_response: models::FlexibleLoanRepayResponse =
1449                serde_json::from_value(resp_json.clone())
1450                    .expect("should parse into models::FlexibleLoanRepayResponse");
1451
1452            let dummy = DummyRestApiResponse {
1453                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1454                status: 200,
1455                headers: HashMap::new(),
1456                rate_limits: None,
1457            };
1458
1459            Ok(dummy.into())
1460        }
1461
1462        async fn get_flexible_loan_assets_data(
1463            &self,
1464            _params: GetFlexibleLoanAssetsDataParams,
1465        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanAssetsDataResponse>> {
1466            if self.force_error {
1467                return Err(ConnectorError::ConnectorClientError {
1468                    msg: "ResponseError".to_string(),
1469                    code: None,
1470                }
1471                .into());
1472            }
1473
1474            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","flexibleInterestRate":"0.00000491","flexibleMinLimit":"100","flexibleMaxLimit":"1000000"}],"total":1}"#).unwrap();
1475            let dummy_response: models::GetFlexibleLoanAssetsDataResponse =
1476                serde_json::from_value(resp_json.clone())
1477                    .expect("should parse into models::GetFlexibleLoanAssetsDataResponse");
1478
1479            let dummy = DummyRestApiResponse {
1480                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1481                status: 200,
1482                headers: HashMap::new(),
1483                rate_limits: None,
1484            };
1485
1486            Ok(dummy.into())
1487        }
1488
1489        async fn get_flexible_loan_borrow_history(
1490            &self,
1491            _params: GetFlexibleLoanBorrowHistoryParams,
1492        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanBorrowHistoryResponse>> {
1493            if self.force_error {
1494                return Err(ConnectorError::ConnectorClientError {
1495                    msg: "ResponseError".to_string(),
1496                    code: None,
1497                }
1498                .into());
1499            }
1500
1501            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","initialLoanAmount":"10000","collateralCoin":"BNB","initialCollateralAmount":"49.27565492","borrowTime":1575018510000,"status":"SUCCESS"}],"total":1}"#).unwrap();
1502            let dummy_response: models::GetFlexibleLoanBorrowHistoryResponse =
1503                serde_json::from_value(resp_json.clone())
1504                    .expect("should parse into models::GetFlexibleLoanBorrowHistoryResponse");
1505
1506            let dummy = DummyRestApiResponse {
1507                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1508                status: 200,
1509                headers: HashMap::new(),
1510                rate_limits: None,
1511            };
1512
1513            Ok(dummy.into())
1514        }
1515
1516        async fn get_flexible_loan_collateral_assets_data(
1517            &self,
1518            _params: GetFlexibleLoanCollateralAssetsDataParams,
1519        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanCollateralAssetsDataResponse>>
1520        {
1521            if self.force_error {
1522                return Err(ConnectorError::ConnectorClientError {
1523                    msg: "ResponseError".to_string(),
1524                    code: None,
1525                }
1526                .into());
1527            }
1528
1529            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"collateralCoin":"BNB","initialLTV":"0.65","marginCallLTV":"0.75","liquidationLTV":"0.83","maxLimit":"1000000"}],"total":1}"#).unwrap();
1530            let dummy_response: models::GetFlexibleLoanCollateralAssetsDataResponse =
1531                serde_json::from_value(resp_json.clone()).expect(
1532                    "should parse into models::GetFlexibleLoanCollateralAssetsDataResponse",
1533                );
1534
1535            let dummy = DummyRestApiResponse {
1536                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1537                status: 200,
1538                headers: HashMap::new(),
1539                rate_limits: None,
1540            };
1541
1542            Ok(dummy.into())
1543        }
1544
1545        async fn get_flexible_loan_interest_rate_history(
1546            &self,
1547            _params: GetFlexibleLoanInterestRateHistoryParams,
1548        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanInterestRateHistoryResponse>>
1549        {
1550            if self.force_error {
1551                return Err(ConnectorError::ConnectorClientError {
1552                    msg: "ResponseError".to_string(),
1553                    code: None,
1554                }
1555                .into());
1556            }
1557
1558            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"coin":"USDT","annualizedInterestRate":"0.0647","time":1575018510000},{"coin":"USDT","annualizedInterestRate":"0.0647","time":1575018510000}],"total":2}"#).unwrap();
1559            let dummy_response: models::GetFlexibleLoanInterestRateHistoryResponse =
1560                serde_json::from_value(resp_json.clone())
1561                    .expect("should parse into models::GetFlexibleLoanInterestRateHistoryResponse");
1562
1563            let dummy = DummyRestApiResponse {
1564                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1565                status: 200,
1566                headers: HashMap::new(),
1567                rate_limits: None,
1568            };
1569
1570            Ok(dummy.into())
1571        }
1572
1573        async fn get_flexible_loan_liquidation_history(
1574            &self,
1575            _params: GetFlexibleLoanLiquidationHistoryParams,
1576        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanLiquidationHistoryResponse>>
1577        {
1578            if self.force_error {
1579                return Err(ConnectorError::ConnectorClientError {
1580                    msg: "ResponseError".to_string(),
1581                    code: None,
1582                }
1583                .into());
1584            }
1585
1586            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","liquidationDebt":"10000","collateralCoin":"BNB","liquidationCollateralAmount":"123","returnCollateralAmount":"0.2","liquidationFee":"1.2","liquidationStartingPrice":"49.27565492","liquidationStartingTime":1575018510000,"status":"Liquidated"}],"total":1}"#).unwrap();
1587            let dummy_response: models::GetFlexibleLoanLiquidationHistoryResponse =
1588                serde_json::from_value(resp_json.clone())
1589                    .expect("should parse into models::GetFlexibleLoanLiquidationHistoryResponse");
1590
1591            let dummy = DummyRestApiResponse {
1592                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1593                status: 200,
1594                headers: HashMap::new(),
1595                rate_limits: None,
1596            };
1597
1598            Ok(dummy.into())
1599        }
1600
1601        async fn get_flexible_loan_ltv_adjustment_history(
1602            &self,
1603            _params: GetFlexibleLoanLtvAdjustmentHistoryParams,
1604        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanLtvAdjustmentHistoryResponse>>
1605        {
1606            if self.force_error {
1607                return Err(ConnectorError::ConnectorClientError {
1608                    msg: "ResponseError".to_string(),
1609                    code: None,
1610                }
1611                .into());
1612            }
1613
1614            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","collateralCoin":"BNB","direction":"ADDITIONAL","collateralAmount":"5.235","preLTV":"0.78","afterLTV":"0.56","adjustTime":1575018510000}],"total":1}"#).unwrap();
1615            let dummy_response: models::GetFlexibleLoanLtvAdjustmentHistoryResponse =
1616                serde_json::from_value(resp_json.clone()).expect(
1617                    "should parse into models::GetFlexibleLoanLtvAdjustmentHistoryResponse",
1618                );
1619
1620            let dummy = DummyRestApiResponse {
1621                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1622                status: 200,
1623                headers: HashMap::new(),
1624                rate_limits: None,
1625            };
1626
1627            Ok(dummy.into())
1628        }
1629
1630        async fn get_flexible_loan_ongoing_orders(
1631            &self,
1632            _params: GetFlexibleLoanOngoingOrdersParams,
1633        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanOngoingOrdersResponse>> {
1634            if self.force_error {
1635                return Err(ConnectorError::ConnectorClientError {
1636                    msg: "ResponseError".to_string(),
1637                    code: None,
1638                }
1639                .into());
1640            }
1641
1642            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","totalDebt":"10000","collateralCoin":"BNB","collateralAmount":"49.27565492","currentLTV":"0.57"}],"total":1}"#).unwrap();
1643            let dummy_response: models::GetFlexibleLoanOngoingOrdersResponse =
1644                serde_json::from_value(resp_json.clone())
1645                    .expect("should parse into models::GetFlexibleLoanOngoingOrdersResponse");
1646
1647            let dummy = DummyRestApiResponse {
1648                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1649                status: 200,
1650                headers: HashMap::new(),
1651                rate_limits: None,
1652            };
1653
1654            Ok(dummy.into())
1655        }
1656
1657        async fn get_flexible_loan_repayment_history(
1658            &self,
1659            _params: GetFlexibleLoanRepaymentHistoryParams,
1660        ) -> anyhow::Result<RestApiResponse<models::GetFlexibleLoanRepaymentHistoryResponse>>
1661        {
1662            if self.force_error {
1663                return Err(ConnectorError::ConnectorClientError {
1664                    msg: "ResponseError".to_string(),
1665                    code: None,
1666                }
1667                .into());
1668            }
1669
1670            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","repayAmount":"10000","collateralCoin":"BNB","collateralReturn":"49.27565492","repayStatus":"REPAID","repayTime":1575018510000}],"total":1}"#).unwrap();
1671            let dummy_response: models::GetFlexibleLoanRepaymentHistoryResponse =
1672                serde_json::from_value(resp_json.clone())
1673                    .expect("should parse into models::GetFlexibleLoanRepaymentHistoryResponse");
1674
1675            let dummy = DummyRestApiResponse {
1676                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
1677                status: 200,
1678                headers: HashMap::new(),
1679                rate_limits: None,
1680            };
1681
1682            Ok(dummy.into())
1683        }
1684    }
1685
1686    #[test]
1687    fn check_collateral_repay_rate_required_params_success() {
1688        TOKIO_SHARED_RT.block_on(async {
1689            let client = MockFlexibleRateApiClient { force_error: false };
1690
1691            let params = CheckCollateralRepayRateParams::builder(
1692                "loan_coin_example".to_string(),
1693                "collateral_coin_example".to_string(),
1694            )
1695            .build()
1696            .unwrap();
1697
1698            let resp_json: Value = serde_json::from_str(
1699                r#"{"loanCoin":"BUSD","collateralCoin":"BNB","rate":"300.36781234"}"#,
1700            )
1701            .unwrap();
1702            let expected_response: models::CheckCollateralRepayRateResponse =
1703                serde_json::from_value(resp_json.clone())
1704                    .expect("should parse into models::CheckCollateralRepayRateResponse");
1705
1706            let resp = client
1707                .check_collateral_repay_rate(params)
1708                .await
1709                .expect("Expected a response");
1710            let data_future = resp.data();
1711            let actual_response = data_future.await.unwrap();
1712            assert_eq!(actual_response, expected_response);
1713        });
1714    }
1715
1716    #[test]
1717    fn check_collateral_repay_rate_optional_params_success() {
1718        TOKIO_SHARED_RT.block_on(async {
1719            let client = MockFlexibleRateApiClient { force_error: false };
1720
1721            let params = CheckCollateralRepayRateParams::builder(
1722                "loan_coin_example".to_string(),
1723                "collateral_coin_example".to_string(),
1724            )
1725            .recv_window(5000)
1726            .build()
1727            .unwrap();
1728
1729            let resp_json: Value = serde_json::from_str(
1730                r#"{"loanCoin":"BUSD","collateralCoin":"BNB","rate":"300.36781234"}"#,
1731            )
1732            .unwrap();
1733            let expected_response: models::CheckCollateralRepayRateResponse =
1734                serde_json::from_value(resp_json.clone())
1735                    .expect("should parse into models::CheckCollateralRepayRateResponse");
1736
1737            let resp = client
1738                .check_collateral_repay_rate(params)
1739                .await
1740                .expect("Expected a response");
1741            let data_future = resp.data();
1742            let actual_response = data_future.await.unwrap();
1743            assert_eq!(actual_response, expected_response);
1744        });
1745    }
1746
1747    #[test]
1748    fn check_collateral_repay_rate_response_error() {
1749        TOKIO_SHARED_RT.block_on(async {
1750            let client = MockFlexibleRateApiClient { force_error: true };
1751
1752            let params = CheckCollateralRepayRateParams::builder(
1753                "loan_coin_example".to_string(),
1754                "collateral_coin_example".to_string(),
1755            )
1756            .build()
1757            .unwrap();
1758
1759            match client.check_collateral_repay_rate(params).await {
1760                Ok(_) => panic!("Expected an error"),
1761                Err(err) => {
1762                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
1763                }
1764            }
1765        });
1766    }
1767
1768    #[test]
1769    fn flexible_loan_adjust_ltv_required_params_success() {
1770        TOKIO_SHARED_RT.block_on(async {
1771            let client = MockFlexibleRateApiClient { force_error: false };
1772
1773            let params = FlexibleLoanAdjustLtvParams::builder("loan_coin_example".to_string(),"collateral_coin_example".to_string(),dec!(1.0),"direction_example".to_string(),).build().unwrap();
1774
1775            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","collateralCoin":"BNB","direction":"ADDITIONAL","adjustmentAmount":"5.235","currentLTV":"0.52","status":"Succeeds"}"#).unwrap();
1776            let expected_response : models::FlexibleLoanAdjustLtvResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::FlexibleLoanAdjustLtvResponse");
1777
1778            let resp = client.flexible_loan_adjust_ltv(params).await.expect("Expected a response");
1779            let data_future = resp.data();
1780            let actual_response = data_future.await.unwrap();
1781            assert_eq!(actual_response, expected_response);
1782        });
1783    }
1784
1785    #[test]
1786    fn flexible_loan_adjust_ltv_optional_params_success() {
1787        TOKIO_SHARED_RT.block_on(async {
1788            let client = MockFlexibleRateApiClient { force_error: false };
1789
1790            let params = FlexibleLoanAdjustLtvParams::builder("loan_coin_example".to_string(),"collateral_coin_example".to_string(),dec!(1.0),"direction_example".to_string(),).recv_window(5000).build().unwrap();
1791
1792            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","collateralCoin":"BNB","direction":"ADDITIONAL","adjustmentAmount":"5.235","currentLTV":"0.52","status":"Succeeds"}"#).unwrap();
1793            let expected_response : models::FlexibleLoanAdjustLtvResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::FlexibleLoanAdjustLtvResponse");
1794
1795            let resp = client.flexible_loan_adjust_ltv(params).await.expect("Expected a response");
1796            let data_future = resp.data();
1797            let actual_response = data_future.await.unwrap();
1798            assert_eq!(actual_response, expected_response);
1799        });
1800    }
1801
1802    #[test]
1803    fn flexible_loan_adjust_ltv_response_error() {
1804        TOKIO_SHARED_RT.block_on(async {
1805            let client = MockFlexibleRateApiClient { force_error: true };
1806
1807            let params = FlexibleLoanAdjustLtvParams::builder(
1808                "loan_coin_example".to_string(),
1809                "collateral_coin_example".to_string(),
1810                dec!(1.0),
1811                "direction_example".to_string(),
1812            )
1813            .build()
1814            .unwrap();
1815
1816            match client.flexible_loan_adjust_ltv(params).await {
1817                Ok(_) => panic!("Expected an error"),
1818                Err(err) => {
1819                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
1820                }
1821            }
1822        });
1823    }
1824
1825    #[test]
1826    fn flexible_loan_borrow_required_params_success() {
1827        TOKIO_SHARED_RT.block_on(async {
1828            let client = MockFlexibleRateApiClient { force_error: false };
1829
1830            let params = FlexibleLoanBorrowParams::builder("loan_coin_example".to_string(),"collateral_coin_example".to_string(),).build().unwrap();
1831
1832            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","loanAmount":"100.5","collateralCoin":"BNB","collateralAmount":"50.5","status":"Succeeds"}"#).unwrap();
1833            let expected_response : models::FlexibleLoanBorrowResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::FlexibleLoanBorrowResponse");
1834
1835            let resp = client.flexible_loan_borrow(params).await.expect("Expected a response");
1836            let data_future = resp.data();
1837            let actual_response = data_future.await.unwrap();
1838            assert_eq!(actual_response, expected_response);
1839        });
1840    }
1841
1842    #[test]
1843    fn flexible_loan_borrow_optional_params_success() {
1844        TOKIO_SHARED_RT.block_on(async {
1845            let client = MockFlexibleRateApiClient { force_error: false };
1846
1847            let params = FlexibleLoanBorrowParams::builder("loan_coin_example".to_string(),"collateral_coin_example".to_string(),).loan_amount(dec!(1.0)).collateral_amount(dec!(1.0)).recv_window(5000).build().unwrap();
1848
1849            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","loanAmount":"100.5","collateralCoin":"BNB","collateralAmount":"50.5","status":"Succeeds"}"#).unwrap();
1850            let expected_response : models::FlexibleLoanBorrowResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::FlexibleLoanBorrowResponse");
1851
1852            let resp = client.flexible_loan_borrow(params).await.expect("Expected a response");
1853            let data_future = resp.data();
1854            let actual_response = data_future.await.unwrap();
1855            assert_eq!(actual_response, expected_response);
1856        });
1857    }
1858
1859    #[test]
1860    fn flexible_loan_borrow_response_error() {
1861        TOKIO_SHARED_RT.block_on(async {
1862            let client = MockFlexibleRateApiClient { force_error: true };
1863
1864            let params = FlexibleLoanBorrowParams::builder(
1865                "loan_coin_example".to_string(),
1866                "collateral_coin_example".to_string(),
1867            )
1868            .build()
1869            .unwrap();
1870
1871            match client.flexible_loan_borrow(params).await {
1872                Ok(_) => panic!("Expected an error"),
1873                Err(err) => {
1874                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
1875                }
1876            }
1877        });
1878    }
1879
1880    #[test]
1881    fn flexible_loan_repay_required_params_success() {
1882        TOKIO_SHARED_RT.block_on(async {
1883            let client = MockFlexibleRateApiClient { force_error: false };
1884
1885            let params = FlexibleLoanRepayParams::builder("loan_coin_example".to_string(),"collateral_coin_example".to_string(),dec!(1.0),).build().unwrap();
1886
1887            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","collateralCoin":"BNB","remainingDebt":"100.5","remainingCollateral":"5.253","fullRepayment":false,"currentLTV":"0.25","repayStatus":"REPAID"}"#).unwrap();
1888            let expected_response : models::FlexibleLoanRepayResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::FlexibleLoanRepayResponse");
1889
1890            let resp = client.flexible_loan_repay(params).await.expect("Expected a response");
1891            let data_future = resp.data();
1892            let actual_response = data_future.await.unwrap();
1893            assert_eq!(actual_response, expected_response);
1894        });
1895    }
1896
1897    #[test]
1898    fn flexible_loan_repay_optional_params_success() {
1899        TOKIO_SHARED_RT.block_on(async {
1900            let client = MockFlexibleRateApiClient { force_error: false };
1901
1902            let params = FlexibleLoanRepayParams::builder("loan_coin_example".to_string(),"collateral_coin_example".to_string(),dec!(1.0),).collateral_return(true).full_repayment(false).repayment_type(1).recv_window(5000).build().unwrap();
1903
1904            let resp_json: Value = serde_json::from_str(r#"{"loanCoin":"BUSD","collateralCoin":"BNB","remainingDebt":"100.5","remainingCollateral":"5.253","fullRepayment":false,"currentLTV":"0.25","repayStatus":"REPAID"}"#).unwrap();
1905            let expected_response : models::FlexibleLoanRepayResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::FlexibleLoanRepayResponse");
1906
1907            let resp = client.flexible_loan_repay(params).await.expect("Expected a response");
1908            let data_future = resp.data();
1909            let actual_response = data_future.await.unwrap();
1910            assert_eq!(actual_response, expected_response);
1911        });
1912    }
1913
1914    #[test]
1915    fn flexible_loan_repay_response_error() {
1916        TOKIO_SHARED_RT.block_on(async {
1917            let client = MockFlexibleRateApiClient { force_error: true };
1918
1919            let params = FlexibleLoanRepayParams::builder(
1920                "loan_coin_example".to_string(),
1921                "collateral_coin_example".to_string(),
1922                dec!(1.0),
1923            )
1924            .build()
1925            .unwrap();
1926
1927            match client.flexible_loan_repay(params).await {
1928                Ok(_) => panic!("Expected an error"),
1929                Err(err) => {
1930                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
1931                }
1932            }
1933        });
1934    }
1935
1936    #[test]
1937    fn get_flexible_loan_assets_data_required_params_success() {
1938        TOKIO_SHARED_RT.block_on(async {
1939            let client = MockFlexibleRateApiClient { force_error: false };
1940
1941            let params = GetFlexibleLoanAssetsDataParams::builder().build().unwrap();
1942
1943            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","flexibleInterestRate":"0.00000491","flexibleMinLimit":"100","flexibleMaxLimit":"1000000"}],"total":1}"#).unwrap();
1944            let expected_response : models::GetFlexibleLoanAssetsDataResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanAssetsDataResponse");
1945
1946            let resp = client.get_flexible_loan_assets_data(params).await.expect("Expected a response");
1947            let data_future = resp.data();
1948            let actual_response = data_future.await.unwrap();
1949            assert_eq!(actual_response, expected_response);
1950        });
1951    }
1952
1953    #[test]
1954    fn get_flexible_loan_assets_data_optional_params_success() {
1955        TOKIO_SHARED_RT.block_on(async {
1956            let client = MockFlexibleRateApiClient { force_error: false };
1957
1958            let params = GetFlexibleLoanAssetsDataParams::builder().loan_coin("loan_coin_example".to_string()).recv_window(5000).build().unwrap();
1959
1960            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","flexibleInterestRate":"0.00000491","flexibleMinLimit":"100","flexibleMaxLimit":"1000000"}],"total":1}"#).unwrap();
1961            let expected_response : models::GetFlexibleLoanAssetsDataResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanAssetsDataResponse");
1962
1963            let resp = client.get_flexible_loan_assets_data(params).await.expect("Expected a response");
1964            let data_future = resp.data();
1965            let actual_response = data_future.await.unwrap();
1966            assert_eq!(actual_response, expected_response);
1967        });
1968    }
1969
1970    #[test]
1971    fn get_flexible_loan_assets_data_response_error() {
1972        TOKIO_SHARED_RT.block_on(async {
1973            let client = MockFlexibleRateApiClient { force_error: true };
1974
1975            let params = GetFlexibleLoanAssetsDataParams::builder().build().unwrap();
1976
1977            match client.get_flexible_loan_assets_data(params).await {
1978                Ok(_) => panic!("Expected an error"),
1979                Err(err) => {
1980                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
1981                }
1982            }
1983        });
1984    }
1985
1986    #[test]
1987    fn get_flexible_loan_borrow_history_required_params_success() {
1988        TOKIO_SHARED_RT.block_on(async {
1989            let client = MockFlexibleRateApiClient { force_error: false };
1990
1991            let params = GetFlexibleLoanBorrowHistoryParams::builder().build().unwrap();
1992
1993            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","initialLoanAmount":"10000","collateralCoin":"BNB","initialCollateralAmount":"49.27565492","borrowTime":1575018510000,"status":"SUCCESS"}],"total":1}"#).unwrap();
1994            let expected_response : models::GetFlexibleLoanBorrowHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanBorrowHistoryResponse");
1995
1996            let resp = client.get_flexible_loan_borrow_history(params).await.expect("Expected a response");
1997            let data_future = resp.data();
1998            let actual_response = data_future.await.unwrap();
1999            assert_eq!(actual_response, expected_response);
2000        });
2001    }
2002
2003    #[test]
2004    fn get_flexible_loan_borrow_history_optional_params_success() {
2005        TOKIO_SHARED_RT.block_on(async {
2006            let client = MockFlexibleRateApiClient { force_error: false };
2007
2008            let params = GetFlexibleLoanBorrowHistoryParams::builder().loan_coin("loan_coin_example".to_string()).collateral_coin("collateral_coin_example".to_string()).start_time(1623319461670).end_time(1641782889000).current(1).limit(10).recv_window(5000).build().unwrap();
2009
2010            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","initialLoanAmount":"10000","collateralCoin":"BNB","initialCollateralAmount":"49.27565492","borrowTime":1575018510000,"status":"SUCCESS"}],"total":1}"#).unwrap();
2011            let expected_response : models::GetFlexibleLoanBorrowHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanBorrowHistoryResponse");
2012
2013            let resp = client.get_flexible_loan_borrow_history(params).await.expect("Expected a response");
2014            let data_future = resp.data();
2015            let actual_response = data_future.await.unwrap();
2016            assert_eq!(actual_response, expected_response);
2017        });
2018    }
2019
2020    #[test]
2021    fn get_flexible_loan_borrow_history_response_error() {
2022        TOKIO_SHARED_RT.block_on(async {
2023            let client = MockFlexibleRateApiClient { force_error: true };
2024
2025            let params = GetFlexibleLoanBorrowHistoryParams::builder()
2026                .build()
2027                .unwrap();
2028
2029            match client.get_flexible_loan_borrow_history(params).await {
2030                Ok(_) => panic!("Expected an error"),
2031                Err(err) => {
2032                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2033                }
2034            }
2035        });
2036    }
2037
2038    #[test]
2039    fn get_flexible_loan_collateral_assets_data_required_params_success() {
2040        TOKIO_SHARED_RT.block_on(async {
2041            let client = MockFlexibleRateApiClient { force_error: false };
2042
2043            let params = GetFlexibleLoanCollateralAssetsDataParams::builder().build().unwrap();
2044
2045            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"collateralCoin":"BNB","initialLTV":"0.65","marginCallLTV":"0.75","liquidationLTV":"0.83","maxLimit":"1000000"}],"total":1}"#).unwrap();
2046            let expected_response : models::GetFlexibleLoanCollateralAssetsDataResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanCollateralAssetsDataResponse");
2047
2048            let resp = client.get_flexible_loan_collateral_assets_data(params).await.expect("Expected a response");
2049            let data_future = resp.data();
2050            let actual_response = data_future.await.unwrap();
2051            assert_eq!(actual_response, expected_response);
2052        });
2053    }
2054
2055    #[test]
2056    fn get_flexible_loan_collateral_assets_data_optional_params_success() {
2057        TOKIO_SHARED_RT.block_on(async {
2058            let client = MockFlexibleRateApiClient { force_error: false };
2059
2060            let params = GetFlexibleLoanCollateralAssetsDataParams::builder().collateral_coin("collateral_coin_example".to_string()).recv_window(5000).build().unwrap();
2061
2062            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"collateralCoin":"BNB","initialLTV":"0.65","marginCallLTV":"0.75","liquidationLTV":"0.83","maxLimit":"1000000"}],"total":1}"#).unwrap();
2063            let expected_response : models::GetFlexibleLoanCollateralAssetsDataResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanCollateralAssetsDataResponse");
2064
2065            let resp = client.get_flexible_loan_collateral_assets_data(params).await.expect("Expected a response");
2066            let data_future = resp.data();
2067            let actual_response = data_future.await.unwrap();
2068            assert_eq!(actual_response, expected_response);
2069        });
2070    }
2071
2072    #[test]
2073    fn get_flexible_loan_collateral_assets_data_response_error() {
2074        TOKIO_SHARED_RT.block_on(async {
2075            let client = MockFlexibleRateApiClient { force_error: true };
2076
2077            let params = GetFlexibleLoanCollateralAssetsDataParams::builder()
2078                .build()
2079                .unwrap();
2080
2081            match client
2082                .get_flexible_loan_collateral_assets_data(params)
2083                .await
2084            {
2085                Ok(_) => panic!("Expected an error"),
2086                Err(err) => {
2087                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2088                }
2089            }
2090        });
2091    }
2092
2093    #[test]
2094    fn get_flexible_loan_interest_rate_history_required_params_success() {
2095        TOKIO_SHARED_RT.block_on(async {
2096            let client = MockFlexibleRateApiClient { force_error: false };
2097
2098            let params = GetFlexibleLoanInterestRateHistoryParams::builder("coin_example".to_string(),5000,).build().unwrap();
2099
2100            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"coin":"USDT","annualizedInterestRate":"0.0647","time":1575018510000},{"coin":"USDT","annualizedInterestRate":"0.0647","time":1575018510000}],"total":2}"#).unwrap();
2101            let expected_response : models::GetFlexibleLoanInterestRateHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanInterestRateHistoryResponse");
2102
2103            let resp = client.get_flexible_loan_interest_rate_history(params).await.expect("Expected a response");
2104            let data_future = resp.data();
2105            let actual_response = data_future.await.unwrap();
2106            assert_eq!(actual_response, expected_response);
2107        });
2108    }
2109
2110    #[test]
2111    fn get_flexible_loan_interest_rate_history_optional_params_success() {
2112        TOKIO_SHARED_RT.block_on(async {
2113            let client = MockFlexibleRateApiClient { force_error: false };
2114
2115            let params = GetFlexibleLoanInterestRateHistoryParams::builder("coin_example".to_string(),5000,).start_time(1623319461670).end_time(1641782889000).current(1).limit(10).build().unwrap();
2116
2117            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"coin":"USDT","annualizedInterestRate":"0.0647","time":1575018510000},{"coin":"USDT","annualizedInterestRate":"0.0647","time":1575018510000}],"total":2}"#).unwrap();
2118            let expected_response : models::GetFlexibleLoanInterestRateHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanInterestRateHistoryResponse");
2119
2120            let resp = client.get_flexible_loan_interest_rate_history(params).await.expect("Expected a response");
2121            let data_future = resp.data();
2122            let actual_response = data_future.await.unwrap();
2123            assert_eq!(actual_response, expected_response);
2124        });
2125    }
2126
2127    #[test]
2128    fn get_flexible_loan_interest_rate_history_response_error() {
2129        TOKIO_SHARED_RT.block_on(async {
2130            let client = MockFlexibleRateApiClient { force_error: true };
2131
2132            let params =
2133                GetFlexibleLoanInterestRateHistoryParams::builder("coin_example".to_string(), 5000)
2134                    .build()
2135                    .unwrap();
2136
2137            match client.get_flexible_loan_interest_rate_history(params).await {
2138                Ok(_) => panic!("Expected an error"),
2139                Err(err) => {
2140                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2141                }
2142            }
2143        });
2144    }
2145
2146    #[test]
2147    fn get_flexible_loan_liquidation_history_required_params_success() {
2148        TOKIO_SHARED_RT.block_on(async {
2149            let client = MockFlexibleRateApiClient { force_error: false };
2150
2151            let params = GetFlexibleLoanLiquidationHistoryParams::builder().build().unwrap();
2152
2153            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","liquidationDebt":"10000","collateralCoin":"BNB","liquidationCollateralAmount":"123","returnCollateralAmount":"0.2","liquidationFee":"1.2","liquidationStartingPrice":"49.27565492","liquidationStartingTime":1575018510000,"status":"Liquidated"}],"total":1}"#).unwrap();
2154            let expected_response : models::GetFlexibleLoanLiquidationHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanLiquidationHistoryResponse");
2155
2156            let resp = client.get_flexible_loan_liquidation_history(params).await.expect("Expected a response");
2157            let data_future = resp.data();
2158            let actual_response = data_future.await.unwrap();
2159            assert_eq!(actual_response, expected_response);
2160        });
2161    }
2162
2163    #[test]
2164    fn get_flexible_loan_liquidation_history_optional_params_success() {
2165        TOKIO_SHARED_RT.block_on(async {
2166            let client = MockFlexibleRateApiClient { force_error: false };
2167
2168            let params = GetFlexibleLoanLiquidationHistoryParams::builder().loan_coin("loan_coin_example".to_string()).collateral_coin("collateral_coin_example".to_string()).start_time(1623319461670).end_time(1641782889000).current(1).limit(10).recv_window(5000).build().unwrap();
2169
2170            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","liquidationDebt":"10000","collateralCoin":"BNB","liquidationCollateralAmount":"123","returnCollateralAmount":"0.2","liquidationFee":"1.2","liquidationStartingPrice":"49.27565492","liquidationStartingTime":1575018510000,"status":"Liquidated"}],"total":1}"#).unwrap();
2171            let expected_response : models::GetFlexibleLoanLiquidationHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanLiquidationHistoryResponse");
2172
2173            let resp = client.get_flexible_loan_liquidation_history(params).await.expect("Expected a response");
2174            let data_future = resp.data();
2175            let actual_response = data_future.await.unwrap();
2176            assert_eq!(actual_response, expected_response);
2177        });
2178    }
2179
2180    #[test]
2181    fn get_flexible_loan_liquidation_history_response_error() {
2182        TOKIO_SHARED_RT.block_on(async {
2183            let client = MockFlexibleRateApiClient { force_error: true };
2184
2185            let params = GetFlexibleLoanLiquidationHistoryParams::builder()
2186                .build()
2187                .unwrap();
2188
2189            match client.get_flexible_loan_liquidation_history(params).await {
2190                Ok(_) => panic!("Expected an error"),
2191                Err(err) => {
2192                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2193                }
2194            }
2195        });
2196    }
2197
2198    #[test]
2199    fn get_flexible_loan_ltv_adjustment_history_required_params_success() {
2200        TOKIO_SHARED_RT.block_on(async {
2201            let client = MockFlexibleRateApiClient { force_error: false };
2202
2203            let params = GetFlexibleLoanLtvAdjustmentHistoryParams::builder().build().unwrap();
2204
2205            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","collateralCoin":"BNB","direction":"ADDITIONAL","collateralAmount":"5.235","preLTV":"0.78","afterLTV":"0.56","adjustTime":1575018510000}],"total":1}"#).unwrap();
2206            let expected_response : models::GetFlexibleLoanLtvAdjustmentHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanLtvAdjustmentHistoryResponse");
2207
2208            let resp = client.get_flexible_loan_ltv_adjustment_history(params).await.expect("Expected a response");
2209            let data_future = resp.data();
2210            let actual_response = data_future.await.unwrap();
2211            assert_eq!(actual_response, expected_response);
2212        });
2213    }
2214
2215    #[test]
2216    fn get_flexible_loan_ltv_adjustment_history_optional_params_success() {
2217        TOKIO_SHARED_RT.block_on(async {
2218            let client = MockFlexibleRateApiClient { force_error: false };
2219
2220            let params = GetFlexibleLoanLtvAdjustmentHistoryParams::builder().loan_coin("loan_coin_example".to_string()).collateral_coin("collateral_coin_example".to_string()).start_time(1623319461670).end_time(1641782889000).current(1).limit(10).recv_window(5000).build().unwrap();
2221
2222            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","collateralCoin":"BNB","direction":"ADDITIONAL","collateralAmount":"5.235","preLTV":"0.78","afterLTV":"0.56","adjustTime":1575018510000}],"total":1}"#).unwrap();
2223            let expected_response : models::GetFlexibleLoanLtvAdjustmentHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanLtvAdjustmentHistoryResponse");
2224
2225            let resp = client.get_flexible_loan_ltv_adjustment_history(params).await.expect("Expected a response");
2226            let data_future = resp.data();
2227            let actual_response = data_future.await.unwrap();
2228            assert_eq!(actual_response, expected_response);
2229        });
2230    }
2231
2232    #[test]
2233    fn get_flexible_loan_ltv_adjustment_history_response_error() {
2234        TOKIO_SHARED_RT.block_on(async {
2235            let client = MockFlexibleRateApiClient { force_error: true };
2236
2237            let params = GetFlexibleLoanLtvAdjustmentHistoryParams::builder()
2238                .build()
2239                .unwrap();
2240
2241            match client
2242                .get_flexible_loan_ltv_adjustment_history(params)
2243                .await
2244            {
2245                Ok(_) => panic!("Expected an error"),
2246                Err(err) => {
2247                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2248                }
2249            }
2250        });
2251    }
2252
2253    #[test]
2254    fn get_flexible_loan_ongoing_orders_required_params_success() {
2255        TOKIO_SHARED_RT.block_on(async {
2256            let client = MockFlexibleRateApiClient { force_error: false };
2257
2258            let params = GetFlexibleLoanOngoingOrdersParams::builder().build().unwrap();
2259
2260            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","totalDebt":"10000","collateralCoin":"BNB","collateralAmount":"49.27565492","currentLTV":"0.57"}],"total":1}"#).unwrap();
2261            let expected_response : models::GetFlexibleLoanOngoingOrdersResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanOngoingOrdersResponse");
2262
2263            let resp = client.get_flexible_loan_ongoing_orders(params).await.expect("Expected a response");
2264            let data_future = resp.data();
2265            let actual_response = data_future.await.unwrap();
2266            assert_eq!(actual_response, expected_response);
2267        });
2268    }
2269
2270    #[test]
2271    fn get_flexible_loan_ongoing_orders_optional_params_success() {
2272        TOKIO_SHARED_RT.block_on(async {
2273            let client = MockFlexibleRateApiClient { force_error: false };
2274
2275            let params = GetFlexibleLoanOngoingOrdersParams::builder().loan_coin("loan_coin_example".to_string()).collateral_coin("collateral_coin_example".to_string()).current(1).limit(10).recv_window(5000).build().unwrap();
2276
2277            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","totalDebt":"10000","collateralCoin":"BNB","collateralAmount":"49.27565492","currentLTV":"0.57"}],"total":1}"#).unwrap();
2278            let expected_response : models::GetFlexibleLoanOngoingOrdersResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanOngoingOrdersResponse");
2279
2280            let resp = client.get_flexible_loan_ongoing_orders(params).await.expect("Expected a response");
2281            let data_future = resp.data();
2282            let actual_response = data_future.await.unwrap();
2283            assert_eq!(actual_response, expected_response);
2284        });
2285    }
2286
2287    #[test]
2288    fn get_flexible_loan_ongoing_orders_response_error() {
2289        TOKIO_SHARED_RT.block_on(async {
2290            let client = MockFlexibleRateApiClient { force_error: true };
2291
2292            let params = GetFlexibleLoanOngoingOrdersParams::builder()
2293                .build()
2294                .unwrap();
2295
2296            match client.get_flexible_loan_ongoing_orders(params).await {
2297                Ok(_) => panic!("Expected an error"),
2298                Err(err) => {
2299                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2300                }
2301            }
2302        });
2303    }
2304
2305    #[test]
2306    fn get_flexible_loan_repayment_history_required_params_success() {
2307        TOKIO_SHARED_RT.block_on(async {
2308            let client = MockFlexibleRateApiClient { force_error: false };
2309
2310            let params = GetFlexibleLoanRepaymentHistoryParams::builder().build().unwrap();
2311
2312            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","repayAmount":"10000","collateralCoin":"BNB","collateralReturn":"49.27565492","repayStatus":"REPAID","repayTime":1575018510000}],"total":1}"#).unwrap();
2313            let expected_response : models::GetFlexibleLoanRepaymentHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanRepaymentHistoryResponse");
2314
2315            let resp = client.get_flexible_loan_repayment_history(params).await.expect("Expected a response");
2316            let data_future = resp.data();
2317            let actual_response = data_future.await.unwrap();
2318            assert_eq!(actual_response, expected_response);
2319        });
2320    }
2321
2322    #[test]
2323    fn get_flexible_loan_repayment_history_optional_params_success() {
2324        TOKIO_SHARED_RT.block_on(async {
2325            let client = MockFlexibleRateApiClient { force_error: false };
2326
2327            let params = GetFlexibleLoanRepaymentHistoryParams::builder().loan_coin("loan_coin_example".to_string()).collateral_coin("collateral_coin_example".to_string()).start_time(1623319461670).end_time(1641782889000).current(1).limit(10).recv_window(5000).build().unwrap();
2328
2329            let resp_json: Value = serde_json::from_str(r#"{"rows":[{"loanCoin":"BUSD","repayAmount":"10000","collateralCoin":"BNB","collateralReturn":"49.27565492","repayStatus":"REPAID","repayTime":1575018510000}],"total":1}"#).unwrap();
2330            let expected_response : models::GetFlexibleLoanRepaymentHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetFlexibleLoanRepaymentHistoryResponse");
2331
2332            let resp = client.get_flexible_loan_repayment_history(params).await.expect("Expected a response");
2333            let data_future = resp.data();
2334            let actual_response = data_future.await.unwrap();
2335            assert_eq!(actual_response, expected_response);
2336        });
2337    }
2338
2339    #[test]
2340    fn get_flexible_loan_repayment_history_response_error() {
2341        TOKIO_SHARED_RT.block_on(async {
2342            let client = MockFlexibleRateApiClient { force_error: true };
2343
2344            let params = GetFlexibleLoanRepaymentHistoryParams::builder()
2345                .build()
2346                .unwrap();
2347
2348            match client.get_flexible_loan_repayment_history(params).await {
2349                Ok(_) => panic!("Expected an error"),
2350                Err(err) => {
2351                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
2352                }
2353            }
2354        });
2355    }
2356}