1#![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::margin_trading::rest_api::models;
29
30const HAS_TIME_UNIT: bool = false;
31
32#[async_trait]
33pub trait TradeApi: Send + Sync {
34 async fn create_special_key(
35 &self,
36 params: CreateSpecialKeyParams,
37 ) -> anyhow::Result<RestApiResponse<models::CreateSpecialKeyResponse>>;
38 async fn delete_special_key(
39 &self,
40 params: DeleteSpecialKeyParams,
41 ) -> anyhow::Result<RestApiResponse<Value>>;
42 async fn edit_ip_for_special_key(
43 &self,
44 params: EditIpForSpecialKeyParams,
45 ) -> anyhow::Result<RestApiResponse<Value>>;
46 async fn get_force_liquidation_record(
47 &self,
48 params: GetForceLiquidationRecordParams,
49 ) -> anyhow::Result<RestApiResponse<models::GetForceLiquidationRecordResponse>>;
50 async fn get_small_liability_exchange_coin_list(
51 &self,
52 params: GetSmallLiabilityExchangeCoinListParams,
53 ) -> anyhow::Result<RestApiResponse<Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>>>;
54 async fn get_small_liability_exchange_history(
55 &self,
56 params: GetSmallLiabilityExchangeHistoryParams,
57 ) -> anyhow::Result<RestApiResponse<models::GetSmallLiabilityExchangeHistoryResponse>>;
58 async fn margin_account_cancel_all_open_orders_on_a_symbol(
59 &self,
60 params: MarginAccountCancelAllOpenOrdersOnASymbolParams,
61 ) -> anyhow::Result<
62 RestApiResponse<Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>>,
63 >;
64 async fn margin_account_cancel_oco(
65 &self,
66 params: MarginAccountCancelOcoParams,
67 ) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOcoResponse>>;
68 async fn margin_account_cancel_order(
69 &self,
70 params: MarginAccountCancelOrderParams,
71 ) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOrderResponse>>;
72 async fn margin_account_new_oco(
73 &self,
74 params: MarginAccountNewOcoParams,
75 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOcoResponse>>;
76 async fn margin_account_new_order(
77 &self,
78 params: MarginAccountNewOrderParams,
79 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOrderResponse>>;
80 async fn margin_account_new_oto(
81 &self,
82 params: MarginAccountNewOtoParams,
83 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtoResponse>>;
84 async fn margin_account_new_otoco(
85 &self,
86 params: MarginAccountNewOtocoParams,
87 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtocoResponse>>;
88 async fn margin_manual_liquidation(
89 &self,
90 params: MarginManualLiquidationParams,
91 ) -> anyhow::Result<RestApiResponse<models::MarginManualLiquidationResponse>>;
92 async fn query_current_margin_order_count_usage(
93 &self,
94 params: QueryCurrentMarginOrderCountUsageParams,
95 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>>>;
96 async fn query_margin_accounts_all_oco(
97 &self,
98 params: QueryMarginAccountsAllOcoParams,
99 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOcoResponseInner>>>;
100 async fn query_margin_accounts_all_orders(
101 &self,
102 params: QueryMarginAccountsAllOrdersParams,
103 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOrdersResponseInner>>>;
104 async fn query_margin_accounts_oco(
105 &self,
106 params: QueryMarginAccountsOcoParams,
107 ) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOcoResponse>>;
108 async fn query_margin_accounts_open_oco(
109 &self,
110 params: QueryMarginAccountsOpenOcoParams,
111 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOcoResponseInner>>>;
112 async fn query_margin_accounts_open_orders(
113 &self,
114 params: QueryMarginAccountsOpenOrdersParams,
115 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOrdersResponseInner>>>;
116 async fn query_margin_accounts_order(
117 &self,
118 params: QueryMarginAccountsOrderParams,
119 ) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOrderResponse>>;
120 async fn query_margin_accounts_trade_list(
121 &self,
122 params: QueryMarginAccountsTradeListParams,
123 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsTradeListResponseInner>>>;
124 async fn query_prevented_matches(
125 &self,
126 params: QueryPreventedMatchesParams,
127 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryPreventedMatchesResponseInner>>>;
128 async fn query_special_key(
129 &self,
130 params: QuerySpecialKeyParams,
131 ) -> anyhow::Result<RestApiResponse<models::QuerySpecialKeyResponse>>;
132 async fn query_special_key_list(
133 &self,
134 params: QuerySpecialKeyListParams,
135 ) -> anyhow::Result<RestApiResponse<Vec<models::QuerySpecialKeyListResponseInner>>>;
136 async fn small_liability_exchange(
137 &self,
138 params: SmallLiabilityExchangeParams,
139 ) -> anyhow::Result<RestApiResponse<Value>>;
140}
141
142#[derive(Debug, Clone)]
143pub struct TradeApiClient {
144 configuration: ConfigurationRestApi,
145}
146
147impl TradeApiClient {
148 pub fn new(configuration: ConfigurationRestApi) -> Self {
149 Self { configuration }
150 }
151}
152
153#[allow(non_camel_case_types)]
154#[derive(Debug, Clone, Serialize, Deserialize)]
155pub enum MarginAccountNewOcoSideEnum {
156 #[serde(rename = "BUY")]
157 Buy,
158 #[serde(rename = "SELL")]
159 Sell,
160}
161
162impl MarginAccountNewOcoSideEnum {
163 #[must_use]
164 pub fn as_str(&self) -> &'static str {
165 match self {
166 Self::Buy => "BUY",
167 Self::Sell => "SELL",
168 }
169 }
170}
171
172impl std::str::FromStr for MarginAccountNewOcoSideEnum {
173 type Err = Box<dyn std::error::Error + Send + Sync>;
174
175 fn from_str(s: &str) -> Result<Self, Self::Err> {
176 match s {
177 "BUY" => Ok(Self::Buy),
178 "SELL" => Ok(Self::Sell),
179 other => Err(format!("invalid MarginAccountNewOcoSideEnum: {}", other).into()),
180 }
181 }
182}
183
184#[allow(non_camel_case_types)]
185#[derive(Debug, Clone, Serialize, Deserialize)]
186pub enum MarginAccountNewOcoNewOrderRespTypeEnum {
187 #[serde(rename = "ACK")]
188 Ack,
189 #[serde(rename = "RESULT")]
190 Result,
191 #[serde(rename = "FULL")]
192 Full,
193}
194
195impl MarginAccountNewOcoNewOrderRespTypeEnum {
196 #[must_use]
197 pub fn as_str(&self) -> &'static str {
198 match self {
199 Self::Ack => "ACK",
200 Self::Result => "RESULT",
201 Self::Full => "FULL",
202 }
203 }
204}
205
206impl std::str::FromStr for MarginAccountNewOcoNewOrderRespTypeEnum {
207 type Err = Box<dyn std::error::Error + Send + Sync>;
208
209 fn from_str(s: &str) -> Result<Self, Self::Err> {
210 match s {
211 "ACK" => Ok(Self::Ack),
212 "RESULT" => Ok(Self::Result),
213 "FULL" => Ok(Self::Full),
214 other => {
215 Err(format!("invalid MarginAccountNewOcoNewOrderRespTypeEnum: {}", other).into())
216 }
217 }
218 }
219}
220
221#[allow(non_camel_case_types)]
222#[derive(Debug, Clone, Serialize, Deserialize)]
223pub enum MarginAccountNewOrderSideEnum {
224 #[serde(rename = "BUY")]
225 Buy,
226 #[serde(rename = "SELL")]
227 Sell,
228}
229
230impl MarginAccountNewOrderSideEnum {
231 #[must_use]
232 pub fn as_str(&self) -> &'static str {
233 match self {
234 Self::Buy => "BUY",
235 Self::Sell => "SELL",
236 }
237 }
238}
239
240impl std::str::FromStr for MarginAccountNewOrderSideEnum {
241 type Err = Box<dyn std::error::Error + Send + Sync>;
242
243 fn from_str(s: &str) -> Result<Self, Self::Err> {
244 match s {
245 "BUY" => Ok(Self::Buy),
246 "SELL" => Ok(Self::Sell),
247 other => Err(format!("invalid MarginAccountNewOrderSideEnum: {}", other).into()),
248 }
249 }
250}
251
252#[allow(non_camel_case_types)]
253#[derive(Debug, Clone, Serialize, Deserialize)]
254pub enum MarginAccountNewOrderNewOrderRespTypeEnum {
255 #[serde(rename = "ACK")]
256 Ack,
257 #[serde(rename = "RESULT")]
258 Result,
259 #[serde(rename = "FULL")]
260 Full,
261}
262
263impl MarginAccountNewOrderNewOrderRespTypeEnum {
264 #[must_use]
265 pub fn as_str(&self) -> &'static str {
266 match self {
267 Self::Ack => "ACK",
268 Self::Result => "RESULT",
269 Self::Full => "FULL",
270 }
271 }
272}
273
274impl std::str::FromStr for MarginAccountNewOrderNewOrderRespTypeEnum {
275 type Err = Box<dyn std::error::Error + Send + Sync>;
276
277 fn from_str(s: &str) -> Result<Self, Self::Err> {
278 match s {
279 "ACK" => Ok(Self::Ack),
280 "RESULT" => Ok(Self::Result),
281 "FULL" => Ok(Self::Full),
282 other => Err(format!(
283 "invalid MarginAccountNewOrderNewOrderRespTypeEnum: {}",
284 other
285 )
286 .into()),
287 }
288 }
289}
290
291#[allow(non_camel_case_types)]
292#[derive(Debug, Clone, Serialize, Deserialize)]
293pub enum MarginAccountNewOrderTimeInForceEnum {
294 #[serde(rename = "GTC")]
295 Gtc,
296 #[serde(rename = "IOC")]
297 Ioc,
298 #[serde(rename = "FOK")]
299 Fok,
300}
301
302impl MarginAccountNewOrderTimeInForceEnum {
303 #[must_use]
304 pub fn as_str(&self) -> &'static str {
305 match self {
306 Self::Gtc => "GTC",
307 Self::Ioc => "IOC",
308 Self::Fok => "FOK",
309 }
310 }
311}
312
313impl std::str::FromStr for MarginAccountNewOrderTimeInForceEnum {
314 type Err = Box<dyn std::error::Error + Send + Sync>;
315
316 fn from_str(s: &str) -> Result<Self, Self::Err> {
317 match s {
318 "GTC" => Ok(Self::Gtc),
319 "IOC" => Ok(Self::Ioc),
320 "FOK" => Ok(Self::Fok),
321 other => Err(format!("invalid MarginAccountNewOrderTimeInForceEnum: {}", other).into()),
322 }
323 }
324}
325
326#[allow(non_camel_case_types)]
327#[derive(Debug, Clone, Serialize, Deserialize)]
328pub enum MarginAccountNewOtoNewOrderRespTypeEnum {
329 #[serde(rename = "ACK")]
330 Ack,
331 #[serde(rename = "RESULT")]
332 Result,
333 #[serde(rename = "FULL")]
334 Full,
335}
336
337impl MarginAccountNewOtoNewOrderRespTypeEnum {
338 #[must_use]
339 pub fn as_str(&self) -> &'static str {
340 match self {
341 Self::Ack => "ACK",
342 Self::Result => "RESULT",
343 Self::Full => "FULL",
344 }
345 }
346}
347
348impl std::str::FromStr for MarginAccountNewOtoNewOrderRespTypeEnum {
349 type Err = Box<dyn std::error::Error + Send + Sync>;
350
351 fn from_str(s: &str) -> Result<Self, Self::Err> {
352 match s {
353 "ACK" => Ok(Self::Ack),
354 "RESULT" => Ok(Self::Result),
355 "FULL" => Ok(Self::Full),
356 other => {
357 Err(format!("invalid MarginAccountNewOtoNewOrderRespTypeEnum: {}", other).into())
358 }
359 }
360 }
361}
362
363#[allow(non_camel_case_types)]
364#[derive(Debug, Clone, Serialize, Deserialize)]
365pub enum MarginAccountNewOtocoNewOrderRespTypeEnum {
366 #[serde(rename = "ACK")]
367 Ack,
368 #[serde(rename = "RESULT")]
369 Result,
370 #[serde(rename = "FULL")]
371 Full,
372}
373
374impl MarginAccountNewOtocoNewOrderRespTypeEnum {
375 #[must_use]
376 pub fn as_str(&self) -> &'static str {
377 match self {
378 Self::Ack => "ACK",
379 Self::Result => "RESULT",
380 Self::Full => "FULL",
381 }
382 }
383}
384
385impl std::str::FromStr for MarginAccountNewOtocoNewOrderRespTypeEnum {
386 type Err = Box<dyn std::error::Error + Send + Sync>;
387
388 fn from_str(s: &str) -> Result<Self, Self::Err> {
389 match s {
390 "ACK" => Ok(Self::Ack),
391 "RESULT" => Ok(Self::Result),
392 "FULL" => Ok(Self::Full),
393 other => Err(format!(
394 "invalid MarginAccountNewOtocoNewOrderRespTypeEnum: {}",
395 other
396 )
397 .into()),
398 }
399 }
400}
401
402#[derive(Clone, Debug, Builder)]
407#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
408pub struct CreateSpecialKeyParams {
409 #[builder(setter(into))]
414 pub api_name: String,
415 #[builder(setter(into), default)]
419 pub symbol: Option<String>,
420 #[builder(setter(into), default)]
424 pub ip: Option<String>,
425 #[builder(setter(into), default)]
429 pub public_key: Option<String>,
430 #[builder(setter(into), default)]
434 pub permission_mode: Option<String>,
435 #[builder(setter(into), default)]
439 pub recv_window: Option<i64>,
440}
441
442impl CreateSpecialKeyParams {
443 #[must_use]
450 pub fn builder(api_name: String) -> CreateSpecialKeyParamsBuilder {
451 CreateSpecialKeyParamsBuilder::default().api_name(api_name)
452 }
453}
454#[derive(Clone, Debug, Builder, Default)]
459#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
460pub struct DeleteSpecialKeyParams {
461 #[builder(setter(into), default)]
466 pub api_name: Option<String>,
467 #[builder(setter(into), default)]
471 pub symbol: Option<String>,
472 #[builder(setter(into), default)]
476 pub recv_window: Option<i64>,
477}
478
479impl DeleteSpecialKeyParams {
480 #[must_use]
483 pub fn builder() -> DeleteSpecialKeyParamsBuilder {
484 DeleteSpecialKeyParamsBuilder::default()
485 }
486}
487#[derive(Clone, Debug, Builder)]
492#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
493pub struct EditIpForSpecialKeyParams {
494 #[builder(setter(into))]
498 pub ip: String,
499 #[builder(setter(into), default)]
503 pub symbol: Option<String>,
504 #[builder(setter(into), default)]
508 pub recv_window: Option<i64>,
509}
510
511impl EditIpForSpecialKeyParams {
512 #[must_use]
519 pub fn builder(ip: String) -> EditIpForSpecialKeyParamsBuilder {
520 EditIpForSpecialKeyParamsBuilder::default().ip(ip)
521 }
522}
523#[derive(Clone, Debug, Builder, Default)]
528#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
529pub struct GetForceLiquidationRecordParams {
530 #[builder(setter(into), default)]
534 pub start_time: Option<i64>,
535 #[builder(setter(into), default)]
540 pub end_time: Option<i64>,
541 #[builder(setter(into), default)]
545 pub isolated_symbol: Option<String>,
546 #[builder(setter(into), default)]
550 pub current: Option<i64>,
551 #[builder(setter(into), default)]
555 pub size: Option<i64>,
556 #[builder(setter(into), default)]
560 pub recv_window: Option<i64>,
561}
562
563impl GetForceLiquidationRecordParams {
564 #[must_use]
567 pub fn builder() -> GetForceLiquidationRecordParamsBuilder {
568 GetForceLiquidationRecordParamsBuilder::default()
569 }
570}
571#[derive(Clone, Debug, Builder, Default)]
576#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
577pub struct GetSmallLiabilityExchangeCoinListParams {
578 #[builder(setter(into), default)]
582 pub recv_window: Option<i64>,
583}
584
585impl GetSmallLiabilityExchangeCoinListParams {
586 #[must_use]
589 pub fn builder() -> GetSmallLiabilityExchangeCoinListParamsBuilder {
590 GetSmallLiabilityExchangeCoinListParamsBuilder::default()
591 }
592}
593#[derive(Clone, Debug, Builder)]
598#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
599pub struct GetSmallLiabilityExchangeHistoryParams {
600 #[builder(setter(into))]
604 pub current: i64,
605 #[builder(setter(into))]
609 pub size: i64,
610 #[builder(setter(into), default)]
614 pub start_time: Option<i64>,
615 #[builder(setter(into), default)]
620 pub end_time: Option<i64>,
621 #[builder(setter(into), default)]
625 pub recv_window: Option<i64>,
626}
627
628impl GetSmallLiabilityExchangeHistoryParams {
629 #[must_use]
637 pub fn builder(current: i64, size: i64) -> GetSmallLiabilityExchangeHistoryParamsBuilder {
638 GetSmallLiabilityExchangeHistoryParamsBuilder::default()
639 .current(current)
640 .size(size)
641 }
642}
643#[derive(Clone, Debug, Builder)]
648#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
649pub struct MarginAccountCancelAllOpenOrdersOnASymbolParams {
650 #[builder(setter(into))]
655 pub symbol: String,
656 #[builder(setter(into), default)]
660 pub is_isolated: Option<String>,
661 #[builder(setter(into), default)]
665 pub recv_window: Option<i64>,
666}
667
668impl MarginAccountCancelAllOpenOrdersOnASymbolParams {
669 #[must_use]
676 pub fn builder(symbol: String) -> MarginAccountCancelAllOpenOrdersOnASymbolParamsBuilder {
677 MarginAccountCancelAllOpenOrdersOnASymbolParamsBuilder::default().symbol(symbol)
678 }
679}
680#[derive(Clone, Debug, Builder)]
685#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
686pub struct MarginAccountCancelOcoParams {
687 #[builder(setter(into))]
692 pub symbol: String,
693 #[builder(setter(into), default)]
697 pub is_isolated: Option<String>,
698 #[builder(setter(into), default)]
702 pub order_list_id: Option<i64>,
703 #[builder(setter(into), default)]
707 pub list_client_order_id: Option<String>,
708 #[builder(setter(into), default)]
712 pub new_client_order_id: Option<String>,
713 #[builder(setter(into), default)]
717 pub recv_window: Option<i64>,
718}
719
720impl MarginAccountCancelOcoParams {
721 #[must_use]
728 pub fn builder(symbol: String) -> MarginAccountCancelOcoParamsBuilder {
729 MarginAccountCancelOcoParamsBuilder::default().symbol(symbol)
730 }
731}
732#[derive(Clone, Debug, Builder)]
737#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
738pub struct MarginAccountCancelOrderParams {
739 #[builder(setter(into))]
744 pub symbol: String,
745 #[builder(setter(into), default)]
749 pub is_isolated: Option<String>,
750 #[builder(setter(into), default)]
755 pub order_id: Option<i64>,
756 #[builder(setter(into), default)]
761 pub orig_client_order_id: Option<String>,
762 #[builder(setter(into), default)]
766 pub new_client_order_id: Option<String>,
767 #[builder(setter(into), default)]
771 pub recv_window: Option<i64>,
772}
773
774impl MarginAccountCancelOrderParams {
775 #[must_use]
782 pub fn builder(symbol: String) -> MarginAccountCancelOrderParamsBuilder {
783 MarginAccountCancelOrderParamsBuilder::default().symbol(symbol)
784 }
785}
786#[derive(Clone, Debug, Builder)]
791#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
792pub struct MarginAccountNewOcoParams {
793 #[builder(setter(into))]
798 pub symbol: String,
799 #[builder(setter(into))]
804 pub side: MarginAccountNewOcoSideEnum,
805 #[builder(setter(into))]
810 pub quantity: rust_decimal::Decimal,
811 #[builder(setter(into))]
816 pub price: rust_decimal::Decimal,
817 #[builder(setter(into))]
822 pub stop_price: rust_decimal::Decimal,
823 #[builder(setter(into), default)]
827 pub is_isolated: Option<String>,
828 #[builder(setter(into), default)]
832 pub list_client_order_id: Option<String>,
833 #[builder(setter(into), default)]
837 pub limit_client_order_id: Option<String>,
838 #[builder(setter(into), default)]
843 pub limit_iceberg_qty: Option<rust_decimal::Decimal>,
844 #[builder(setter(into), default)]
848 pub stop_client_order_id: Option<String>,
849 #[builder(setter(into), default)]
853 pub stop_limit_price: Option<rust_decimal::Decimal>,
854 #[builder(setter(into), default)]
859 pub stop_iceberg_qty: Option<rust_decimal::Decimal>,
860 #[builder(setter(into), default)]
864 pub stop_limit_time_in_force: Option<String>,
865 #[builder(setter(into), default)]
869 pub new_order_resp_type: Option<MarginAccountNewOcoNewOrderRespTypeEnum>,
870 #[builder(setter(into), default)]
874 pub side_effect_type: Option<String>,
875 #[builder(setter(into), default)]
879 pub self_trade_prevention_mode: Option<String>,
880 #[builder(setter(into), default)]
884 pub auto_repay_at_cancel: Option<bool>,
885 #[builder(setter(into), default)]
889 pub recv_window: Option<i64>,
890}
891
892impl MarginAccountNewOcoParams {
893 #[must_use]
904 pub fn builder(
905 symbol: String,
906 side: MarginAccountNewOcoSideEnum,
907 quantity: rust_decimal::Decimal,
908 price: rust_decimal::Decimal,
909 stop_price: rust_decimal::Decimal,
910 ) -> MarginAccountNewOcoParamsBuilder {
911 MarginAccountNewOcoParamsBuilder::default()
912 .symbol(symbol)
913 .side(side)
914 .quantity(quantity)
915 .price(price)
916 .stop_price(stop_price)
917 }
918}
919#[derive(Clone, Debug, Builder)]
924#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
925pub struct MarginAccountNewOrderParams {
926 #[builder(setter(into))]
931 pub symbol: String,
932 #[builder(setter(into))]
937 pub side: MarginAccountNewOrderSideEnum,
938 #[builder(setter(into))]
942 pub r#type: String,
943 #[builder(setter(into), default)]
947 pub is_isolated: Option<String>,
948 #[builder(setter(into), default)]
953 pub quantity: Option<rust_decimal::Decimal>,
954 #[builder(setter(into), default)]
959 pub quote_order_qty: Option<rust_decimal::Decimal>,
960 #[builder(setter(into), default)]
965 pub price: Option<rust_decimal::Decimal>,
966 #[builder(setter(into), default)]
970 pub stop_price: Option<rust_decimal::Decimal>,
971 #[builder(setter(into), default)]
975 pub new_client_order_id: Option<String>,
976 #[builder(setter(into), default)]
980 pub iceberg_qty: Option<rust_decimal::Decimal>,
981 #[builder(setter(into), default)]
985 pub new_order_resp_type: Option<MarginAccountNewOrderNewOrderRespTypeEnum>,
986 #[builder(setter(into), default)]
990 pub side_effect_type: Option<String>,
991 #[builder(setter(into), default)]
995 pub time_in_force: Option<MarginAccountNewOrderTimeInForceEnum>,
996 #[builder(setter(into), default)]
1000 pub self_trade_prevention_mode: Option<String>,
1001 #[builder(setter(into), default)]
1005 pub auto_repay_at_cancel: Option<bool>,
1006 #[builder(setter(into), default)]
1010 pub recv_window: Option<i64>,
1011}
1012
1013impl MarginAccountNewOrderParams {
1014 #[must_use]
1023 pub fn builder(
1024 symbol: String,
1025 side: MarginAccountNewOrderSideEnum,
1026 r#type: String,
1027 ) -> MarginAccountNewOrderParamsBuilder {
1028 MarginAccountNewOrderParamsBuilder::default()
1029 .symbol(symbol)
1030 .side(side)
1031 .r#type(r#type)
1032 }
1033}
1034#[derive(Clone, Debug, Builder)]
1039#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1040pub struct MarginAccountNewOtoParams {
1041 #[builder(setter(into))]
1046 pub symbol: String,
1047 #[builder(setter(into))]
1051 pub working_type: String,
1052 #[builder(setter(into))]
1056 pub working_side: String,
1057 #[builder(setter(into))]
1062 pub working_price: rust_decimal::Decimal,
1063 #[builder(setter(into))]
1068 pub working_quantity: rust_decimal::Decimal,
1069 #[builder(setter(into))]
1073 pub working_iceberg_qty: rust_decimal::Decimal,
1074 #[builder(setter(into))]
1078 pub pending_type: String,
1079 #[builder(setter(into))]
1083 pub pending_side: String,
1084 #[builder(setter(into))]
1089 pub pending_quantity: rust_decimal::Decimal,
1090 #[builder(setter(into), default)]
1094 pub is_isolated: Option<String>,
1095 #[builder(setter(into), default)]
1099 pub list_client_order_id: Option<String>,
1100 #[builder(setter(into), default)]
1104 pub new_order_resp_type: Option<MarginAccountNewOtoNewOrderRespTypeEnum>,
1105 #[builder(setter(into), default)]
1109 pub side_effect_type: Option<String>,
1110 #[builder(setter(into), default)]
1114 pub self_trade_prevention_mode: Option<String>,
1115 #[builder(setter(into), default)]
1119 pub auto_repay_at_cancel: Option<bool>,
1120 #[builder(setter(into), default)]
1124 pub working_client_order_id: Option<String>,
1125 #[builder(setter(into), default)]
1129 pub working_time_in_force: Option<String>,
1130 #[builder(setter(into), default)]
1134 pub pending_client_order_id: Option<String>,
1135 #[builder(setter(into), default)]
1140 pub pending_price: Option<rust_decimal::Decimal>,
1141 #[builder(setter(into), default)]
1146 pub pending_stop_price: Option<rust_decimal::Decimal>,
1147 #[builder(setter(into), default)]
1152 pub pending_trailing_delta: Option<rust_decimal::Decimal>,
1153 #[builder(setter(into), default)]
1157 pub pending_iceberg_qty: Option<rust_decimal::Decimal>,
1158 #[builder(setter(into), default)]
1162 pub pending_time_in_force: Option<String>,
1163}
1164
1165impl MarginAccountNewOtoParams {
1166 #[must_use]
1181 pub fn builder(
1182 symbol: String,
1183 working_type: String,
1184 working_side: String,
1185 working_price: rust_decimal::Decimal,
1186 working_quantity: rust_decimal::Decimal,
1187 working_iceberg_qty: rust_decimal::Decimal,
1188 pending_type: String,
1189 pending_side: String,
1190 pending_quantity: rust_decimal::Decimal,
1191 ) -> MarginAccountNewOtoParamsBuilder {
1192 MarginAccountNewOtoParamsBuilder::default()
1193 .symbol(symbol)
1194 .working_type(working_type)
1195 .working_side(working_side)
1196 .working_price(working_price)
1197 .working_quantity(working_quantity)
1198 .working_iceberg_qty(working_iceberg_qty)
1199 .pending_type(pending_type)
1200 .pending_side(pending_side)
1201 .pending_quantity(pending_quantity)
1202 }
1203}
1204#[derive(Clone, Debug, Builder)]
1209#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1210pub struct MarginAccountNewOtocoParams {
1211 #[builder(setter(into))]
1216 pub symbol: String,
1217 #[builder(setter(into))]
1221 pub working_type: String,
1222 #[builder(setter(into))]
1226 pub working_side: String,
1227 #[builder(setter(into))]
1232 pub working_price: rust_decimal::Decimal,
1233 #[builder(setter(into))]
1238 pub working_quantity: rust_decimal::Decimal,
1239 #[builder(setter(into))]
1243 pub pending_side: String,
1244 #[builder(setter(into))]
1249 pub pending_quantity: rust_decimal::Decimal,
1250 #[builder(setter(into))]
1254 pub pending_above_type: String,
1255 #[builder(setter(into), default)]
1259 pub is_isolated: Option<String>,
1260 #[builder(setter(into), default)]
1264 pub side_effect_type: Option<String>,
1265 #[builder(setter(into), default)]
1269 pub auto_repay_at_cancel: Option<bool>,
1270 #[builder(setter(into), default)]
1274 pub list_client_order_id: Option<String>,
1275 #[builder(setter(into), default)]
1279 pub new_order_resp_type: Option<MarginAccountNewOtocoNewOrderRespTypeEnum>,
1280 #[builder(setter(into), default)]
1284 pub self_trade_prevention_mode: Option<String>,
1285 #[builder(setter(into), default)]
1289 pub working_client_order_id: Option<String>,
1290 #[builder(setter(into), default)]
1294 pub working_iceberg_qty: Option<rust_decimal::Decimal>,
1295 #[builder(setter(into), default)]
1299 pub working_time_in_force: Option<String>,
1300 #[builder(setter(into), default)]
1304 pub pending_above_client_order_id: Option<String>,
1305 #[builder(setter(into), default)]
1310 pub pending_above_price: Option<rust_decimal::Decimal>,
1311 #[builder(setter(into), default)]
1316 pub pending_above_stop_price: Option<rust_decimal::Decimal>,
1317 #[builder(setter(into), default)]
1322 pub pending_above_trailing_delta: Option<rust_decimal::Decimal>,
1323 #[builder(setter(into), default)]
1327 pub pending_above_iceberg_qty: Option<rust_decimal::Decimal>,
1328 #[builder(setter(into), default)]
1333 pub pending_above_time_in_force: Option<String>,
1334 #[builder(setter(into), default)]
1338 pub pending_below_type: Option<String>,
1339 #[builder(setter(into), default)]
1343 pub pending_below_client_order_id: Option<String>,
1344 #[builder(setter(into), default)]
1349 pub pending_below_price: Option<rust_decimal::Decimal>,
1350 #[builder(setter(into), default)]
1355 pub pending_below_stop_price: Option<rust_decimal::Decimal>,
1356 #[builder(setter(into), default)]
1361 pub pending_below_trailing_delta: Option<rust_decimal::Decimal>,
1362 #[builder(setter(into), default)]
1366 pub pending_below_iceberg_qty: Option<rust_decimal::Decimal>,
1367 #[builder(setter(into), default)]
1372 pub pending_below_time_in_force: Option<String>,
1373}
1374
1375impl MarginAccountNewOtocoParams {
1376 #[must_use]
1390 pub fn builder(
1391 symbol: String,
1392 working_type: String,
1393 working_side: String,
1394 working_price: rust_decimal::Decimal,
1395 working_quantity: rust_decimal::Decimal,
1396 pending_side: String,
1397 pending_quantity: rust_decimal::Decimal,
1398 pending_above_type: String,
1399 ) -> MarginAccountNewOtocoParamsBuilder {
1400 MarginAccountNewOtocoParamsBuilder::default()
1401 .symbol(symbol)
1402 .working_type(working_type)
1403 .working_side(working_side)
1404 .working_price(working_price)
1405 .working_quantity(working_quantity)
1406 .pending_side(pending_side)
1407 .pending_quantity(pending_quantity)
1408 .pending_above_type(pending_above_type)
1409 }
1410}
1411#[derive(Clone, Debug, Builder)]
1416#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1417pub struct MarginManualLiquidationParams {
1418 #[builder(setter(into))]
1422 pub r#type: String,
1423 #[builder(setter(into), default)]
1427 pub symbol: Option<String>,
1428 #[builder(setter(into), default)]
1432 pub recv_window: Option<i64>,
1433}
1434
1435impl MarginManualLiquidationParams {
1436 #[must_use]
1443 pub fn builder(r#type: String) -> MarginManualLiquidationParamsBuilder {
1444 MarginManualLiquidationParamsBuilder::default().r#type(r#type)
1445 }
1446}
1447#[derive(Clone, Debug, Builder, Default)]
1452#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1453pub struct QueryCurrentMarginOrderCountUsageParams {
1454 #[builder(setter(into), default)]
1458 pub is_isolated: Option<String>,
1459 #[builder(setter(into), default)]
1463 pub symbol: Option<String>,
1464 #[builder(setter(into), default)]
1468 pub recv_window: Option<i64>,
1469}
1470
1471impl QueryCurrentMarginOrderCountUsageParams {
1472 #[must_use]
1475 pub fn builder() -> QueryCurrentMarginOrderCountUsageParamsBuilder {
1476 QueryCurrentMarginOrderCountUsageParamsBuilder::default()
1477 }
1478}
1479#[derive(Clone, Debug, Builder, Default)]
1484#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1485pub struct QueryMarginAccountsAllOcoParams {
1486 #[builder(setter(into), default)]
1490 pub is_isolated: Option<String>,
1491 #[builder(setter(into), default)]
1495 pub symbol: Option<String>,
1496 #[builder(setter(into), default)]
1500 pub from_id: Option<i64>,
1501 #[builder(setter(into), default)]
1505 pub start_time: Option<i64>,
1506 #[builder(setter(into), default)]
1511 pub end_time: Option<i64>,
1512 #[builder(setter(into), default)]
1516 pub limit: Option<i64>,
1517 #[builder(setter(into), default)]
1521 pub recv_window: Option<i64>,
1522}
1523
1524impl QueryMarginAccountsAllOcoParams {
1525 #[must_use]
1528 pub fn builder() -> QueryMarginAccountsAllOcoParamsBuilder {
1529 QueryMarginAccountsAllOcoParamsBuilder::default()
1530 }
1531}
1532#[derive(Clone, Debug, Builder)]
1537#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1538pub struct QueryMarginAccountsAllOrdersParams {
1539 #[builder(setter(into))]
1544 pub symbol: String,
1545 #[builder(setter(into), default)]
1549 pub is_isolated: Option<String>,
1550 #[builder(setter(into), default)]
1555 pub order_id: Option<i64>,
1556 #[builder(setter(into), default)]
1560 pub start_time: Option<i64>,
1561 #[builder(setter(into), default)]
1566 pub end_time: Option<i64>,
1567 #[builder(setter(into), default)]
1571 pub limit: Option<i64>,
1572 #[builder(setter(into), default)]
1576 pub recv_window: Option<i64>,
1577}
1578
1579impl QueryMarginAccountsAllOrdersParams {
1580 #[must_use]
1587 pub fn builder(symbol: String) -> QueryMarginAccountsAllOrdersParamsBuilder {
1588 QueryMarginAccountsAllOrdersParamsBuilder::default().symbol(symbol)
1589 }
1590}
1591#[derive(Clone, Debug, Builder, Default)]
1596#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1597pub struct QueryMarginAccountsOcoParams {
1598 #[builder(setter(into), default)]
1602 pub is_isolated: Option<String>,
1603 #[builder(setter(into), default)]
1607 pub symbol: Option<String>,
1608 #[builder(setter(into), default)]
1612 pub order_list_id: Option<i64>,
1613 #[builder(setter(into), default)]
1618 pub orig_client_order_id: Option<String>,
1619 #[builder(setter(into), default)]
1623 pub recv_window: Option<i64>,
1624}
1625
1626impl QueryMarginAccountsOcoParams {
1627 #[must_use]
1630 pub fn builder() -> QueryMarginAccountsOcoParamsBuilder {
1631 QueryMarginAccountsOcoParamsBuilder::default()
1632 }
1633}
1634#[derive(Clone, Debug, Builder, Default)]
1639#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1640pub struct QueryMarginAccountsOpenOcoParams {
1641 #[builder(setter(into), default)]
1645 pub is_isolated: Option<String>,
1646 #[builder(setter(into), default)]
1650 pub symbol: Option<String>,
1651 #[builder(setter(into), default)]
1655 pub recv_window: Option<i64>,
1656}
1657
1658impl QueryMarginAccountsOpenOcoParams {
1659 #[must_use]
1662 pub fn builder() -> QueryMarginAccountsOpenOcoParamsBuilder {
1663 QueryMarginAccountsOpenOcoParamsBuilder::default()
1664 }
1665}
1666#[derive(Clone, Debug, Builder, Default)]
1671#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1672pub struct QueryMarginAccountsOpenOrdersParams {
1673 #[builder(setter(into), default)]
1677 pub symbol: Option<String>,
1678 #[builder(setter(into), default)]
1682 pub is_isolated: Option<String>,
1683 #[builder(setter(into), default)]
1687 pub recv_window: Option<i64>,
1688}
1689
1690impl QueryMarginAccountsOpenOrdersParams {
1691 #[must_use]
1694 pub fn builder() -> QueryMarginAccountsOpenOrdersParamsBuilder {
1695 QueryMarginAccountsOpenOrdersParamsBuilder::default()
1696 }
1697}
1698#[derive(Clone, Debug, Builder)]
1703#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1704pub struct QueryMarginAccountsOrderParams {
1705 #[builder(setter(into))]
1710 pub symbol: String,
1711 #[builder(setter(into), default)]
1715 pub is_isolated: Option<String>,
1716 #[builder(setter(into), default)]
1721 pub order_id: Option<i64>,
1722 #[builder(setter(into), default)]
1727 pub orig_client_order_id: Option<String>,
1728 #[builder(setter(into), default)]
1732 pub recv_window: Option<i64>,
1733}
1734
1735impl QueryMarginAccountsOrderParams {
1736 #[must_use]
1743 pub fn builder(symbol: String) -> QueryMarginAccountsOrderParamsBuilder {
1744 QueryMarginAccountsOrderParamsBuilder::default().symbol(symbol)
1745 }
1746}
1747#[derive(Clone, Debug, Builder)]
1752#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1753pub struct QueryMarginAccountsTradeListParams {
1754 #[builder(setter(into))]
1759 pub symbol: String,
1760 #[builder(setter(into), default)]
1764 pub is_isolated: Option<String>,
1765 #[builder(setter(into), default)]
1770 pub order_id: Option<i64>,
1771 #[builder(setter(into), default)]
1775 pub start_time: Option<i64>,
1776 #[builder(setter(into), default)]
1781 pub end_time: Option<i64>,
1782 #[builder(setter(into), default)]
1786 pub from_id: Option<i64>,
1787 #[builder(setter(into), default)]
1791 pub limit: Option<i64>,
1792 #[builder(setter(into), default)]
1796 pub recv_window: Option<i64>,
1797}
1798
1799impl QueryMarginAccountsTradeListParams {
1800 #[must_use]
1807 pub fn builder(symbol: String) -> QueryMarginAccountsTradeListParamsBuilder {
1808 QueryMarginAccountsTradeListParamsBuilder::default().symbol(symbol)
1809 }
1810}
1811#[derive(Clone, Debug, Builder)]
1816#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1817pub struct QueryPreventedMatchesParams {
1818 #[builder(setter(into))]
1823 pub symbol: String,
1824 #[builder(setter(into), default)]
1829 pub prevented_match_id: Option<i64>,
1830 #[builder(setter(into), default)]
1835 pub order_id: Option<i64>,
1836 #[builder(setter(into), default)]
1841 pub from_prevented_match_id: Option<i64>,
1842 #[builder(setter(into), default)]
1846 pub recv_window: Option<i64>,
1847 #[builder(setter(into), default)]
1851 pub is_isolated: Option<String>,
1852}
1853
1854impl QueryPreventedMatchesParams {
1855 #[must_use]
1862 pub fn builder(symbol: String) -> QueryPreventedMatchesParamsBuilder {
1863 QueryPreventedMatchesParamsBuilder::default().symbol(symbol)
1864 }
1865}
1866#[derive(Clone, Debug, Builder, Default)]
1871#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1872pub struct QuerySpecialKeyParams {
1873 #[builder(setter(into), default)]
1877 pub symbol: Option<String>,
1878 #[builder(setter(into), default)]
1882 pub recv_window: Option<i64>,
1883}
1884
1885impl QuerySpecialKeyParams {
1886 #[must_use]
1889 pub fn builder() -> QuerySpecialKeyParamsBuilder {
1890 QuerySpecialKeyParamsBuilder::default()
1891 }
1892}
1893#[derive(Clone, Debug, Builder, Default)]
1898#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1899pub struct QuerySpecialKeyListParams {
1900 #[builder(setter(into), default)]
1904 pub symbol: Option<String>,
1905 #[builder(setter(into), default)]
1909 pub recv_window: Option<i64>,
1910}
1911
1912impl QuerySpecialKeyListParams {
1913 #[must_use]
1916 pub fn builder() -> QuerySpecialKeyListParamsBuilder {
1917 QuerySpecialKeyListParamsBuilder::default()
1918 }
1919}
1920#[derive(Clone, Debug, Builder)]
1925#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
1926pub struct SmallLiabilityExchangeParams {
1927 #[builder(setter(into))]
1931 pub asset_names: Vec<String>,
1932 #[builder(setter(into), default)]
1936 pub recv_window: Option<i64>,
1937}
1938
1939impl SmallLiabilityExchangeParams {
1940 #[must_use]
1947 pub fn builder(asset_names: Vec<String>) -> SmallLiabilityExchangeParamsBuilder {
1948 SmallLiabilityExchangeParamsBuilder::default().asset_names(asset_names)
1949 }
1950}
1951
1952#[async_trait]
1953impl TradeApi for TradeApiClient {
1954 async fn create_special_key(
1955 &self,
1956 params: CreateSpecialKeyParams,
1957 ) -> anyhow::Result<RestApiResponse<models::CreateSpecialKeyResponse>> {
1958 let CreateSpecialKeyParams {
1959 api_name,
1960 symbol,
1961 ip,
1962 public_key,
1963 permission_mode,
1964 recv_window,
1965 } = params;
1966
1967 let mut query_params = BTreeMap::new();
1968 let body_params = BTreeMap::new();
1969
1970 query_params.insert("apiName".to_string(), json!(api_name));
1971
1972 if let Some(rw) = symbol {
1973 query_params.insert("symbol".to_string(), json!(rw));
1974 }
1975
1976 if let Some(rw) = ip {
1977 query_params.insert("ip".to_string(), json!(rw));
1978 }
1979
1980 if let Some(rw) = public_key {
1981 query_params.insert("publicKey".to_string(), json!(rw));
1982 }
1983
1984 if let Some(rw) = permission_mode {
1985 query_params.insert("permissionMode".to_string(), json!(rw));
1986 }
1987
1988 if let Some(rw) = recv_window {
1989 query_params.insert("recvWindow".to_string(), json!(rw));
1990 }
1991
1992 send_request::<models::CreateSpecialKeyResponse>(
1993 &self.configuration,
1994 "/sapi/v1/margin/apiKey",
1995 reqwest::Method::POST,
1996 query_params,
1997 body_params,
1998 if HAS_TIME_UNIT {
1999 self.configuration.time_unit
2000 } else {
2001 None
2002 },
2003 true,
2004 )
2005 .await
2006 }
2007
2008 async fn delete_special_key(
2009 &self,
2010 params: DeleteSpecialKeyParams,
2011 ) -> anyhow::Result<RestApiResponse<Value>> {
2012 let DeleteSpecialKeyParams {
2013 api_name,
2014 symbol,
2015 recv_window,
2016 } = params;
2017
2018 let mut query_params = BTreeMap::new();
2019 let body_params = BTreeMap::new();
2020
2021 if let Some(rw) = api_name {
2022 query_params.insert("apiName".to_string(), json!(rw));
2023 }
2024
2025 if let Some(rw) = symbol {
2026 query_params.insert("symbol".to_string(), json!(rw));
2027 }
2028
2029 if let Some(rw) = recv_window {
2030 query_params.insert("recvWindow".to_string(), json!(rw));
2031 }
2032
2033 send_request::<Value>(
2034 &self.configuration,
2035 "/sapi/v1/margin/apiKey",
2036 reqwest::Method::DELETE,
2037 query_params,
2038 body_params,
2039 if HAS_TIME_UNIT {
2040 self.configuration.time_unit
2041 } else {
2042 None
2043 },
2044 true,
2045 )
2046 .await
2047 }
2048
2049 async fn edit_ip_for_special_key(
2050 &self,
2051 params: EditIpForSpecialKeyParams,
2052 ) -> anyhow::Result<RestApiResponse<Value>> {
2053 let EditIpForSpecialKeyParams {
2054 ip,
2055 symbol,
2056 recv_window,
2057 } = params;
2058
2059 let mut query_params = BTreeMap::new();
2060 let body_params = BTreeMap::new();
2061
2062 if let Some(rw) = symbol {
2063 query_params.insert("symbol".to_string(), json!(rw));
2064 }
2065
2066 query_params.insert("ip".to_string(), json!(ip));
2067
2068 if let Some(rw) = recv_window {
2069 query_params.insert("recvWindow".to_string(), json!(rw));
2070 }
2071
2072 send_request::<Value>(
2073 &self.configuration,
2074 "/sapi/v1/margin/apiKey/ip",
2075 reqwest::Method::PUT,
2076 query_params,
2077 body_params,
2078 if HAS_TIME_UNIT {
2079 self.configuration.time_unit
2080 } else {
2081 None
2082 },
2083 true,
2084 )
2085 .await
2086 }
2087
2088 async fn get_force_liquidation_record(
2089 &self,
2090 params: GetForceLiquidationRecordParams,
2091 ) -> anyhow::Result<RestApiResponse<models::GetForceLiquidationRecordResponse>> {
2092 let GetForceLiquidationRecordParams {
2093 start_time,
2094 end_time,
2095 isolated_symbol,
2096 current,
2097 size,
2098 recv_window,
2099 } = params;
2100
2101 let mut query_params = BTreeMap::new();
2102 let body_params = BTreeMap::new();
2103
2104 if let Some(rw) = start_time {
2105 query_params.insert("startTime".to_string(), json!(rw));
2106 }
2107
2108 if let Some(rw) = end_time {
2109 query_params.insert("endTime".to_string(), json!(rw));
2110 }
2111
2112 if let Some(rw) = isolated_symbol {
2113 query_params.insert("isolatedSymbol".to_string(), json!(rw));
2114 }
2115
2116 if let Some(rw) = current {
2117 query_params.insert("current".to_string(), json!(rw));
2118 }
2119
2120 if let Some(rw) = size {
2121 query_params.insert("size".to_string(), json!(rw));
2122 }
2123
2124 if let Some(rw) = recv_window {
2125 query_params.insert("recvWindow".to_string(), json!(rw));
2126 }
2127
2128 send_request::<models::GetForceLiquidationRecordResponse>(
2129 &self.configuration,
2130 "/sapi/v1/margin/forceLiquidationRec",
2131 reqwest::Method::GET,
2132 query_params,
2133 body_params,
2134 if HAS_TIME_UNIT {
2135 self.configuration.time_unit
2136 } else {
2137 None
2138 },
2139 true,
2140 )
2141 .await
2142 }
2143
2144 async fn get_small_liability_exchange_coin_list(
2145 &self,
2146 params: GetSmallLiabilityExchangeCoinListParams,
2147 ) -> anyhow::Result<RestApiResponse<Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>>>
2148 {
2149 let GetSmallLiabilityExchangeCoinListParams { recv_window } = params;
2150
2151 let mut query_params = BTreeMap::new();
2152 let body_params = BTreeMap::new();
2153
2154 if let Some(rw) = recv_window {
2155 query_params.insert("recvWindow".to_string(), json!(rw));
2156 }
2157
2158 send_request::<Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>>(
2159 &self.configuration,
2160 "/sapi/v1/margin/exchange-small-liability",
2161 reqwest::Method::GET,
2162 query_params,
2163 body_params,
2164 if HAS_TIME_UNIT {
2165 self.configuration.time_unit
2166 } else {
2167 None
2168 },
2169 true,
2170 )
2171 .await
2172 }
2173
2174 async fn get_small_liability_exchange_history(
2175 &self,
2176 params: GetSmallLiabilityExchangeHistoryParams,
2177 ) -> anyhow::Result<RestApiResponse<models::GetSmallLiabilityExchangeHistoryResponse>> {
2178 let GetSmallLiabilityExchangeHistoryParams {
2179 current,
2180 size,
2181 start_time,
2182 end_time,
2183 recv_window,
2184 } = params;
2185
2186 let mut query_params = BTreeMap::new();
2187 let body_params = BTreeMap::new();
2188
2189 query_params.insert("current".to_string(), json!(current));
2190
2191 query_params.insert("size".to_string(), json!(size));
2192
2193 if let Some(rw) = start_time {
2194 query_params.insert("startTime".to_string(), json!(rw));
2195 }
2196
2197 if let Some(rw) = end_time {
2198 query_params.insert("endTime".to_string(), json!(rw));
2199 }
2200
2201 if let Some(rw) = recv_window {
2202 query_params.insert("recvWindow".to_string(), json!(rw));
2203 }
2204
2205 send_request::<models::GetSmallLiabilityExchangeHistoryResponse>(
2206 &self.configuration,
2207 "/sapi/v1/margin/exchange-small-liability-history",
2208 reqwest::Method::GET,
2209 query_params,
2210 body_params,
2211 if HAS_TIME_UNIT {
2212 self.configuration.time_unit
2213 } else {
2214 None
2215 },
2216 true,
2217 )
2218 .await
2219 }
2220
2221 async fn margin_account_cancel_all_open_orders_on_a_symbol(
2222 &self,
2223 params: MarginAccountCancelAllOpenOrdersOnASymbolParams,
2224 ) -> anyhow::Result<
2225 RestApiResponse<Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>>,
2226 > {
2227 let MarginAccountCancelAllOpenOrdersOnASymbolParams {
2228 symbol,
2229 is_isolated,
2230 recv_window,
2231 } = params;
2232
2233 let mut query_params = BTreeMap::new();
2234 let body_params = BTreeMap::new();
2235
2236 query_params.insert("symbol".to_string(), json!(symbol));
2237
2238 if let Some(rw) = is_isolated {
2239 query_params.insert("isIsolated".to_string(), json!(rw));
2240 }
2241
2242 if let Some(rw) = recv_window {
2243 query_params.insert("recvWindow".to_string(), json!(rw));
2244 }
2245
2246 send_request::<Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>>(
2247 &self.configuration,
2248 "/sapi/v1/margin/openOrders",
2249 reqwest::Method::DELETE,
2250 query_params,
2251 body_params,
2252 if HAS_TIME_UNIT {
2253 self.configuration.time_unit
2254 } else {
2255 None
2256 },
2257 true,
2258 )
2259 .await
2260 }
2261
2262 async fn margin_account_cancel_oco(
2263 &self,
2264 params: MarginAccountCancelOcoParams,
2265 ) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOcoResponse>> {
2266 let MarginAccountCancelOcoParams {
2267 symbol,
2268 is_isolated,
2269 order_list_id,
2270 list_client_order_id,
2271 new_client_order_id,
2272 recv_window,
2273 } = params;
2274
2275 let mut query_params = BTreeMap::new();
2276 let body_params = BTreeMap::new();
2277
2278 query_params.insert("symbol".to_string(), json!(symbol));
2279
2280 if let Some(rw) = is_isolated {
2281 query_params.insert("isIsolated".to_string(), json!(rw));
2282 }
2283
2284 if let Some(rw) = order_list_id {
2285 query_params.insert("orderListId".to_string(), json!(rw));
2286 }
2287
2288 if let Some(rw) = list_client_order_id {
2289 query_params.insert("listClientOrderId".to_string(), json!(rw));
2290 }
2291
2292 if let Some(rw) = new_client_order_id {
2293 query_params.insert("newClientOrderId".to_string(), json!(rw));
2294 }
2295
2296 if let Some(rw) = recv_window {
2297 query_params.insert("recvWindow".to_string(), json!(rw));
2298 }
2299
2300 send_request::<models::MarginAccountCancelOcoResponse>(
2301 &self.configuration,
2302 "/sapi/v1/margin/orderList",
2303 reqwest::Method::DELETE,
2304 query_params,
2305 body_params,
2306 if HAS_TIME_UNIT {
2307 self.configuration.time_unit
2308 } else {
2309 None
2310 },
2311 true,
2312 )
2313 .await
2314 }
2315
2316 async fn margin_account_cancel_order(
2317 &self,
2318 params: MarginAccountCancelOrderParams,
2319 ) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOrderResponse>> {
2320 let MarginAccountCancelOrderParams {
2321 symbol,
2322 is_isolated,
2323 order_id,
2324 orig_client_order_id,
2325 new_client_order_id,
2326 recv_window,
2327 } = params;
2328
2329 let mut query_params = BTreeMap::new();
2330 let body_params = BTreeMap::new();
2331
2332 query_params.insert("symbol".to_string(), json!(symbol));
2333
2334 if let Some(rw) = is_isolated {
2335 query_params.insert("isIsolated".to_string(), json!(rw));
2336 }
2337
2338 if let Some(rw) = order_id {
2339 query_params.insert("orderId".to_string(), json!(rw));
2340 }
2341
2342 if let Some(rw) = orig_client_order_id {
2343 query_params.insert("origClientOrderId".to_string(), json!(rw));
2344 }
2345
2346 if let Some(rw) = new_client_order_id {
2347 query_params.insert("newClientOrderId".to_string(), json!(rw));
2348 }
2349
2350 if let Some(rw) = recv_window {
2351 query_params.insert("recvWindow".to_string(), json!(rw));
2352 }
2353
2354 send_request::<models::MarginAccountCancelOrderResponse>(
2355 &self.configuration,
2356 "/sapi/v1/margin/order",
2357 reqwest::Method::DELETE,
2358 query_params,
2359 body_params,
2360 if HAS_TIME_UNIT {
2361 self.configuration.time_unit
2362 } else {
2363 None
2364 },
2365 true,
2366 )
2367 .await
2368 }
2369
2370 async fn margin_account_new_oco(
2371 &self,
2372 params: MarginAccountNewOcoParams,
2373 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOcoResponse>> {
2374 let MarginAccountNewOcoParams {
2375 symbol,
2376 side,
2377 quantity,
2378 price,
2379 stop_price,
2380 is_isolated,
2381 list_client_order_id,
2382 limit_client_order_id,
2383 limit_iceberg_qty,
2384 stop_client_order_id,
2385 stop_limit_price,
2386 stop_iceberg_qty,
2387 stop_limit_time_in_force,
2388 new_order_resp_type,
2389 side_effect_type,
2390 self_trade_prevention_mode,
2391 auto_repay_at_cancel,
2392 recv_window,
2393 } = params;
2394
2395 let mut query_params = BTreeMap::new();
2396 let body_params = BTreeMap::new();
2397
2398 query_params.insert("symbol".to_string(), json!(symbol));
2399
2400 if let Some(rw) = is_isolated {
2401 query_params.insert("isIsolated".to_string(), json!(rw));
2402 }
2403
2404 if let Some(rw) = list_client_order_id {
2405 query_params.insert("listClientOrderId".to_string(), json!(rw));
2406 }
2407
2408 query_params.insert("side".to_string(), json!(side));
2409
2410 query_params.insert("quantity".to_string(), json!(quantity));
2411
2412 if let Some(rw) = limit_client_order_id {
2413 query_params.insert("limitClientOrderId".to_string(), json!(rw));
2414 }
2415
2416 query_params.insert("price".to_string(), json!(price));
2417
2418 if let Some(rw) = limit_iceberg_qty {
2419 query_params.insert("limitIcebergQty".to_string(), json!(rw));
2420 }
2421
2422 if let Some(rw) = stop_client_order_id {
2423 query_params.insert("stopClientOrderId".to_string(), json!(rw));
2424 }
2425
2426 query_params.insert("stopPrice".to_string(), json!(stop_price));
2427
2428 if let Some(rw) = stop_limit_price {
2429 query_params.insert("stopLimitPrice".to_string(), json!(rw));
2430 }
2431
2432 if let Some(rw) = stop_iceberg_qty {
2433 query_params.insert("stopIcebergQty".to_string(), json!(rw));
2434 }
2435
2436 if let Some(rw) = stop_limit_time_in_force {
2437 query_params.insert("stopLimitTimeInForce".to_string(), json!(rw));
2438 }
2439
2440 if let Some(rw) = new_order_resp_type {
2441 query_params.insert("newOrderRespType".to_string(), json!(rw));
2442 }
2443
2444 if let Some(rw) = side_effect_type {
2445 query_params.insert("sideEffectType".to_string(), json!(rw));
2446 }
2447
2448 if let Some(rw) = self_trade_prevention_mode {
2449 query_params.insert("selfTradePreventionMode".to_string(), json!(rw));
2450 }
2451
2452 if let Some(rw) = auto_repay_at_cancel {
2453 query_params.insert("autoRepayAtCancel".to_string(), json!(rw));
2454 }
2455
2456 if let Some(rw) = recv_window {
2457 query_params.insert("recvWindow".to_string(), json!(rw));
2458 }
2459
2460 send_request::<models::MarginAccountNewOcoResponse>(
2461 &self.configuration,
2462 "/sapi/v1/margin/order/oco",
2463 reqwest::Method::POST,
2464 query_params,
2465 body_params,
2466 if HAS_TIME_UNIT {
2467 self.configuration.time_unit
2468 } else {
2469 None
2470 },
2471 true,
2472 )
2473 .await
2474 }
2475
2476 async fn margin_account_new_order(
2477 &self,
2478 params: MarginAccountNewOrderParams,
2479 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOrderResponse>> {
2480 let MarginAccountNewOrderParams {
2481 symbol,
2482 side,
2483 r#type,
2484 is_isolated,
2485 quantity,
2486 quote_order_qty,
2487 price,
2488 stop_price,
2489 new_client_order_id,
2490 iceberg_qty,
2491 new_order_resp_type,
2492 side_effect_type,
2493 time_in_force,
2494 self_trade_prevention_mode,
2495 auto_repay_at_cancel,
2496 recv_window,
2497 } = params;
2498
2499 let mut query_params = BTreeMap::new();
2500 let body_params = BTreeMap::new();
2501
2502 query_params.insert("symbol".to_string(), json!(symbol));
2503
2504 if let Some(rw) = is_isolated {
2505 query_params.insert("isIsolated".to_string(), json!(rw));
2506 }
2507
2508 query_params.insert("side".to_string(), json!(side));
2509
2510 query_params.insert("type".to_string(), json!(r#type));
2511
2512 if let Some(rw) = quantity {
2513 query_params.insert("quantity".to_string(), json!(rw));
2514 }
2515
2516 if let Some(rw) = quote_order_qty {
2517 query_params.insert("quoteOrderQty".to_string(), json!(rw));
2518 }
2519
2520 if let Some(rw) = price {
2521 query_params.insert("price".to_string(), json!(rw));
2522 }
2523
2524 if let Some(rw) = stop_price {
2525 query_params.insert("stopPrice".to_string(), json!(rw));
2526 }
2527
2528 if let Some(rw) = new_client_order_id {
2529 query_params.insert("newClientOrderId".to_string(), json!(rw));
2530 }
2531
2532 if let Some(rw) = iceberg_qty {
2533 query_params.insert("icebergQty".to_string(), json!(rw));
2534 }
2535
2536 if let Some(rw) = new_order_resp_type {
2537 query_params.insert("newOrderRespType".to_string(), json!(rw));
2538 }
2539
2540 if let Some(rw) = side_effect_type {
2541 query_params.insert("sideEffectType".to_string(), json!(rw));
2542 }
2543
2544 if let Some(rw) = time_in_force {
2545 query_params.insert("timeInForce".to_string(), json!(rw));
2546 }
2547
2548 if let Some(rw) = self_trade_prevention_mode {
2549 query_params.insert("selfTradePreventionMode".to_string(), json!(rw));
2550 }
2551
2552 if let Some(rw) = auto_repay_at_cancel {
2553 query_params.insert("autoRepayAtCancel".to_string(), json!(rw));
2554 }
2555
2556 if let Some(rw) = recv_window {
2557 query_params.insert("recvWindow".to_string(), json!(rw));
2558 }
2559
2560 send_request::<models::MarginAccountNewOrderResponse>(
2561 &self.configuration,
2562 "/sapi/v1/margin/order",
2563 reqwest::Method::POST,
2564 query_params,
2565 body_params,
2566 if HAS_TIME_UNIT {
2567 self.configuration.time_unit
2568 } else {
2569 None
2570 },
2571 true,
2572 )
2573 .await
2574 }
2575
2576 async fn margin_account_new_oto(
2577 &self,
2578 params: MarginAccountNewOtoParams,
2579 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtoResponse>> {
2580 let MarginAccountNewOtoParams {
2581 symbol,
2582 working_type,
2583 working_side,
2584 working_price,
2585 working_quantity,
2586 working_iceberg_qty,
2587 pending_type,
2588 pending_side,
2589 pending_quantity,
2590 is_isolated,
2591 list_client_order_id,
2592 new_order_resp_type,
2593 side_effect_type,
2594 self_trade_prevention_mode,
2595 auto_repay_at_cancel,
2596 working_client_order_id,
2597 working_time_in_force,
2598 pending_client_order_id,
2599 pending_price,
2600 pending_stop_price,
2601 pending_trailing_delta,
2602 pending_iceberg_qty,
2603 pending_time_in_force,
2604 } = params;
2605
2606 let mut query_params = BTreeMap::new();
2607 let body_params = BTreeMap::new();
2608
2609 query_params.insert("symbol".to_string(), json!(symbol));
2610
2611 if let Some(rw) = is_isolated {
2612 query_params.insert("isIsolated".to_string(), json!(rw));
2613 }
2614
2615 if let Some(rw) = list_client_order_id {
2616 query_params.insert("listClientOrderId".to_string(), json!(rw));
2617 }
2618
2619 if let Some(rw) = new_order_resp_type {
2620 query_params.insert("newOrderRespType".to_string(), json!(rw));
2621 }
2622
2623 if let Some(rw) = side_effect_type {
2624 query_params.insert("sideEffectType".to_string(), json!(rw));
2625 }
2626
2627 if let Some(rw) = self_trade_prevention_mode {
2628 query_params.insert("selfTradePreventionMode".to_string(), json!(rw));
2629 }
2630
2631 if let Some(rw) = auto_repay_at_cancel {
2632 query_params.insert("autoRepayAtCancel".to_string(), json!(rw));
2633 }
2634
2635 query_params.insert("workingType".to_string(), json!(working_type));
2636
2637 query_params.insert("workingSide".to_string(), json!(working_side));
2638
2639 if let Some(rw) = working_client_order_id {
2640 query_params.insert("workingClientOrderId".to_string(), json!(rw));
2641 }
2642
2643 query_params.insert("workingPrice".to_string(), json!(working_price));
2644
2645 query_params.insert("workingQuantity".to_string(), json!(working_quantity));
2646
2647 query_params.insert("workingIcebergQty".to_string(), json!(working_iceberg_qty));
2648
2649 if let Some(rw) = working_time_in_force {
2650 query_params.insert("workingTimeInForce".to_string(), json!(rw));
2651 }
2652
2653 query_params.insert("pendingType".to_string(), json!(pending_type));
2654
2655 query_params.insert("pendingSide".to_string(), json!(pending_side));
2656
2657 if let Some(rw) = pending_client_order_id {
2658 query_params.insert("pendingClientOrderId".to_string(), json!(rw));
2659 }
2660
2661 if let Some(rw) = pending_price {
2662 query_params.insert("pendingPrice".to_string(), json!(rw));
2663 }
2664
2665 if let Some(rw) = pending_stop_price {
2666 query_params.insert("pendingStopPrice".to_string(), json!(rw));
2667 }
2668
2669 if let Some(rw) = pending_trailing_delta {
2670 query_params.insert("pendingTrailingDelta".to_string(), json!(rw));
2671 }
2672
2673 query_params.insert("pendingQuantity".to_string(), json!(pending_quantity));
2674
2675 if let Some(rw) = pending_iceberg_qty {
2676 query_params.insert("pendingIcebergQty".to_string(), json!(rw));
2677 }
2678
2679 if let Some(rw) = pending_time_in_force {
2680 query_params.insert("pendingTimeInForce".to_string(), json!(rw));
2681 }
2682
2683 send_request::<models::MarginAccountNewOtoResponse>(
2684 &self.configuration,
2685 "/sapi/v1/margin/order/oto",
2686 reqwest::Method::POST,
2687 query_params,
2688 body_params,
2689 if HAS_TIME_UNIT {
2690 self.configuration.time_unit
2691 } else {
2692 None
2693 },
2694 true,
2695 )
2696 .await
2697 }
2698
2699 async fn margin_account_new_otoco(
2700 &self,
2701 params: MarginAccountNewOtocoParams,
2702 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtocoResponse>> {
2703 let MarginAccountNewOtocoParams {
2704 symbol,
2705 working_type,
2706 working_side,
2707 working_price,
2708 working_quantity,
2709 pending_side,
2710 pending_quantity,
2711 pending_above_type,
2712 is_isolated,
2713 side_effect_type,
2714 auto_repay_at_cancel,
2715 list_client_order_id,
2716 new_order_resp_type,
2717 self_trade_prevention_mode,
2718 working_client_order_id,
2719 working_iceberg_qty,
2720 working_time_in_force,
2721 pending_above_client_order_id,
2722 pending_above_price,
2723 pending_above_stop_price,
2724 pending_above_trailing_delta,
2725 pending_above_iceberg_qty,
2726 pending_above_time_in_force,
2727 pending_below_type,
2728 pending_below_client_order_id,
2729 pending_below_price,
2730 pending_below_stop_price,
2731 pending_below_trailing_delta,
2732 pending_below_iceberg_qty,
2733 pending_below_time_in_force,
2734 } = params;
2735
2736 let mut query_params = BTreeMap::new();
2737 let body_params = BTreeMap::new();
2738
2739 query_params.insert("symbol".to_string(), json!(symbol));
2740
2741 if let Some(rw) = is_isolated {
2742 query_params.insert("isIsolated".to_string(), json!(rw));
2743 }
2744
2745 if let Some(rw) = side_effect_type {
2746 query_params.insert("sideEffectType".to_string(), json!(rw));
2747 }
2748
2749 if let Some(rw) = auto_repay_at_cancel {
2750 query_params.insert("autoRepayAtCancel".to_string(), json!(rw));
2751 }
2752
2753 if let Some(rw) = list_client_order_id {
2754 query_params.insert("listClientOrderId".to_string(), json!(rw));
2755 }
2756
2757 if let Some(rw) = new_order_resp_type {
2758 query_params.insert("newOrderRespType".to_string(), json!(rw));
2759 }
2760
2761 if let Some(rw) = self_trade_prevention_mode {
2762 query_params.insert("selfTradePreventionMode".to_string(), json!(rw));
2763 }
2764
2765 query_params.insert("workingType".to_string(), json!(working_type));
2766
2767 query_params.insert("workingSide".to_string(), json!(working_side));
2768
2769 if let Some(rw) = working_client_order_id {
2770 query_params.insert("workingClientOrderId".to_string(), json!(rw));
2771 }
2772
2773 query_params.insert("workingPrice".to_string(), json!(working_price));
2774
2775 query_params.insert("workingQuantity".to_string(), json!(working_quantity));
2776
2777 if let Some(rw) = working_iceberg_qty {
2778 query_params.insert("workingIcebergQty".to_string(), json!(rw));
2779 }
2780
2781 if let Some(rw) = working_time_in_force {
2782 query_params.insert("workingTimeInForce".to_string(), json!(rw));
2783 }
2784
2785 query_params.insert("pendingSide".to_string(), json!(pending_side));
2786
2787 query_params.insert("pendingQuantity".to_string(), json!(pending_quantity));
2788
2789 query_params.insert("pendingAboveType".to_string(), json!(pending_above_type));
2790
2791 if let Some(rw) = pending_above_client_order_id {
2792 query_params.insert("pendingAboveClientOrderId".to_string(), json!(rw));
2793 }
2794
2795 if let Some(rw) = pending_above_price {
2796 query_params.insert("pendingAbovePrice".to_string(), json!(rw));
2797 }
2798
2799 if let Some(rw) = pending_above_stop_price {
2800 query_params.insert("pendingAboveStopPrice".to_string(), json!(rw));
2801 }
2802
2803 if let Some(rw) = pending_above_trailing_delta {
2804 query_params.insert("pendingAboveTrailingDelta".to_string(), json!(rw));
2805 }
2806
2807 if let Some(rw) = pending_above_iceberg_qty {
2808 query_params.insert("pendingAboveIcebergQty".to_string(), json!(rw));
2809 }
2810
2811 if let Some(rw) = pending_above_time_in_force {
2812 query_params.insert("pendingAboveTimeInForce".to_string(), json!(rw));
2813 }
2814
2815 if let Some(rw) = pending_below_type {
2816 query_params.insert("pendingBelowType".to_string(), json!(rw));
2817 }
2818
2819 if let Some(rw) = pending_below_client_order_id {
2820 query_params.insert("pendingBelowClientOrderId".to_string(), json!(rw));
2821 }
2822
2823 if let Some(rw) = pending_below_price {
2824 query_params.insert("pendingBelowPrice".to_string(), json!(rw));
2825 }
2826
2827 if let Some(rw) = pending_below_stop_price {
2828 query_params.insert("pendingBelowStopPrice".to_string(), json!(rw));
2829 }
2830
2831 if let Some(rw) = pending_below_trailing_delta {
2832 query_params.insert("pendingBelowTrailingDelta".to_string(), json!(rw));
2833 }
2834
2835 if let Some(rw) = pending_below_iceberg_qty {
2836 query_params.insert("pendingBelowIcebergQty".to_string(), json!(rw));
2837 }
2838
2839 if let Some(rw) = pending_below_time_in_force {
2840 query_params.insert("pendingBelowTimeInForce".to_string(), json!(rw));
2841 }
2842
2843 send_request::<models::MarginAccountNewOtocoResponse>(
2844 &self.configuration,
2845 "/sapi/v1/margin/order/otoco",
2846 reqwest::Method::POST,
2847 query_params,
2848 body_params,
2849 if HAS_TIME_UNIT {
2850 self.configuration.time_unit
2851 } else {
2852 None
2853 },
2854 true,
2855 )
2856 .await
2857 }
2858
2859 async fn margin_manual_liquidation(
2860 &self,
2861 params: MarginManualLiquidationParams,
2862 ) -> anyhow::Result<RestApiResponse<models::MarginManualLiquidationResponse>> {
2863 let MarginManualLiquidationParams {
2864 r#type,
2865 symbol,
2866 recv_window,
2867 } = params;
2868
2869 let mut query_params = BTreeMap::new();
2870 let body_params = BTreeMap::new();
2871
2872 query_params.insert("type".to_string(), json!(r#type));
2873
2874 if let Some(rw) = symbol {
2875 query_params.insert("symbol".to_string(), json!(rw));
2876 }
2877
2878 if let Some(rw) = recv_window {
2879 query_params.insert("recvWindow".to_string(), json!(rw));
2880 }
2881
2882 send_request::<models::MarginManualLiquidationResponse>(
2883 &self.configuration,
2884 "/sapi/v1/margin/manual-liquidation",
2885 reqwest::Method::POST,
2886 query_params,
2887 body_params,
2888 if HAS_TIME_UNIT {
2889 self.configuration.time_unit
2890 } else {
2891 None
2892 },
2893 true,
2894 )
2895 .await
2896 }
2897
2898 async fn query_current_margin_order_count_usage(
2899 &self,
2900 params: QueryCurrentMarginOrderCountUsageParams,
2901 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>>>
2902 {
2903 let QueryCurrentMarginOrderCountUsageParams {
2904 is_isolated,
2905 symbol,
2906 recv_window,
2907 } = params;
2908
2909 let mut query_params = BTreeMap::new();
2910 let body_params = BTreeMap::new();
2911
2912 if let Some(rw) = is_isolated {
2913 query_params.insert("isIsolated".to_string(), json!(rw));
2914 }
2915
2916 if let Some(rw) = symbol {
2917 query_params.insert("symbol".to_string(), json!(rw));
2918 }
2919
2920 if let Some(rw) = recv_window {
2921 query_params.insert("recvWindow".to_string(), json!(rw));
2922 }
2923
2924 send_request::<Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>>(
2925 &self.configuration,
2926 "/sapi/v1/margin/rateLimit/order",
2927 reqwest::Method::GET,
2928 query_params,
2929 body_params,
2930 if HAS_TIME_UNIT {
2931 self.configuration.time_unit
2932 } else {
2933 None
2934 },
2935 true,
2936 )
2937 .await
2938 }
2939
2940 async fn query_margin_accounts_all_oco(
2941 &self,
2942 params: QueryMarginAccountsAllOcoParams,
2943 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOcoResponseInner>>> {
2944 let QueryMarginAccountsAllOcoParams {
2945 is_isolated,
2946 symbol,
2947 from_id,
2948 start_time,
2949 end_time,
2950 limit,
2951 recv_window,
2952 } = params;
2953
2954 let mut query_params = BTreeMap::new();
2955 let body_params = BTreeMap::new();
2956
2957 if let Some(rw) = is_isolated {
2958 query_params.insert("isIsolated".to_string(), json!(rw));
2959 }
2960
2961 if let Some(rw) = symbol {
2962 query_params.insert("symbol".to_string(), json!(rw));
2963 }
2964
2965 if let Some(rw) = from_id {
2966 query_params.insert("fromId".to_string(), json!(rw));
2967 }
2968
2969 if let Some(rw) = start_time {
2970 query_params.insert("startTime".to_string(), json!(rw));
2971 }
2972
2973 if let Some(rw) = end_time {
2974 query_params.insert("endTime".to_string(), json!(rw));
2975 }
2976
2977 if let Some(rw) = limit {
2978 query_params.insert("limit".to_string(), json!(rw));
2979 }
2980
2981 if let Some(rw) = recv_window {
2982 query_params.insert("recvWindow".to_string(), json!(rw));
2983 }
2984
2985 send_request::<Vec<models::QueryMarginAccountsAllOcoResponseInner>>(
2986 &self.configuration,
2987 "/sapi/v1/margin/allOrderList",
2988 reqwest::Method::GET,
2989 query_params,
2990 body_params,
2991 if HAS_TIME_UNIT {
2992 self.configuration.time_unit
2993 } else {
2994 None
2995 },
2996 true,
2997 )
2998 .await
2999 }
3000
3001 async fn query_margin_accounts_all_orders(
3002 &self,
3003 params: QueryMarginAccountsAllOrdersParams,
3004 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOrdersResponseInner>>>
3005 {
3006 let QueryMarginAccountsAllOrdersParams {
3007 symbol,
3008 is_isolated,
3009 order_id,
3010 start_time,
3011 end_time,
3012 limit,
3013 recv_window,
3014 } = params;
3015
3016 let mut query_params = BTreeMap::new();
3017 let body_params = BTreeMap::new();
3018
3019 query_params.insert("symbol".to_string(), json!(symbol));
3020
3021 if let Some(rw) = is_isolated {
3022 query_params.insert("isIsolated".to_string(), json!(rw));
3023 }
3024
3025 if let Some(rw) = order_id {
3026 query_params.insert("orderId".to_string(), json!(rw));
3027 }
3028
3029 if let Some(rw) = start_time {
3030 query_params.insert("startTime".to_string(), json!(rw));
3031 }
3032
3033 if let Some(rw) = end_time {
3034 query_params.insert("endTime".to_string(), json!(rw));
3035 }
3036
3037 if let Some(rw) = limit {
3038 query_params.insert("limit".to_string(), json!(rw));
3039 }
3040
3041 if let Some(rw) = recv_window {
3042 query_params.insert("recvWindow".to_string(), json!(rw));
3043 }
3044
3045 send_request::<Vec<models::QueryMarginAccountsAllOrdersResponseInner>>(
3046 &self.configuration,
3047 "/sapi/v1/margin/allOrders",
3048 reqwest::Method::GET,
3049 query_params,
3050 body_params,
3051 if HAS_TIME_UNIT {
3052 self.configuration.time_unit
3053 } else {
3054 None
3055 },
3056 true,
3057 )
3058 .await
3059 }
3060
3061 async fn query_margin_accounts_oco(
3062 &self,
3063 params: QueryMarginAccountsOcoParams,
3064 ) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOcoResponse>> {
3065 let QueryMarginAccountsOcoParams {
3066 is_isolated,
3067 symbol,
3068 order_list_id,
3069 orig_client_order_id,
3070 recv_window,
3071 } = params;
3072
3073 let mut query_params = BTreeMap::new();
3074 let body_params = BTreeMap::new();
3075
3076 if let Some(rw) = is_isolated {
3077 query_params.insert("isIsolated".to_string(), json!(rw));
3078 }
3079
3080 if let Some(rw) = symbol {
3081 query_params.insert("symbol".to_string(), json!(rw));
3082 }
3083
3084 if let Some(rw) = order_list_id {
3085 query_params.insert("orderListId".to_string(), json!(rw));
3086 }
3087
3088 if let Some(rw) = orig_client_order_id {
3089 query_params.insert("origClientOrderId".to_string(), json!(rw));
3090 }
3091
3092 if let Some(rw) = recv_window {
3093 query_params.insert("recvWindow".to_string(), json!(rw));
3094 }
3095
3096 send_request::<models::QueryMarginAccountsOcoResponse>(
3097 &self.configuration,
3098 "/sapi/v1/margin/orderList",
3099 reqwest::Method::GET,
3100 query_params,
3101 body_params,
3102 if HAS_TIME_UNIT {
3103 self.configuration.time_unit
3104 } else {
3105 None
3106 },
3107 true,
3108 )
3109 .await
3110 }
3111
3112 async fn query_margin_accounts_open_oco(
3113 &self,
3114 params: QueryMarginAccountsOpenOcoParams,
3115 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOcoResponseInner>>> {
3116 let QueryMarginAccountsOpenOcoParams {
3117 is_isolated,
3118 symbol,
3119 recv_window,
3120 } = params;
3121
3122 let mut query_params = BTreeMap::new();
3123 let body_params = BTreeMap::new();
3124
3125 if let Some(rw) = is_isolated {
3126 query_params.insert("isIsolated".to_string(), json!(rw));
3127 }
3128
3129 if let Some(rw) = symbol {
3130 query_params.insert("symbol".to_string(), json!(rw));
3131 }
3132
3133 if let Some(rw) = recv_window {
3134 query_params.insert("recvWindow".to_string(), json!(rw));
3135 }
3136
3137 send_request::<Vec<models::QueryMarginAccountsOpenOcoResponseInner>>(
3138 &self.configuration,
3139 "/sapi/v1/margin/openOrderList",
3140 reqwest::Method::GET,
3141 query_params,
3142 body_params,
3143 if HAS_TIME_UNIT {
3144 self.configuration.time_unit
3145 } else {
3146 None
3147 },
3148 true,
3149 )
3150 .await
3151 }
3152
3153 async fn query_margin_accounts_open_orders(
3154 &self,
3155 params: QueryMarginAccountsOpenOrdersParams,
3156 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOrdersResponseInner>>>
3157 {
3158 let QueryMarginAccountsOpenOrdersParams {
3159 symbol,
3160 is_isolated,
3161 recv_window,
3162 } = params;
3163
3164 let mut query_params = BTreeMap::new();
3165 let body_params = BTreeMap::new();
3166
3167 if let Some(rw) = symbol {
3168 query_params.insert("symbol".to_string(), json!(rw));
3169 }
3170
3171 if let Some(rw) = is_isolated {
3172 query_params.insert("isIsolated".to_string(), json!(rw));
3173 }
3174
3175 if let Some(rw) = recv_window {
3176 query_params.insert("recvWindow".to_string(), json!(rw));
3177 }
3178
3179 send_request::<Vec<models::QueryMarginAccountsOpenOrdersResponseInner>>(
3180 &self.configuration,
3181 "/sapi/v1/margin/openOrders",
3182 reqwest::Method::GET,
3183 query_params,
3184 body_params,
3185 if HAS_TIME_UNIT {
3186 self.configuration.time_unit
3187 } else {
3188 None
3189 },
3190 true,
3191 )
3192 .await
3193 }
3194
3195 async fn query_margin_accounts_order(
3196 &self,
3197 params: QueryMarginAccountsOrderParams,
3198 ) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOrderResponse>> {
3199 let QueryMarginAccountsOrderParams {
3200 symbol,
3201 is_isolated,
3202 order_id,
3203 orig_client_order_id,
3204 recv_window,
3205 } = params;
3206
3207 let mut query_params = BTreeMap::new();
3208 let body_params = BTreeMap::new();
3209
3210 query_params.insert("symbol".to_string(), json!(symbol));
3211
3212 if let Some(rw) = is_isolated {
3213 query_params.insert("isIsolated".to_string(), json!(rw));
3214 }
3215
3216 if let Some(rw) = order_id {
3217 query_params.insert("orderId".to_string(), json!(rw));
3218 }
3219
3220 if let Some(rw) = orig_client_order_id {
3221 query_params.insert("origClientOrderId".to_string(), json!(rw));
3222 }
3223
3224 if let Some(rw) = recv_window {
3225 query_params.insert("recvWindow".to_string(), json!(rw));
3226 }
3227
3228 send_request::<models::QueryMarginAccountsOrderResponse>(
3229 &self.configuration,
3230 "/sapi/v1/margin/order",
3231 reqwest::Method::GET,
3232 query_params,
3233 body_params,
3234 if HAS_TIME_UNIT {
3235 self.configuration.time_unit
3236 } else {
3237 None
3238 },
3239 true,
3240 )
3241 .await
3242 }
3243
3244 async fn query_margin_accounts_trade_list(
3245 &self,
3246 params: QueryMarginAccountsTradeListParams,
3247 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsTradeListResponseInner>>>
3248 {
3249 let QueryMarginAccountsTradeListParams {
3250 symbol,
3251 is_isolated,
3252 order_id,
3253 start_time,
3254 end_time,
3255 from_id,
3256 limit,
3257 recv_window,
3258 } = params;
3259
3260 let mut query_params = BTreeMap::new();
3261 let body_params = BTreeMap::new();
3262
3263 query_params.insert("symbol".to_string(), json!(symbol));
3264
3265 if let Some(rw) = is_isolated {
3266 query_params.insert("isIsolated".to_string(), json!(rw));
3267 }
3268
3269 if let Some(rw) = order_id {
3270 query_params.insert("orderId".to_string(), json!(rw));
3271 }
3272
3273 if let Some(rw) = start_time {
3274 query_params.insert("startTime".to_string(), json!(rw));
3275 }
3276
3277 if let Some(rw) = end_time {
3278 query_params.insert("endTime".to_string(), json!(rw));
3279 }
3280
3281 if let Some(rw) = from_id {
3282 query_params.insert("fromId".to_string(), json!(rw));
3283 }
3284
3285 if let Some(rw) = limit {
3286 query_params.insert("limit".to_string(), json!(rw));
3287 }
3288
3289 if let Some(rw) = recv_window {
3290 query_params.insert("recvWindow".to_string(), json!(rw));
3291 }
3292
3293 send_request::<Vec<models::QueryMarginAccountsTradeListResponseInner>>(
3294 &self.configuration,
3295 "/sapi/v1/margin/myTrades",
3296 reqwest::Method::GET,
3297 query_params,
3298 body_params,
3299 if HAS_TIME_UNIT {
3300 self.configuration.time_unit
3301 } else {
3302 None
3303 },
3304 true,
3305 )
3306 .await
3307 }
3308
3309 async fn query_prevented_matches(
3310 &self,
3311 params: QueryPreventedMatchesParams,
3312 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryPreventedMatchesResponseInner>>> {
3313 let QueryPreventedMatchesParams {
3314 symbol,
3315 prevented_match_id,
3316 order_id,
3317 from_prevented_match_id,
3318 recv_window,
3319 is_isolated,
3320 } = params;
3321
3322 let mut query_params = BTreeMap::new();
3323 let body_params = BTreeMap::new();
3324
3325 query_params.insert("symbol".to_string(), json!(symbol));
3326
3327 if let Some(rw) = prevented_match_id {
3328 query_params.insert("preventedMatchId".to_string(), json!(rw));
3329 }
3330
3331 if let Some(rw) = order_id {
3332 query_params.insert("orderId".to_string(), json!(rw));
3333 }
3334
3335 if let Some(rw) = from_prevented_match_id {
3336 query_params.insert("fromPreventedMatchId".to_string(), json!(rw));
3337 }
3338
3339 if let Some(rw) = recv_window {
3340 query_params.insert("recvWindow".to_string(), json!(rw));
3341 }
3342
3343 if let Some(rw) = is_isolated {
3344 query_params.insert("isIsolated".to_string(), json!(rw));
3345 }
3346
3347 send_request::<Vec<models::QueryPreventedMatchesResponseInner>>(
3348 &self.configuration,
3349 "/sapi/v1/margin/myPreventedMatches",
3350 reqwest::Method::GET,
3351 query_params,
3352 body_params,
3353 if HAS_TIME_UNIT {
3354 self.configuration.time_unit
3355 } else {
3356 None
3357 },
3358 true,
3359 )
3360 .await
3361 }
3362
3363 async fn query_special_key(
3364 &self,
3365 params: QuerySpecialKeyParams,
3366 ) -> anyhow::Result<RestApiResponse<models::QuerySpecialKeyResponse>> {
3367 let QuerySpecialKeyParams {
3368 symbol,
3369 recv_window,
3370 } = params;
3371
3372 let mut query_params = BTreeMap::new();
3373 let body_params = BTreeMap::new();
3374
3375 if let Some(rw) = symbol {
3376 query_params.insert("symbol".to_string(), json!(rw));
3377 }
3378
3379 if let Some(rw) = recv_window {
3380 query_params.insert("recvWindow".to_string(), json!(rw));
3381 }
3382
3383 send_request::<models::QuerySpecialKeyResponse>(
3384 &self.configuration,
3385 "/sapi/v1/margin/apiKey",
3386 reqwest::Method::GET,
3387 query_params,
3388 body_params,
3389 if HAS_TIME_UNIT {
3390 self.configuration.time_unit
3391 } else {
3392 None
3393 },
3394 true,
3395 )
3396 .await
3397 }
3398
3399 async fn query_special_key_list(
3400 &self,
3401 params: QuerySpecialKeyListParams,
3402 ) -> anyhow::Result<RestApiResponse<Vec<models::QuerySpecialKeyListResponseInner>>> {
3403 let QuerySpecialKeyListParams {
3404 symbol,
3405 recv_window,
3406 } = params;
3407
3408 let mut query_params = BTreeMap::new();
3409 let body_params = BTreeMap::new();
3410
3411 if let Some(rw) = symbol {
3412 query_params.insert("symbol".to_string(), json!(rw));
3413 }
3414
3415 if let Some(rw) = recv_window {
3416 query_params.insert("recvWindow".to_string(), json!(rw));
3417 }
3418
3419 send_request::<Vec<models::QuerySpecialKeyListResponseInner>>(
3420 &self.configuration,
3421 "/sapi/v1/margin/api-key-list",
3422 reqwest::Method::GET,
3423 query_params,
3424 body_params,
3425 if HAS_TIME_UNIT {
3426 self.configuration.time_unit
3427 } else {
3428 None
3429 },
3430 true,
3431 )
3432 .await
3433 }
3434
3435 async fn small_liability_exchange(
3436 &self,
3437 params: SmallLiabilityExchangeParams,
3438 ) -> anyhow::Result<RestApiResponse<Value>> {
3439 let SmallLiabilityExchangeParams {
3440 asset_names,
3441 recv_window,
3442 } = params;
3443
3444 let mut query_params = BTreeMap::new();
3445 let body_params = BTreeMap::new();
3446
3447 query_params.insert("assetNames".to_string(), json!(asset_names));
3448
3449 if let Some(rw) = recv_window {
3450 query_params.insert("recvWindow".to_string(), json!(rw));
3451 }
3452
3453 send_request::<Value>(
3454 &self.configuration,
3455 "/sapi/v1/margin/exchange-small-liability",
3456 reqwest::Method::POST,
3457 query_params,
3458 body_params,
3459 if HAS_TIME_UNIT {
3460 self.configuration.time_unit
3461 } else {
3462 None
3463 },
3464 true,
3465 )
3466 .await
3467 }
3468}
3469
3470#[cfg(all(test, feature = "margin_trading"))]
3471mod tests {
3472 use super::*;
3473 use crate::TOKIO_SHARED_RT;
3474 use crate::{errors::ConnectorError, models::DataFuture, models::RestApiRateLimit};
3475 use async_trait::async_trait;
3476 use std::collections::HashMap;
3477
3478 struct DummyRestApiResponse<T> {
3479 inner: Box<dyn FnOnce() -> DataFuture<Result<T, ConnectorError>> + Send + Sync>,
3480 status: u16,
3481 headers: HashMap<String, String>,
3482 rate_limits: Option<Vec<RestApiRateLimit>>,
3483 }
3484
3485 impl<T> From<DummyRestApiResponse<T>> for RestApiResponse<T> {
3486 fn from(dummy: DummyRestApiResponse<T>) -> Self {
3487 Self {
3488 data_fn: dummy.inner,
3489 status: dummy.status,
3490 headers: dummy.headers,
3491 rate_limits: dummy.rate_limits,
3492 }
3493 }
3494 }
3495
3496 struct MockTradeApiClient {
3497 force_error: bool,
3498 }
3499
3500 #[async_trait]
3501 impl TradeApi for MockTradeApiClient {
3502 async fn create_special_key(
3503 &self,
3504 _params: CreateSpecialKeyParams,
3505 ) -> anyhow::Result<RestApiResponse<models::CreateSpecialKeyResponse>> {
3506 if self.force_error {
3507 return Err(ConnectorError::ConnectorClientError {
3508 msg: "ResponseError".to_string(),
3509 code: None,
3510 }
3511 .into());
3512 }
3513
3514 let resp_json: Value = serde_json::from_str(r#"{"apiKey":"npOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoGx","secretKey":"87ssWB7azoy6ACRfyp6OVOL5U3rtZptX31QWw2kWjl1jHEYRbyM1pd6qykRBQw8p","type":"HMAC_SHA256"}"#).unwrap();
3515 let dummy_response: models::CreateSpecialKeyResponse =
3516 serde_json::from_value(resp_json.clone())
3517 .expect("should parse into models::CreateSpecialKeyResponse");
3518
3519 let dummy = DummyRestApiResponse {
3520 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3521 status: 200,
3522 headers: HashMap::new(),
3523 rate_limits: None,
3524 };
3525
3526 Ok(dummy.into())
3527 }
3528
3529 async fn delete_special_key(
3530 &self,
3531 _params: DeleteSpecialKeyParams,
3532 ) -> anyhow::Result<RestApiResponse<Value>> {
3533 if self.force_error {
3534 return Err(ConnectorError::ConnectorClientError {
3535 msg: "ResponseError".to_string(),
3536 code: None,
3537 }
3538 .into());
3539 }
3540
3541 let dummy_response = Value::Null;
3542
3543 let dummy = DummyRestApiResponse {
3544 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3545 status: 200,
3546 headers: HashMap::new(),
3547 rate_limits: None,
3548 };
3549
3550 Ok(dummy.into())
3551 }
3552
3553 async fn edit_ip_for_special_key(
3554 &self,
3555 _params: EditIpForSpecialKeyParams,
3556 ) -> anyhow::Result<RestApiResponse<Value>> {
3557 if self.force_error {
3558 return Err(ConnectorError::ConnectorClientError {
3559 msg: "ResponseError".to_string(),
3560 code: None,
3561 }
3562 .into());
3563 }
3564
3565 let dummy_response = Value::Null;
3566
3567 let dummy = DummyRestApiResponse {
3568 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3569 status: 200,
3570 headers: HashMap::new(),
3571 rate_limits: None,
3572 };
3573
3574 Ok(dummy.into())
3575 }
3576
3577 async fn get_force_liquidation_record(
3578 &self,
3579 _params: GetForceLiquidationRecordParams,
3580 ) -> anyhow::Result<RestApiResponse<models::GetForceLiquidationRecordResponse>> {
3581 if self.force_error {
3582 return Err(ConnectorError::ConnectorClientError {
3583 msg: "ResponseError".to_string(),
3584 code: None,
3585 }
3586 .into());
3587 }
3588
3589 let resp_json: Value = serde_json::from_str(r#"{"rows":[{"avgPrice":"0.00388359","executedQty":"31.39000000","orderId":180015097,"price":"0.00388110","qty":"31.39000000","side":"SELL","symbol":"BNBBTC","timeInForce":"GTC","isIsolated":true,"updatedTime":1558941374745}],"total":1}"#).unwrap();
3590 let dummy_response: models::GetForceLiquidationRecordResponse =
3591 serde_json::from_value(resp_json.clone())
3592 .expect("should parse into models::GetForceLiquidationRecordResponse");
3593
3594 let dummy = DummyRestApiResponse {
3595 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3596 status: 200,
3597 headers: HashMap::new(),
3598 rate_limits: None,
3599 };
3600
3601 Ok(dummy.into())
3602 }
3603
3604 async fn get_small_liability_exchange_coin_list(
3605 &self,
3606 _params: GetSmallLiabilityExchangeCoinListParams,
3607 ) -> anyhow::Result<
3608 RestApiResponse<Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>>,
3609 > {
3610 if self.force_error {
3611 return Err(ConnectorError::ConnectorClientError {
3612 msg: "ResponseError".to_string(),
3613 code: None,
3614 }
3615 .into());
3616 }
3617
3618 let resp_json: Value = serde_json::from_str(r#"[{"asset":"ETH","interest":"0.00083334","principal":"0.001","liabilityAsset":"USDT","liabilityQty":0.3552}]"#).unwrap();
3619 let dummy_response: Vec<models::GetSmallLiabilityExchangeCoinListResponseInner> =
3620 serde_json::from_value(resp_json.clone()).expect(
3621 "should parse into Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>",
3622 );
3623
3624 let dummy = DummyRestApiResponse {
3625 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3626 status: 200,
3627 headers: HashMap::new(),
3628 rate_limits: None,
3629 };
3630
3631 Ok(dummy.into())
3632 }
3633
3634 async fn get_small_liability_exchange_history(
3635 &self,
3636 _params: GetSmallLiabilityExchangeHistoryParams,
3637 ) -> anyhow::Result<RestApiResponse<models::GetSmallLiabilityExchangeHistoryResponse>>
3638 {
3639 if self.force_error {
3640 return Err(ConnectorError::ConnectorClientError {
3641 msg: "ResponseError".to_string(),
3642 code: None,
3643 }
3644 .into());
3645 }
3646
3647 let resp_json: Value = serde_json::from_str(r#"{"total":1,"rows":[{"asset":"ETH","amount":"0.00083434","targetAsset":"BUSD","targetAmount":"1.37576819","bizType":"EXCHANGE_SMALL_LIABILITY","timestamp":1672801339253}]}"#).unwrap();
3648 let dummy_response: models::GetSmallLiabilityExchangeHistoryResponse =
3649 serde_json::from_value(resp_json.clone())
3650 .expect("should parse into models::GetSmallLiabilityExchangeHistoryResponse");
3651
3652 let dummy = DummyRestApiResponse {
3653 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3654 status: 200,
3655 headers: HashMap::new(),
3656 rate_limits: None,
3657 };
3658
3659 Ok(dummy.into())
3660 }
3661
3662 async fn margin_account_cancel_all_open_orders_on_a_symbol(
3663 &self,
3664 _params: MarginAccountCancelAllOpenOrdersOnASymbolParams,
3665 ) -> anyhow::Result<
3666 RestApiResponse<Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>>,
3667 > {
3668 if self.force_error {
3669 return Err(ConnectorError::ConnectorClientError {
3670 msg: "ResponseError".to_string(),
3671 code: None,
3672 }
3673 .into());
3674 }
3675
3676 let resp_json: Value = serde_json::from_str(r#"[{"symbol":"BTCUSDT","isIsolated":true,"origClientOrderId":"E6APeyTJvkMvLMYMqu1KQ4","orderId":11,"orderListId":-1,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.089853","origQty":"0.178622","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"symbol":"BTCUSDT","isIsolated":false,"origClientOrderId":"A3EF2HCwxgZPFMrfwbgrhv","orderId":13,"orderListId":-1,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.090430","origQty":"0.178622","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"orderListId":1929,"contingencyType":"OCO","listStatusType":"ALL_DONE","listOrderStatus":"ALL_DONE","listClientOrderId":"2inzWQdDvZLHbbAmAozX2N","transactionTime":1585230948299,"symbol":"BTCUSDT","isIsolated":true,"orders":[{"symbol":"BTCUSDT","orderId":20,"clientOrderId":"CwOOIPHSmYywx6jZX77TdL"},{"symbol":"BTCUSDT","orderId":21,"clientOrderId":"461cPg51vQjV3zIMOXNz39"}],"orderReports":[{"symbol":"BTCUSDT","origClientOrderId":"CwOOIPHSmYywx6jZX77TdL","orderId":20,"orderListId":1929,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.668611","origQty":"0.690354","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"STOP_LOSS_LIMIT","side":"BUY","stopPrice":"0.378131","icebergQty":"0.017083"},{"symbol":"BTCUSDT","origClientOrderId":"461cPg51vQjV3zIMOXNz39","orderId":21,"orderListId":1929,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.008791","origQty":"0.690354","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT_MAKER","side":"BUY","icebergQty":"0.639962"}]}]"#).unwrap();
3677 let dummy_response : Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>");
3678
3679 let dummy = DummyRestApiResponse {
3680 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3681 status: 200,
3682 headers: HashMap::new(),
3683 rate_limits: None,
3684 };
3685
3686 Ok(dummy.into())
3687 }
3688
3689 async fn margin_account_cancel_oco(
3690 &self,
3691 _params: MarginAccountCancelOcoParams,
3692 ) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOcoResponse>> {
3693 if self.force_error {
3694 return Err(ConnectorError::ConnectorClientError {
3695 msg: "ResponseError".to_string(),
3696 code: None,
3697 }
3698 .into());
3699 }
3700
3701 let resp_json: Value = serde_json::from_str(r#"{"orderListId":0,"contingencyType":"OCO","listStatusType":"ALL_DONE","listOrderStatus":"ALL_DONE","listClientOrderId":"C3wyj4WVEktd7u9aVBRXcN","transactionTime":1574040868128,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"pO9ufTiFGg3nw2fOdgeOXa"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"TXOvglzXuaubXAaENpaRCB"}],"orderReports":[{"symbol":"LTCBTC","origClientOrderId":"pO9ufTiFGg3nw2fOdgeOXa","orderId":2,"orderListId":0,"clientOrderId":"unfWT8ig8i0uj6lPuYLez6","price":"1.00000000","origQty":"10.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"CANCELED","timeInForce":"GTC","type":"STOP_LOSS_LIMIT","side":"SELL","stopPrice":"1.00000000","selfTradePreventionMode":"NONE"},{"symbol":"LTCBTC","origClientOrderId":"TXOvglzXuaubXAaENpaRCB","orderId":3,"orderListId":0,"clientOrderId":"unfWT8ig8i0uj6lPuYLez6","price":"3.00000000","origQty":"10.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT_MAKER","side":"SELL","selfTradePreventionMode":"NONE"}]}"#).unwrap();
3702 let dummy_response: models::MarginAccountCancelOcoResponse =
3703 serde_json::from_value(resp_json.clone())
3704 .expect("should parse into models::MarginAccountCancelOcoResponse");
3705
3706 let dummy = DummyRestApiResponse {
3707 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3708 status: 200,
3709 headers: HashMap::new(),
3710 rate_limits: None,
3711 };
3712
3713 Ok(dummy.into())
3714 }
3715
3716 async fn margin_account_cancel_order(
3717 &self,
3718 _params: MarginAccountCancelOrderParams,
3719 ) -> anyhow::Result<RestApiResponse<models::MarginAccountCancelOrderResponse>> {
3720 if self.force_error {
3721 return Err(ConnectorError::ConnectorClientError {
3722 msg: "ResponseError".to_string(),
3723 code: None,
3724 }
3725 .into());
3726 }
3727
3728 let resp_json: Value = serde_json::from_str(r#"{"symbol":"LTCBTC","isIsolated":true,"orderId":"28","origClientOrderId":"myOrder1","clientOrderId":"cancelMyOrder1","price":"1.00000000","origQty":"10.00000000","executedQty":"8.00000000","cummulativeQuoteQty":"8.00000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"SELL"}"#).unwrap();
3729 let dummy_response: models::MarginAccountCancelOrderResponse =
3730 serde_json::from_value(resp_json.clone())
3731 .expect("should parse into models::MarginAccountCancelOrderResponse");
3732
3733 let dummy = DummyRestApiResponse {
3734 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3735 status: 200,
3736 headers: HashMap::new(),
3737 rate_limits: None,
3738 };
3739
3740 Ok(dummy.into())
3741 }
3742
3743 async fn margin_account_new_oco(
3744 &self,
3745 _params: MarginAccountNewOcoParams,
3746 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOcoResponse>> {
3747 if self.force_error {
3748 return Err(ConnectorError::ConnectorClientError {
3749 msg: "ResponseError".to_string(),
3750 code: None,
3751 }
3752 .into());
3753 }
3754
3755 let resp_json: Value = serde_json::from_str(r#"{"orderListId":0,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"JYVpp3F0f5CAG15DhtrqLp","transactionTime":1563417480525,"symbol":"LTCBTC","marginBuyBorrowAmount":"5","marginBuyBorrowAsset":"BTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"Kk7sqHb9J6mJWTMDVW7Vos"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"xTXKaGYd4bluPVp78IVRvl"}],"orderReports":[{"symbol":"LTCBTC","orderId":2,"orderListId":0,"clientOrderId":"Kk7sqHb9J6mJWTMDVW7Vos","transactTime":1563417480525,"price":"0.000000","origQty":"0.624363","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"NEW","timeInForce":"GTC","type":"STOP_LOSS","side":"BUY","stopPrice":"0.960664","selfTradePreventionMode":"NONE"},{"symbol":"LTCBTC","orderId":3,"orderListId":0,"clientOrderId":"xTXKaGYd4bluPVp78IVRvl","transactTime":1563417480525,"price":"0.036435","origQty":"0.624363","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"NEW","timeInForce":"GTC","type":"LIMIT_MAKER","side":"BUY","selfTradePreventionMode":"NONE"}]}"#).unwrap();
3756 let dummy_response: models::MarginAccountNewOcoResponse =
3757 serde_json::from_value(resp_json.clone())
3758 .expect("should parse into models::MarginAccountNewOcoResponse");
3759
3760 let dummy = DummyRestApiResponse {
3761 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3762 status: 200,
3763 headers: HashMap::new(),
3764 rate_limits: None,
3765 };
3766
3767 Ok(dummy.into())
3768 }
3769
3770 async fn margin_account_new_order(
3771 &self,
3772 _params: MarginAccountNewOrderParams,
3773 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOrderResponse>> {
3774 if self.force_error {
3775 return Err(ConnectorError::ConnectorClientError {
3776 msg: "ResponseError".to_string(),
3777 code: None,
3778 }
3779 .into());
3780 }
3781
3782 let resp_json: Value = serde_json::from_str(r#"{"symbol":"BTCUSDT","orderId":26769564559,"clientOrderId":"E156O3KP4gOif65bjuUK5V","isIsolated":false,"transactTime":1713873075893,"price":"0","origQty":"0.001","executedQty":"0.001","cummulativeQuoteQty":"65.98253","status":"FILLED","timeInForce":"GTC","type":"MARKET","side":"SELL","selfTradePreventionMode":"EXPIRE_MAKER","marginBuyBorrowAmount":5,"marginBuyBorrowAsset":"BTC","fills":[{"price":"65982.53","qty":"0.001","commission":"0.06598253","commissionAsset":"USDT","tradeId":3570680726}]}"#).unwrap();
3783 let dummy_response: models::MarginAccountNewOrderResponse =
3784 serde_json::from_value(resp_json.clone())
3785 .expect("should parse into models::MarginAccountNewOrderResponse");
3786
3787 let dummy = DummyRestApiResponse {
3788 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3789 status: 200,
3790 headers: HashMap::new(),
3791 rate_limits: None,
3792 };
3793
3794 Ok(dummy.into())
3795 }
3796
3797 async fn margin_account_new_oto(
3798 &self,
3799 _params: MarginAccountNewOtoParams,
3800 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtoResponse>> {
3801 if self.force_error {
3802 return Err(ConnectorError::ConnectorClientError {
3803 msg: "ResponseError".to_string(),
3804 code: None,
3805 }
3806 .into());
3807 }
3808
3809 let resp_json: Value = serde_json::from_str(r#"{"orderListId":13551,"contingencyType":"OTO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"JDuOrsu0Ge8GTyvx8J7VTD","transactionTime":1725521998054,"symbol":"BTCUSDT","isIsolated":false,"orders":[{"symbol":"BTCUSDT","orderId":29896699,"clientOrderId":"y8RB6tQEMuHUXybqbtzTxk"},{"symbol":"BTCUSDT","orderId":29896700,"clientOrderId":"dKQEdh5HhXb7Lpp85jz1dQ"}],"orderReports":[{"symbol":"BTCUSDT","orderId":29896699,"orderListId":13551,"clientOrderId":"y8RB6tQEMuHUXybqbtzTxk","transactTime":1725521998054,"price":"80000.00000000","origQty":"0.02000000","executedQty":"0","cummulativeQuoteQty":"0","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL","selfTradePreventionMode":"NONE"},{"symbol":"BTCUSDT","orderId":29896700,"orderListId":13551,"clientOrderId":"dKQEdh5HhXb7Lpp85jz1dQ","transactTime":1725521998054,"price":"50000.00000000","origQty":"0.02000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"}]}"#).unwrap();
3810 let dummy_response: models::MarginAccountNewOtoResponse =
3811 serde_json::from_value(resp_json.clone())
3812 .expect("should parse into models::MarginAccountNewOtoResponse");
3813
3814 let dummy = DummyRestApiResponse {
3815 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3816 status: 200,
3817 headers: HashMap::new(),
3818 rate_limits: None,
3819 };
3820
3821 Ok(dummy.into())
3822 }
3823
3824 async fn margin_account_new_otoco(
3825 &self,
3826 _params: MarginAccountNewOtocoParams,
3827 ) -> anyhow::Result<RestApiResponse<models::MarginAccountNewOtocoResponse>> {
3828 if self.force_error {
3829 return Err(ConnectorError::ConnectorClientError {
3830 msg: "ResponseError".to_string(),
3831 code: None,
3832 }
3833 .into());
3834 }
3835
3836 let resp_json: Value = serde_json::from_str(r#"{"orderListId":13509,"contingencyType":"OTO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"u2AUo48LLef5qVenRtwJZy","transactionTime":1725521881300,"symbol":"BNBUSDT","isIsolated":false,"orders":[{"symbol":"BNBUSDT","orderId":28282534,"clientOrderId":"IfYDxvrZI4kiyqYpRH13iI"},{"symbol":"BNBUSDT","orderId":28282535,"clientOrderId":"0HCSsPRxVfW8BkTUy9z4np"},{"symbol":"BNBUSDT","orderId":28282536,"clientOrderId":"dypsgdxWnLY75kwT930cbD"}],"orderReports":[{"symbol":"BNBUSDT","orderId":28282534,"orderListId":13509,"clientOrderId":"IfYDxvrZI4kiyqYpRH13iI","transactTime":1725521881300,"price":"300.00000000","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"symbol":"BNBUSDT","orderId":28282535,"orderListId":13509,"clientOrderId":"0HCSsPRxVfW8BkTUy9z4np","transactTime":1725521881300,"price":"0E-8","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"STOP_LOSS","side":"SELL","stopPrice":"299.00000000","selfTradePreventionMode":"NONE"},{"symbol":"BNBUSDT","orderId":28282536,"orderListId":13509,"clientOrderId":"dypsgdxWnLY75kwT930cbD","transactTime":1725521881300,"price":"301.00000000","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"LIMIT_MAKER","side":"SELL","selfTradePreventionMode":"NONE"}]}"#).unwrap();
3837 let dummy_response: models::MarginAccountNewOtocoResponse =
3838 serde_json::from_value(resp_json.clone())
3839 .expect("should parse into models::MarginAccountNewOtocoResponse");
3840
3841 let dummy = DummyRestApiResponse {
3842 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3843 status: 200,
3844 headers: HashMap::new(),
3845 rate_limits: None,
3846 };
3847
3848 Ok(dummy.into())
3849 }
3850
3851 async fn margin_manual_liquidation(
3852 &self,
3853 _params: MarginManualLiquidationParams,
3854 ) -> anyhow::Result<RestApiResponse<models::MarginManualLiquidationResponse>> {
3855 if self.force_error {
3856 return Err(ConnectorError::ConnectorClientError {
3857 msg: "ResponseError".to_string(),
3858 code: None,
3859 }
3860 .into());
3861 }
3862
3863 let resp_json: Value = serde_json::from_str(r#"{"asset":"ETH","interest":"0.00083334","principal":"0.001","liabilityAsset":"USDT","liabilityQty":0.3552}"#).unwrap();
3864 let dummy_response: models::MarginManualLiquidationResponse =
3865 serde_json::from_value(resp_json.clone())
3866 .expect("should parse into models::MarginManualLiquidationResponse");
3867
3868 let dummy = DummyRestApiResponse {
3869 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3870 status: 200,
3871 headers: HashMap::new(),
3872 rate_limits: None,
3873 };
3874
3875 Ok(dummy.into())
3876 }
3877
3878 async fn query_current_margin_order_count_usage(
3879 &self,
3880 _params: QueryCurrentMarginOrderCountUsageParams,
3881 ) -> anyhow::Result<
3882 RestApiResponse<Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>>,
3883 > {
3884 if self.force_error {
3885 return Err(ConnectorError::ConnectorClientError {
3886 msg: "ResponseError".to_string(),
3887 code: None,
3888 }
3889 .into());
3890 }
3891
3892 let resp_json: Value = serde_json::from_str(r#"[{"rateLimitType":"ORDERS","interval":"SECOND","intervalNum":10,"limit":10000,"count":0},{"rateLimitType":"ORDERS","interval":"DAY","intervalNum":1,"limit":20000,"count":0}]"#).unwrap();
3893 let dummy_response: Vec<models::QueryCurrentMarginOrderCountUsageResponseInner> =
3894 serde_json::from_value(resp_json.clone()).expect(
3895 "should parse into Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>",
3896 );
3897
3898 let dummy = DummyRestApiResponse {
3899 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3900 status: 200,
3901 headers: HashMap::new(),
3902 rate_limits: None,
3903 };
3904
3905 Ok(dummy.into())
3906 }
3907
3908 async fn query_margin_accounts_all_oco(
3909 &self,
3910 _params: QueryMarginAccountsAllOcoParams,
3911 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOcoResponseInner>>>
3912 {
3913 if self.force_error {
3914 return Err(ConnectorError::ConnectorClientError {
3915 msg: "ResponseError".to_string(),
3916 code: None,
3917 }
3918 .into());
3919 }
3920
3921 let resp_json: Value = serde_json::from_str(r#"[{"orderListId":29,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"amEEAXryFzFwYF1FeRpUoZ","transactionTime":1565245913483,"symbol":"LTCBTC","isIsolated":true,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"oD7aesZqjEGlZrbtRpy5zB"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"Jr1h6xirOxgeJOUuYQS7V3"}]},{"orderListId":28,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"hG7hFNxJV6cZy3Ze4AUT4d","transactionTime":1565245913407,"symbol":"LTCBTC","orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"j6lFOfbmFMRjTYA7rRJ0LP"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"z0KCjOdditiLS5ekAFtK81"}]}]"#).unwrap();
3922 let dummy_response: Vec<models::QueryMarginAccountsAllOcoResponseInner> =
3923 serde_json::from_value(resp_json.clone()).expect(
3924 "should parse into Vec<models::QueryMarginAccountsAllOcoResponseInner>",
3925 );
3926
3927 let dummy = DummyRestApiResponse {
3928 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3929 status: 200,
3930 headers: HashMap::new(),
3931 rate_limits: None,
3932 };
3933
3934 Ok(dummy.into())
3935 }
3936
3937 async fn query_margin_accounts_all_orders(
3938 &self,
3939 _params: QueryMarginAccountsAllOrdersParams,
3940 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsAllOrdersResponseInner>>>
3941 {
3942 if self.force_error {
3943 return Err(ConnectorError::ConnectorClientError {
3944 msg: "ResponseError".to_string(),
3945 code: None,
3946 }
3947 .into());
3948 }
3949
3950 let resp_json: Value = serde_json::from_str(r#"[{"clientOrderId":"D2KDy4DIeS56PvkM13f8cP","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":false,"orderId":41295,"origQty":"5.31000000","price":"0.22500000","side":"SELL","status":"CANCELED","stopPrice":"0.18000000","symbol":"BNBBTC","isIsolated":false,"time":1565769338806,"timeInForce":"GTC","type":"TAKE_PROFIT_LIMIT","selfTradePreventionMode":"NONE","updateTime":1565769342148},{"clientOrderId":"gXYtqhcEAs2Rn9SUD9nRKx","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"1.00000000","isWorking":true,"orderId":41296,"origQty":"6.65000000","price":"0.18000000","side":"SELL","status":"CANCELED","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":false,"time":1565769348687,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1565769352226}]"#).unwrap();
3951 let dummy_response: Vec<models::QueryMarginAccountsAllOrdersResponseInner> =
3952 serde_json::from_value(resp_json.clone()).expect(
3953 "should parse into Vec<models::QueryMarginAccountsAllOrdersResponseInner>",
3954 );
3955
3956 let dummy = DummyRestApiResponse {
3957 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3958 status: 200,
3959 headers: HashMap::new(),
3960 rate_limits: None,
3961 };
3962
3963 Ok(dummy.into())
3964 }
3965
3966 async fn query_margin_accounts_oco(
3967 &self,
3968 _params: QueryMarginAccountsOcoParams,
3969 ) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOcoResponse>> {
3970 if self.force_error {
3971 return Err(ConnectorError::ConnectorClientError {
3972 msg: "ResponseError".to_string(),
3973 code: None,
3974 }
3975 .into());
3976 }
3977
3978 let resp_json: Value = serde_json::from_str(r#"{"orderListId":27,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"h2USkA5YQpaXHPIrkd96xE","transactionTime":1565245656253,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"qD1gy3kc3Gx0rihm9Y3xwS"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"ARzZ9I00CPM8i3NhmU9Ega"}]}"#).unwrap();
3979 let dummy_response: models::QueryMarginAccountsOcoResponse =
3980 serde_json::from_value(resp_json.clone())
3981 .expect("should parse into models::QueryMarginAccountsOcoResponse");
3982
3983 let dummy = DummyRestApiResponse {
3984 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
3985 status: 200,
3986 headers: HashMap::new(),
3987 rate_limits: None,
3988 };
3989
3990 Ok(dummy.into())
3991 }
3992
3993 async fn query_margin_accounts_open_oco(
3994 &self,
3995 _params: QueryMarginAccountsOpenOcoParams,
3996 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOcoResponseInner>>>
3997 {
3998 if self.force_error {
3999 return Err(ConnectorError::ConnectorClientError {
4000 msg: "ResponseError".to_string(),
4001 code: None,
4002 }
4003 .into());
4004 }
4005
4006 let resp_json: Value = serde_json::from_str(r#"[{"orderListId":31,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"wuB13fmulKj3YjdqWEcsnp","transactionTime":1565246080644,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"r3EH2N76dHfLoSZWIUw1bT"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"Cv1SnyPD3qhqpbjpYEHbd2"}]}]"#).unwrap();
4007 let dummy_response: Vec<models::QueryMarginAccountsOpenOcoResponseInner> =
4008 serde_json::from_value(resp_json.clone()).expect(
4009 "should parse into Vec<models::QueryMarginAccountsOpenOcoResponseInner>",
4010 );
4011
4012 let dummy = DummyRestApiResponse {
4013 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4014 status: 200,
4015 headers: HashMap::new(),
4016 rate_limits: None,
4017 };
4018
4019 Ok(dummy.into())
4020 }
4021
4022 async fn query_margin_accounts_open_orders(
4023 &self,
4024 _params: QueryMarginAccountsOpenOrdersParams,
4025 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsOpenOrdersResponseInner>>>
4026 {
4027 if self.force_error {
4028 return Err(ConnectorError::ConnectorClientError {
4029 msg: "ResponseError".to_string(),
4030 code: None,
4031 }
4032 .into());
4033 }
4034
4035 let resp_json: Value = serde_json::from_str(r#"[{"clientOrderId":"qhcZw71gAkCCTv0t0k8LUK","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":true,"orderId":211842552,"origQty":"0.30000000","price":"0.00475010","side":"SELL","status":"NEW","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":true,"time":1562040170089,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1562040170089}]"#).unwrap();
4036 let dummy_response: Vec<models::QueryMarginAccountsOpenOrdersResponseInner> =
4037 serde_json::from_value(resp_json.clone()).expect(
4038 "should parse into Vec<models::QueryMarginAccountsOpenOrdersResponseInner>",
4039 );
4040
4041 let dummy = DummyRestApiResponse {
4042 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4043 status: 200,
4044 headers: HashMap::new(),
4045 rate_limits: None,
4046 };
4047
4048 Ok(dummy.into())
4049 }
4050
4051 async fn query_margin_accounts_order(
4052 &self,
4053 _params: QueryMarginAccountsOrderParams,
4054 ) -> anyhow::Result<RestApiResponse<models::QueryMarginAccountsOrderResponse>> {
4055 if self.force_error {
4056 return Err(ConnectorError::ConnectorClientError {
4057 msg: "ResponseError".to_string(),
4058 code: None,
4059 }
4060 .into());
4061 }
4062
4063 let resp_json: Value = serde_json::from_str(r#"{"clientOrderId":"ZwfQzuDIGpceVhKW5DvCmO","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":true,"orderId":213205622,"origQty":"0.30000000","price":"0.00493630","side":"SELL","status":"NEW","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":true,"time":1562133008725,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1562133008725}"#).unwrap();
4064 let dummy_response: models::QueryMarginAccountsOrderResponse =
4065 serde_json::from_value(resp_json.clone())
4066 .expect("should parse into models::QueryMarginAccountsOrderResponse");
4067
4068 let dummy = DummyRestApiResponse {
4069 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4070 status: 200,
4071 headers: HashMap::new(),
4072 rate_limits: None,
4073 };
4074
4075 Ok(dummy.into())
4076 }
4077
4078 async fn query_margin_accounts_trade_list(
4079 &self,
4080 _params: QueryMarginAccountsTradeListParams,
4081 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryMarginAccountsTradeListResponseInner>>>
4082 {
4083 if self.force_error {
4084 return Err(ConnectorError::ConnectorClientError {
4085 msg: "ResponseError".to_string(),
4086 code: None,
4087 }
4088 .into());
4089 }
4090
4091 let resp_json: Value = serde_json::from_str(r#"[{"commission":"0.00006000","commissionAsset":"BTC","id":34,"isBestMatch":true,"isBuyer":false,"isMaker":false,"orderId":39324,"price":"0.02000000","qty":"3.00000000","symbol":"BNBBTC","isIsolated":false,"time":1561973357171}]"#).unwrap();
4092 let dummy_response: Vec<models::QueryMarginAccountsTradeListResponseInner> =
4093 serde_json::from_value(resp_json.clone()).expect(
4094 "should parse into Vec<models::QueryMarginAccountsTradeListResponseInner>",
4095 );
4096
4097 let dummy = DummyRestApiResponse {
4098 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4099 status: 200,
4100 headers: HashMap::new(),
4101 rate_limits: None,
4102 };
4103
4104 Ok(dummy.into())
4105 }
4106
4107 async fn query_prevented_matches(
4108 &self,
4109 _params: QueryPreventedMatchesParams,
4110 ) -> anyhow::Result<RestApiResponse<Vec<models::QueryPreventedMatchesResponseInner>>>
4111 {
4112 if self.force_error {
4113 return Err(ConnectorError::ConnectorClientError {
4114 msg: "ResponseError".to_string(),
4115 code: None,
4116 }
4117 .into());
4118 }
4119
4120 let resp_json: Value = serde_json::from_str(r#"[{"symbol":"BTCUSDT","preventedMatchId":1,"takerOrderId":5,"makerSymbol":"BTCUSDT","makerOrderId":3,"tradeGroupId":1,"selfTradePreventionMode":"EXPIRE_MAKER","price":"1.100000","makerPreventedQuantity":"1.300000","transactTime":1669101687094}]"#).unwrap();
4121 let dummy_response: Vec<models::QueryPreventedMatchesResponseInner> =
4122 serde_json::from_value(resp_json.clone())
4123 .expect("should parse into Vec<models::QueryPreventedMatchesResponseInner>");
4124
4125 let dummy = DummyRestApiResponse {
4126 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4127 status: 200,
4128 headers: HashMap::new(),
4129 rate_limits: None,
4130 };
4131
4132 Ok(dummy.into())
4133 }
4134
4135 async fn query_special_key(
4136 &self,
4137 _params: QuerySpecialKeyParams,
4138 ) -> anyhow::Result<RestApiResponse<models::QuerySpecialKeyResponse>> {
4139 if self.force_error {
4140 return Err(ConnectorError::ConnectorClientError {
4141 msg: "ResponseError".to_string(),
4142 code: None,
4143 }
4144 .into());
4145 }
4146
4147 let resp_json: Value = serde_json::from_str(r#"{"apiKey":"npOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoGx","ip":"0.0.0.0,192.168.0.1,192.168.0.2","apiName":"testName","type":"RSA","permissionMode":"TRADE"}"#).unwrap();
4148 let dummy_response: models::QuerySpecialKeyResponse =
4149 serde_json::from_value(resp_json.clone())
4150 .expect("should parse into models::QuerySpecialKeyResponse");
4151
4152 let dummy = DummyRestApiResponse {
4153 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4154 status: 200,
4155 headers: HashMap::new(),
4156 rate_limits: None,
4157 };
4158
4159 Ok(dummy.into())
4160 }
4161
4162 async fn query_special_key_list(
4163 &self,
4164 _params: QuerySpecialKeyListParams,
4165 ) -> anyhow::Result<RestApiResponse<Vec<models::QuerySpecialKeyListResponseInner>>>
4166 {
4167 if self.force_error {
4168 return Err(ConnectorError::ConnectorClientError {
4169 msg: "ResponseError".to_string(),
4170 code: None,
4171 }
4172 .into());
4173 }
4174
4175 let resp_json: Value = serde_json::from_str(r#"[{"apiName":"testName1","apiKey":"znpOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoG","ip":"192.168.0.1,192.168.0.2","type":"RSA","permissionMode":"TRADE"},{"apiName":"testName2","apiKey":"znpOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoG","ip":"192.168.0.1,192.168.0.2","type":"Ed25519","permissionMode":"READ"}]"#).unwrap();
4176 let dummy_response: Vec<models::QuerySpecialKeyListResponseInner> =
4177 serde_json::from_value(resp_json.clone())
4178 .expect("should parse into Vec<models::QuerySpecialKeyListResponseInner>");
4179
4180 let dummy = DummyRestApiResponse {
4181 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4182 status: 200,
4183 headers: HashMap::new(),
4184 rate_limits: None,
4185 };
4186
4187 Ok(dummy.into())
4188 }
4189
4190 async fn small_liability_exchange(
4191 &self,
4192 _params: SmallLiabilityExchangeParams,
4193 ) -> anyhow::Result<RestApiResponse<Value>> {
4194 if self.force_error {
4195 return Err(ConnectorError::ConnectorClientError {
4196 msg: "ResponseError".to_string(),
4197 code: None,
4198 }
4199 .into());
4200 }
4201
4202 let dummy_response = Value::Null;
4203
4204 let dummy = DummyRestApiResponse {
4205 inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
4206 status: 200,
4207 headers: HashMap::new(),
4208 rate_limits: None,
4209 };
4210
4211 Ok(dummy.into())
4212 }
4213 }
4214
4215 #[test]
4216 fn create_special_key_required_params_success() {
4217 TOKIO_SHARED_RT.block_on(async {
4218 let client = MockTradeApiClient { force_error: false };
4219
4220 let params = CreateSpecialKeyParams::builder("api_name_example".to_string(),).build().unwrap();
4221
4222 let resp_json: Value = serde_json::from_str(r#"{"apiKey":"npOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoGx","secretKey":"87ssWB7azoy6ACRfyp6OVOL5U3rtZptX31QWw2kWjl1jHEYRbyM1pd6qykRBQw8p","type":"HMAC_SHA256"}"#).unwrap();
4223 let expected_response : models::CreateSpecialKeyResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::CreateSpecialKeyResponse");
4224
4225 let resp = client.create_special_key(params).await.expect("Expected a response");
4226 let data_future = resp.data();
4227 let actual_response = data_future.await.unwrap();
4228 assert_eq!(actual_response, expected_response);
4229 });
4230 }
4231
4232 #[test]
4233 fn create_special_key_optional_params_success() {
4234 TOKIO_SHARED_RT.block_on(async {
4235 let client = MockTradeApiClient { force_error: false };
4236
4237 let params = CreateSpecialKeyParams::builder("api_name_example".to_string(),).symbol("symbol_example".to_string()).ip("ip_example".to_string()).public_key("public_key_example".to_string()).permission_mode("value".to_string()).recv_window(5000).build().unwrap();
4238
4239 let resp_json: Value = serde_json::from_str(r#"{"apiKey":"npOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoGx","secretKey":"87ssWB7azoy6ACRfyp6OVOL5U3rtZptX31QWw2kWjl1jHEYRbyM1pd6qykRBQw8p","type":"HMAC_SHA256"}"#).unwrap();
4240 let expected_response : models::CreateSpecialKeyResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::CreateSpecialKeyResponse");
4241
4242 let resp = client.create_special_key(params).await.expect("Expected a response");
4243 let data_future = resp.data();
4244 let actual_response = data_future.await.unwrap();
4245 assert_eq!(actual_response, expected_response);
4246 });
4247 }
4248
4249 #[test]
4250 fn create_special_key_response_error() {
4251 TOKIO_SHARED_RT.block_on(async {
4252 let client = MockTradeApiClient { force_error: true };
4253
4254 let params = CreateSpecialKeyParams::builder("api_name_example".to_string())
4255 .build()
4256 .unwrap();
4257
4258 match client.create_special_key(params).await {
4259 Ok(_) => panic!("Expected an error"),
4260 Err(err) => {
4261 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4262 }
4263 }
4264 });
4265 }
4266
4267 #[test]
4268 fn delete_special_key_required_params_success() {
4269 TOKIO_SHARED_RT.block_on(async {
4270 let client = MockTradeApiClient { force_error: false };
4271
4272 let params = DeleteSpecialKeyParams::builder().build().unwrap();
4273
4274 let expected_response = Value::Null;
4275
4276 let resp = client
4277 .delete_special_key(params)
4278 .await
4279 .expect("Expected a response");
4280 let data_future = resp.data();
4281 let actual_response = data_future.await.unwrap();
4282 assert_eq!(actual_response, expected_response);
4283 });
4284 }
4285
4286 #[test]
4287 fn delete_special_key_optional_params_success() {
4288 TOKIO_SHARED_RT.block_on(async {
4289 let client = MockTradeApiClient { force_error: false };
4290
4291 let params = DeleteSpecialKeyParams::builder()
4292 .api_name("api_name_example".to_string())
4293 .symbol("symbol_example".to_string())
4294 .recv_window(5000)
4295 .build()
4296 .unwrap();
4297
4298 let expected_response = Value::Null;
4299
4300 let resp = client
4301 .delete_special_key(params)
4302 .await
4303 .expect("Expected a response");
4304 let data_future = resp.data();
4305 let actual_response = data_future.await.unwrap();
4306 assert_eq!(actual_response, expected_response);
4307 });
4308 }
4309
4310 #[test]
4311 fn delete_special_key_response_error() {
4312 TOKIO_SHARED_RT.block_on(async {
4313 let client = MockTradeApiClient { force_error: true };
4314
4315 let params = DeleteSpecialKeyParams::builder().build().unwrap();
4316
4317 match client.delete_special_key(params).await {
4318 Ok(_) => panic!("Expected an error"),
4319 Err(err) => {
4320 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4321 }
4322 }
4323 });
4324 }
4325
4326 #[test]
4327 fn edit_ip_for_special_key_required_params_success() {
4328 TOKIO_SHARED_RT.block_on(async {
4329 let client = MockTradeApiClient { force_error: false };
4330
4331 let params = EditIpForSpecialKeyParams::builder("ip_example".to_string())
4332 .build()
4333 .unwrap();
4334
4335 let expected_response = Value::Null;
4336
4337 let resp = client
4338 .edit_ip_for_special_key(params)
4339 .await
4340 .expect("Expected a response");
4341 let data_future = resp.data();
4342 let actual_response = data_future.await.unwrap();
4343 assert_eq!(actual_response, expected_response);
4344 });
4345 }
4346
4347 #[test]
4348 fn edit_ip_for_special_key_optional_params_success() {
4349 TOKIO_SHARED_RT.block_on(async {
4350 let client = MockTradeApiClient { force_error: false };
4351
4352 let params = EditIpForSpecialKeyParams::builder("ip_example".to_string())
4353 .symbol("symbol_example".to_string())
4354 .recv_window(5000)
4355 .build()
4356 .unwrap();
4357
4358 let expected_response = Value::Null;
4359
4360 let resp = client
4361 .edit_ip_for_special_key(params)
4362 .await
4363 .expect("Expected a response");
4364 let data_future = resp.data();
4365 let actual_response = data_future.await.unwrap();
4366 assert_eq!(actual_response, expected_response);
4367 });
4368 }
4369
4370 #[test]
4371 fn edit_ip_for_special_key_response_error() {
4372 TOKIO_SHARED_RT.block_on(async {
4373 let client = MockTradeApiClient { force_error: true };
4374
4375 let params = EditIpForSpecialKeyParams::builder("ip_example".to_string())
4376 .build()
4377 .unwrap();
4378
4379 match client.edit_ip_for_special_key(params).await {
4380 Ok(_) => panic!("Expected an error"),
4381 Err(err) => {
4382 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4383 }
4384 }
4385 });
4386 }
4387
4388 #[test]
4389 fn get_force_liquidation_record_required_params_success() {
4390 TOKIO_SHARED_RT.block_on(async {
4391 let client = MockTradeApiClient { force_error: false };
4392
4393 let params = GetForceLiquidationRecordParams::builder().build().unwrap();
4394
4395 let resp_json: Value = serde_json::from_str(r#"{"rows":[{"avgPrice":"0.00388359","executedQty":"31.39000000","orderId":180015097,"price":"0.00388110","qty":"31.39000000","side":"SELL","symbol":"BNBBTC","timeInForce":"GTC","isIsolated":true,"updatedTime":1558941374745}],"total":1}"#).unwrap();
4396 let expected_response : models::GetForceLiquidationRecordResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetForceLiquidationRecordResponse");
4397
4398 let resp = client.get_force_liquidation_record(params).await.expect("Expected a response");
4399 let data_future = resp.data();
4400 let actual_response = data_future.await.unwrap();
4401 assert_eq!(actual_response, expected_response);
4402 });
4403 }
4404
4405 #[test]
4406 fn get_force_liquidation_record_optional_params_success() {
4407 TOKIO_SHARED_RT.block_on(async {
4408 let client = MockTradeApiClient { force_error: false };
4409
4410 let params = GetForceLiquidationRecordParams::builder().start_time(1623319461670).end_time(1641782889000).isolated_symbol("isolated_symbol_example".to_string()).current(1).size(10).recv_window(5000).build().unwrap();
4411
4412 let resp_json: Value = serde_json::from_str(r#"{"rows":[{"avgPrice":"0.00388359","executedQty":"31.39000000","orderId":180015097,"price":"0.00388110","qty":"31.39000000","side":"SELL","symbol":"BNBBTC","timeInForce":"GTC","isIsolated":true,"updatedTime":1558941374745}],"total":1}"#).unwrap();
4413 let expected_response : models::GetForceLiquidationRecordResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetForceLiquidationRecordResponse");
4414
4415 let resp = client.get_force_liquidation_record(params).await.expect("Expected a response");
4416 let data_future = resp.data();
4417 let actual_response = data_future.await.unwrap();
4418 assert_eq!(actual_response, expected_response);
4419 });
4420 }
4421
4422 #[test]
4423 fn get_force_liquidation_record_response_error() {
4424 TOKIO_SHARED_RT.block_on(async {
4425 let client = MockTradeApiClient { force_error: true };
4426
4427 let params = GetForceLiquidationRecordParams::builder().build().unwrap();
4428
4429 match client.get_force_liquidation_record(params).await {
4430 Ok(_) => panic!("Expected an error"),
4431 Err(err) => {
4432 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4433 }
4434 }
4435 });
4436 }
4437
4438 #[test]
4439 fn get_small_liability_exchange_coin_list_required_params_success() {
4440 TOKIO_SHARED_RT.block_on(async {
4441 let client = MockTradeApiClient { force_error: false };
4442
4443 let params = GetSmallLiabilityExchangeCoinListParams::builder().build().unwrap();
4444
4445 let resp_json: Value = serde_json::from_str(r#"[{"asset":"ETH","interest":"0.00083334","principal":"0.001","liabilityAsset":"USDT","liabilityQty":0.3552}]"#).unwrap();
4446 let expected_response : Vec<models::GetSmallLiabilityExchangeCoinListResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>");
4447
4448 let resp = client.get_small_liability_exchange_coin_list(params).await.expect("Expected a response");
4449 let data_future = resp.data();
4450 let actual_response = data_future.await.unwrap();
4451 assert_eq!(actual_response, expected_response);
4452 });
4453 }
4454
4455 #[test]
4456 fn get_small_liability_exchange_coin_list_optional_params_success() {
4457 TOKIO_SHARED_RT.block_on(async {
4458 let client = MockTradeApiClient { force_error: false };
4459
4460 let params = GetSmallLiabilityExchangeCoinListParams::builder().recv_window(5000).build().unwrap();
4461
4462 let resp_json: Value = serde_json::from_str(r#"[{"asset":"ETH","interest":"0.00083334","principal":"0.001","liabilityAsset":"USDT","liabilityQty":0.3552}]"#).unwrap();
4463 let expected_response : Vec<models::GetSmallLiabilityExchangeCoinListResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::GetSmallLiabilityExchangeCoinListResponseInner>");
4464
4465 let resp = client.get_small_liability_exchange_coin_list(params).await.expect("Expected a response");
4466 let data_future = resp.data();
4467 let actual_response = data_future.await.unwrap();
4468 assert_eq!(actual_response, expected_response);
4469 });
4470 }
4471
4472 #[test]
4473 fn get_small_liability_exchange_coin_list_response_error() {
4474 TOKIO_SHARED_RT.block_on(async {
4475 let client = MockTradeApiClient { force_error: true };
4476
4477 let params = GetSmallLiabilityExchangeCoinListParams::builder()
4478 .build()
4479 .unwrap();
4480
4481 match client.get_small_liability_exchange_coin_list(params).await {
4482 Ok(_) => panic!("Expected an error"),
4483 Err(err) => {
4484 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4485 }
4486 }
4487 });
4488 }
4489
4490 #[test]
4491 fn get_small_liability_exchange_history_required_params_success() {
4492 TOKIO_SHARED_RT.block_on(async {
4493 let client = MockTradeApiClient { force_error: false };
4494
4495 let params = GetSmallLiabilityExchangeHistoryParams::builder(1,10,).build().unwrap();
4496
4497 let resp_json: Value = serde_json::from_str(r#"{"total":1,"rows":[{"asset":"ETH","amount":"0.00083434","targetAsset":"BUSD","targetAmount":"1.37576819","bizType":"EXCHANGE_SMALL_LIABILITY","timestamp":1672801339253}]}"#).unwrap();
4498 let expected_response : models::GetSmallLiabilityExchangeHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetSmallLiabilityExchangeHistoryResponse");
4499
4500 let resp = client.get_small_liability_exchange_history(params).await.expect("Expected a response");
4501 let data_future = resp.data();
4502 let actual_response = data_future.await.unwrap();
4503 assert_eq!(actual_response, expected_response);
4504 });
4505 }
4506
4507 #[test]
4508 fn get_small_liability_exchange_history_optional_params_success() {
4509 TOKIO_SHARED_RT.block_on(async {
4510 let client = MockTradeApiClient { force_error: false };
4511
4512 let params = GetSmallLiabilityExchangeHistoryParams::builder(1,10,).start_time(1623319461670).end_time(1641782889000).recv_window(5000).build().unwrap();
4513
4514 let resp_json: Value = serde_json::from_str(r#"{"total":1,"rows":[{"asset":"ETH","amount":"0.00083434","targetAsset":"BUSD","targetAmount":"1.37576819","bizType":"EXCHANGE_SMALL_LIABILITY","timestamp":1672801339253}]}"#).unwrap();
4515 let expected_response : models::GetSmallLiabilityExchangeHistoryResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetSmallLiabilityExchangeHistoryResponse");
4516
4517 let resp = client.get_small_liability_exchange_history(params).await.expect("Expected a response");
4518 let data_future = resp.data();
4519 let actual_response = data_future.await.unwrap();
4520 assert_eq!(actual_response, expected_response);
4521 });
4522 }
4523
4524 #[test]
4525 fn get_small_liability_exchange_history_response_error() {
4526 TOKIO_SHARED_RT.block_on(async {
4527 let client = MockTradeApiClient { force_error: true };
4528
4529 let params = GetSmallLiabilityExchangeHistoryParams::builder(1, 10)
4530 .build()
4531 .unwrap();
4532
4533 match client.get_small_liability_exchange_history(params).await {
4534 Ok(_) => panic!("Expected an error"),
4535 Err(err) => {
4536 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4537 }
4538 }
4539 });
4540 }
4541
4542 #[test]
4543 fn margin_account_cancel_all_open_orders_on_a_symbol_required_params_success() {
4544 TOKIO_SHARED_RT.block_on(async {
4545 let client = MockTradeApiClient { force_error: false };
4546
4547 let params = MarginAccountCancelAllOpenOrdersOnASymbolParams::builder("symbol_example".to_string(),).build().unwrap();
4548
4549 let resp_json: Value = serde_json::from_str(r#"[{"symbol":"BTCUSDT","isIsolated":true,"origClientOrderId":"E6APeyTJvkMvLMYMqu1KQ4","orderId":11,"orderListId":-1,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.089853","origQty":"0.178622","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"symbol":"BTCUSDT","isIsolated":false,"origClientOrderId":"A3EF2HCwxgZPFMrfwbgrhv","orderId":13,"orderListId":-1,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.090430","origQty":"0.178622","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"orderListId":1929,"contingencyType":"OCO","listStatusType":"ALL_DONE","listOrderStatus":"ALL_DONE","listClientOrderId":"2inzWQdDvZLHbbAmAozX2N","transactionTime":1585230948299,"symbol":"BTCUSDT","isIsolated":true,"orders":[{"symbol":"BTCUSDT","orderId":20,"clientOrderId":"CwOOIPHSmYywx6jZX77TdL"},{"symbol":"BTCUSDT","orderId":21,"clientOrderId":"461cPg51vQjV3zIMOXNz39"}],"orderReports":[{"symbol":"BTCUSDT","origClientOrderId":"CwOOIPHSmYywx6jZX77TdL","orderId":20,"orderListId":1929,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.668611","origQty":"0.690354","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"STOP_LOSS_LIMIT","side":"BUY","stopPrice":"0.378131","icebergQty":"0.017083"},{"symbol":"BTCUSDT","origClientOrderId":"461cPg51vQjV3zIMOXNz39","orderId":21,"orderListId":1929,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.008791","origQty":"0.690354","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT_MAKER","side":"BUY","icebergQty":"0.639962"}]}]"#).unwrap();
4550 let expected_response : Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>");
4551
4552 let resp = client.margin_account_cancel_all_open_orders_on_a_symbol(params).await.expect("Expected a response");
4553 let data_future = resp.data();
4554 let actual_response = data_future.await.unwrap();
4555 assert_eq!(actual_response, expected_response);
4556 });
4557 }
4558
4559 #[test]
4560 fn margin_account_cancel_all_open_orders_on_a_symbol_optional_params_success() {
4561 TOKIO_SHARED_RT.block_on(async {
4562 let client = MockTradeApiClient { force_error: false };
4563
4564 let params = MarginAccountCancelAllOpenOrdersOnASymbolParams::builder("symbol_example".to_string(),).is_isolated("false".to_string()).recv_window(5000).build().unwrap();
4565
4566 let resp_json: Value = serde_json::from_str(r#"[{"symbol":"BTCUSDT","isIsolated":true,"origClientOrderId":"E6APeyTJvkMvLMYMqu1KQ4","orderId":11,"orderListId":-1,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.089853","origQty":"0.178622","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"symbol":"BTCUSDT","isIsolated":false,"origClientOrderId":"A3EF2HCwxgZPFMrfwbgrhv","orderId":13,"orderListId":-1,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.090430","origQty":"0.178622","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"orderListId":1929,"contingencyType":"OCO","listStatusType":"ALL_DONE","listOrderStatus":"ALL_DONE","listClientOrderId":"2inzWQdDvZLHbbAmAozX2N","transactionTime":1585230948299,"symbol":"BTCUSDT","isIsolated":true,"orders":[{"symbol":"BTCUSDT","orderId":20,"clientOrderId":"CwOOIPHSmYywx6jZX77TdL"},{"symbol":"BTCUSDT","orderId":21,"clientOrderId":"461cPg51vQjV3zIMOXNz39"}],"orderReports":[{"symbol":"BTCUSDT","origClientOrderId":"CwOOIPHSmYywx6jZX77TdL","orderId":20,"orderListId":1929,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.668611","origQty":"0.690354","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"STOP_LOSS_LIMIT","side":"BUY","stopPrice":"0.378131","icebergQty":"0.017083"},{"symbol":"BTCUSDT","origClientOrderId":"461cPg51vQjV3zIMOXNz39","orderId":21,"orderListId":1929,"clientOrderId":"pXLV6Hz6mprAcVYpVMTGgx","price":"0.008791","origQty":"0.690354","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT_MAKER","side":"BUY","icebergQty":"0.639962"}]}]"#).unwrap();
4567 let expected_response : Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::MarginAccountCancelAllOpenOrdersOnASymbolResponseInner>");
4568
4569 let resp = client.margin_account_cancel_all_open_orders_on_a_symbol(params).await.expect("Expected a response");
4570 let data_future = resp.data();
4571 let actual_response = data_future.await.unwrap();
4572 assert_eq!(actual_response, expected_response);
4573 });
4574 }
4575
4576 #[test]
4577 fn margin_account_cancel_all_open_orders_on_a_symbol_response_error() {
4578 TOKIO_SHARED_RT.block_on(async {
4579 let client = MockTradeApiClient { force_error: true };
4580
4581 let params = MarginAccountCancelAllOpenOrdersOnASymbolParams::builder(
4582 "symbol_example".to_string(),
4583 )
4584 .build()
4585 .unwrap();
4586
4587 match client
4588 .margin_account_cancel_all_open_orders_on_a_symbol(params)
4589 .await
4590 {
4591 Ok(_) => panic!("Expected an error"),
4592 Err(err) => {
4593 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4594 }
4595 }
4596 });
4597 }
4598
4599 #[test]
4600 fn margin_account_cancel_oco_required_params_success() {
4601 TOKIO_SHARED_RT.block_on(async {
4602 let client = MockTradeApiClient { force_error: false };
4603
4604 let params = MarginAccountCancelOcoParams::builder("symbol_example".to_string(),).build().unwrap();
4605
4606 let resp_json: Value = serde_json::from_str(r#"{"orderListId":0,"contingencyType":"OCO","listStatusType":"ALL_DONE","listOrderStatus":"ALL_DONE","listClientOrderId":"C3wyj4WVEktd7u9aVBRXcN","transactionTime":1574040868128,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"pO9ufTiFGg3nw2fOdgeOXa"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"TXOvglzXuaubXAaENpaRCB"}],"orderReports":[{"symbol":"LTCBTC","origClientOrderId":"pO9ufTiFGg3nw2fOdgeOXa","orderId":2,"orderListId":0,"clientOrderId":"unfWT8ig8i0uj6lPuYLez6","price":"1.00000000","origQty":"10.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"CANCELED","timeInForce":"GTC","type":"STOP_LOSS_LIMIT","side":"SELL","stopPrice":"1.00000000","selfTradePreventionMode":"NONE"},{"symbol":"LTCBTC","origClientOrderId":"TXOvglzXuaubXAaENpaRCB","orderId":3,"orderListId":0,"clientOrderId":"unfWT8ig8i0uj6lPuYLez6","price":"3.00000000","origQty":"10.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT_MAKER","side":"SELL","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4607 let expected_response : models::MarginAccountCancelOcoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountCancelOcoResponse");
4608
4609 let resp = client.margin_account_cancel_oco(params).await.expect("Expected a response");
4610 let data_future = resp.data();
4611 let actual_response = data_future.await.unwrap();
4612 assert_eq!(actual_response, expected_response);
4613 });
4614 }
4615
4616 #[test]
4617 fn margin_account_cancel_oco_optional_params_success() {
4618 TOKIO_SHARED_RT.block_on(async {
4619 let client = MockTradeApiClient { force_error: false };
4620
4621 let params = MarginAccountCancelOcoParams::builder("symbol_example".to_string(),).is_isolated("false".to_string()).order_list_id(1).list_client_order_id("1".to_string()).new_client_order_id("1".to_string()).recv_window(5000).build().unwrap();
4622
4623 let resp_json: Value = serde_json::from_str(r#"{"orderListId":0,"contingencyType":"OCO","listStatusType":"ALL_DONE","listOrderStatus":"ALL_DONE","listClientOrderId":"C3wyj4WVEktd7u9aVBRXcN","transactionTime":1574040868128,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"pO9ufTiFGg3nw2fOdgeOXa"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"TXOvglzXuaubXAaENpaRCB"}],"orderReports":[{"symbol":"LTCBTC","origClientOrderId":"pO9ufTiFGg3nw2fOdgeOXa","orderId":2,"orderListId":0,"clientOrderId":"unfWT8ig8i0uj6lPuYLez6","price":"1.00000000","origQty":"10.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"CANCELED","timeInForce":"GTC","type":"STOP_LOSS_LIMIT","side":"SELL","stopPrice":"1.00000000","selfTradePreventionMode":"NONE"},{"symbol":"LTCBTC","origClientOrderId":"TXOvglzXuaubXAaENpaRCB","orderId":3,"orderListId":0,"clientOrderId":"unfWT8ig8i0uj6lPuYLez6","price":"3.00000000","origQty":"10.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT_MAKER","side":"SELL","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4624 let expected_response : models::MarginAccountCancelOcoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountCancelOcoResponse");
4625
4626 let resp = client.margin_account_cancel_oco(params).await.expect("Expected a response");
4627 let data_future = resp.data();
4628 let actual_response = data_future.await.unwrap();
4629 assert_eq!(actual_response, expected_response);
4630 });
4631 }
4632
4633 #[test]
4634 fn margin_account_cancel_oco_response_error() {
4635 TOKIO_SHARED_RT.block_on(async {
4636 let client = MockTradeApiClient { force_error: true };
4637
4638 let params = MarginAccountCancelOcoParams::builder("symbol_example".to_string())
4639 .build()
4640 .unwrap();
4641
4642 match client.margin_account_cancel_oco(params).await {
4643 Ok(_) => panic!("Expected an error"),
4644 Err(err) => {
4645 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4646 }
4647 }
4648 });
4649 }
4650
4651 #[test]
4652 fn margin_account_cancel_order_required_params_success() {
4653 TOKIO_SHARED_RT.block_on(async {
4654 let client = MockTradeApiClient { force_error: false };
4655
4656 let params = MarginAccountCancelOrderParams::builder("symbol_example".to_string(),).build().unwrap();
4657
4658 let resp_json: Value = serde_json::from_str(r#"{"symbol":"LTCBTC","isIsolated":true,"orderId":"28","origClientOrderId":"myOrder1","clientOrderId":"cancelMyOrder1","price":"1.00000000","origQty":"10.00000000","executedQty":"8.00000000","cummulativeQuoteQty":"8.00000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"SELL"}"#).unwrap();
4659 let expected_response : models::MarginAccountCancelOrderResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountCancelOrderResponse");
4660
4661 let resp = client.margin_account_cancel_order(params).await.expect("Expected a response");
4662 let data_future = resp.data();
4663 let actual_response = data_future.await.unwrap();
4664 assert_eq!(actual_response, expected_response);
4665 });
4666 }
4667
4668 #[test]
4669 fn margin_account_cancel_order_optional_params_success() {
4670 TOKIO_SHARED_RT.block_on(async {
4671 let client = MockTradeApiClient { force_error: false };
4672
4673 let params = MarginAccountCancelOrderParams::builder("symbol_example".to_string(),).is_isolated("false".to_string()).order_id(1).orig_client_order_id("1".to_string()).new_client_order_id("1".to_string()).recv_window(5000).build().unwrap();
4674
4675 let resp_json: Value = serde_json::from_str(r#"{"symbol":"LTCBTC","isIsolated":true,"orderId":"28","origClientOrderId":"myOrder1","clientOrderId":"cancelMyOrder1","price":"1.00000000","origQty":"10.00000000","executedQty":"8.00000000","cummulativeQuoteQty":"8.00000000","status":"CANCELED","timeInForce":"GTC","type":"LIMIT","side":"SELL"}"#).unwrap();
4676 let expected_response : models::MarginAccountCancelOrderResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountCancelOrderResponse");
4677
4678 let resp = client.margin_account_cancel_order(params).await.expect("Expected a response");
4679 let data_future = resp.data();
4680 let actual_response = data_future.await.unwrap();
4681 assert_eq!(actual_response, expected_response);
4682 });
4683 }
4684
4685 #[test]
4686 fn margin_account_cancel_order_response_error() {
4687 TOKIO_SHARED_RT.block_on(async {
4688 let client = MockTradeApiClient { force_error: true };
4689
4690 let params = MarginAccountCancelOrderParams::builder("symbol_example".to_string())
4691 .build()
4692 .unwrap();
4693
4694 match client.margin_account_cancel_order(params).await {
4695 Ok(_) => panic!("Expected an error"),
4696 Err(err) => {
4697 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4698 }
4699 }
4700 });
4701 }
4702
4703 #[test]
4704 fn margin_account_new_oco_required_params_success() {
4705 TOKIO_SHARED_RT.block_on(async {
4706 let client = MockTradeApiClient { force_error: false };
4707
4708 let params = MarginAccountNewOcoParams::builder("symbol_example".to_string(),MarginAccountNewOcoSideEnum::Buy,dec!(1.0),dec!(1.0),dec!(1.0),).build().unwrap();
4709
4710 let resp_json: Value = serde_json::from_str(r#"{"orderListId":0,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"JYVpp3F0f5CAG15DhtrqLp","transactionTime":1563417480525,"symbol":"LTCBTC","marginBuyBorrowAmount":"5","marginBuyBorrowAsset":"BTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"Kk7sqHb9J6mJWTMDVW7Vos"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"xTXKaGYd4bluPVp78IVRvl"}],"orderReports":[{"symbol":"LTCBTC","orderId":2,"orderListId":0,"clientOrderId":"Kk7sqHb9J6mJWTMDVW7Vos","transactTime":1563417480525,"price":"0.000000","origQty":"0.624363","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"NEW","timeInForce":"GTC","type":"STOP_LOSS","side":"BUY","stopPrice":"0.960664","selfTradePreventionMode":"NONE"},{"symbol":"LTCBTC","orderId":3,"orderListId":0,"clientOrderId":"xTXKaGYd4bluPVp78IVRvl","transactTime":1563417480525,"price":"0.036435","origQty":"0.624363","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"NEW","timeInForce":"GTC","type":"LIMIT_MAKER","side":"BUY","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4711 let expected_response : models::MarginAccountNewOcoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOcoResponse");
4712
4713 let resp = client.margin_account_new_oco(params).await.expect("Expected a response");
4714 let data_future = resp.data();
4715 let actual_response = data_future.await.unwrap();
4716 assert_eq!(actual_response, expected_response);
4717 });
4718 }
4719
4720 #[test]
4721 fn margin_account_new_oco_optional_params_success() {
4722 TOKIO_SHARED_RT.block_on(async {
4723 let client = MockTradeApiClient { force_error: false };
4724
4725 let params = MarginAccountNewOcoParams::builder("symbol_example".to_string(),MarginAccountNewOcoSideEnum::Buy,dec!(1.0),dec!(1.0),dec!(1.0),).is_isolated("false".to_string()).list_client_order_id("1".to_string()).limit_client_order_id("1".to_string()).limit_iceberg_qty(dec!(1.0)).stop_client_order_id("1".to_string()).stop_limit_price(dec!(1.0)).stop_iceberg_qty(dec!(1.0)).stop_limit_time_in_force("stop_limit_time_in_force_example".to_string()).new_order_resp_type(MarginAccountNewOcoNewOrderRespTypeEnum::Ack).side_effect_type("NO_SIDE_EFFECT".to_string()).self_trade_prevention_mode("NONE".to_string()).auto_repay_at_cancel(true).recv_window(5000).build().unwrap();
4726
4727 let resp_json: Value = serde_json::from_str(r#"{"orderListId":0,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"JYVpp3F0f5CAG15DhtrqLp","transactionTime":1563417480525,"symbol":"LTCBTC","marginBuyBorrowAmount":"5","marginBuyBorrowAsset":"BTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"Kk7sqHb9J6mJWTMDVW7Vos"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"xTXKaGYd4bluPVp78IVRvl"}],"orderReports":[{"symbol":"LTCBTC","orderId":2,"orderListId":0,"clientOrderId":"Kk7sqHb9J6mJWTMDVW7Vos","transactTime":1563417480525,"price":"0.000000","origQty":"0.624363","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"NEW","timeInForce":"GTC","type":"STOP_LOSS","side":"BUY","stopPrice":"0.960664","selfTradePreventionMode":"NONE"},{"symbol":"LTCBTC","orderId":3,"orderListId":0,"clientOrderId":"xTXKaGYd4bluPVp78IVRvl","transactTime":1563417480525,"price":"0.036435","origQty":"0.624363","executedQty":"0.000000","cummulativeQuoteQty":"0.000000","status":"NEW","timeInForce":"GTC","type":"LIMIT_MAKER","side":"BUY","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4728 let expected_response : models::MarginAccountNewOcoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOcoResponse");
4729
4730 let resp = client.margin_account_new_oco(params).await.expect("Expected a response");
4731 let data_future = resp.data();
4732 let actual_response = data_future.await.unwrap();
4733 assert_eq!(actual_response, expected_response);
4734 });
4735 }
4736
4737 #[test]
4738 fn margin_account_new_oco_response_error() {
4739 TOKIO_SHARED_RT.block_on(async {
4740 let client = MockTradeApiClient { force_error: true };
4741
4742 let params = MarginAccountNewOcoParams::builder(
4743 "symbol_example".to_string(),
4744 MarginAccountNewOcoSideEnum::Buy,
4745 dec!(1.0),
4746 dec!(1.0),
4747 dec!(1.0),
4748 )
4749 .build()
4750 .unwrap();
4751
4752 match client.margin_account_new_oco(params).await {
4753 Ok(_) => panic!("Expected an error"),
4754 Err(err) => {
4755 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4756 }
4757 }
4758 });
4759 }
4760
4761 #[test]
4762 fn margin_account_new_order_required_params_success() {
4763 TOKIO_SHARED_RT.block_on(async {
4764 let client = MockTradeApiClient { force_error: false };
4765
4766 let params = MarginAccountNewOrderParams::builder("symbol_example".to_string(),MarginAccountNewOrderSideEnum::Buy,"r#type_example".to_string(),).build().unwrap();
4767
4768 let resp_json: Value = serde_json::from_str(r#"{"symbol":"BTCUSDT","orderId":26769564559,"clientOrderId":"E156O3KP4gOif65bjuUK5V","isIsolated":false,"transactTime":1713873075893,"price":"0","origQty":"0.001","executedQty":"0.001","cummulativeQuoteQty":"65.98253","status":"FILLED","timeInForce":"GTC","type":"MARKET","side":"SELL","selfTradePreventionMode":"EXPIRE_MAKER","marginBuyBorrowAmount":5,"marginBuyBorrowAsset":"BTC","fills":[{"price":"65982.53","qty":"0.001","commission":"0.06598253","commissionAsset":"USDT","tradeId":3570680726}]}"#).unwrap();
4769 let expected_response : models::MarginAccountNewOrderResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOrderResponse");
4770
4771 let resp = client.margin_account_new_order(params).await.expect("Expected a response");
4772 let data_future = resp.data();
4773 let actual_response = data_future.await.unwrap();
4774 assert_eq!(actual_response, expected_response);
4775 });
4776 }
4777
4778 #[test]
4779 fn margin_account_new_order_optional_params_success() {
4780 TOKIO_SHARED_RT.block_on(async {
4781 let client = MockTradeApiClient { force_error: false };
4782
4783 let params = MarginAccountNewOrderParams::builder("symbol_example".to_string(),MarginAccountNewOrderSideEnum::Buy,"r#type_example".to_string(),).is_isolated("false".to_string()).quantity(dec!(1.0)).quote_order_qty(dec!(1.0)).price(dec!(1.0)).stop_price(dec!(1.0)).new_client_order_id("1".to_string()).iceberg_qty(dec!(1.0)).new_order_resp_type(MarginAccountNewOrderNewOrderRespTypeEnum::Ack).side_effect_type("NO_SIDE_EFFECT".to_string()).time_in_force(MarginAccountNewOrderTimeInForceEnum::Gtc).self_trade_prevention_mode("NONE".to_string()).auto_repay_at_cancel(true).recv_window(5000).build().unwrap();
4784
4785 let resp_json: Value = serde_json::from_str(r#"{"symbol":"BTCUSDT","orderId":26769564559,"clientOrderId":"E156O3KP4gOif65bjuUK5V","isIsolated":false,"transactTime":1713873075893,"price":"0","origQty":"0.001","executedQty":"0.001","cummulativeQuoteQty":"65.98253","status":"FILLED","timeInForce":"GTC","type":"MARKET","side":"SELL","selfTradePreventionMode":"EXPIRE_MAKER","marginBuyBorrowAmount":5,"marginBuyBorrowAsset":"BTC","fills":[{"price":"65982.53","qty":"0.001","commission":"0.06598253","commissionAsset":"USDT","tradeId":3570680726}]}"#).unwrap();
4786 let expected_response : models::MarginAccountNewOrderResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOrderResponse");
4787
4788 let resp = client.margin_account_new_order(params).await.expect("Expected a response");
4789 let data_future = resp.data();
4790 let actual_response = data_future.await.unwrap();
4791 assert_eq!(actual_response, expected_response);
4792 });
4793 }
4794
4795 #[test]
4796 fn margin_account_new_order_response_error() {
4797 TOKIO_SHARED_RT.block_on(async {
4798 let client = MockTradeApiClient { force_error: true };
4799
4800 let params = MarginAccountNewOrderParams::builder(
4801 "symbol_example".to_string(),
4802 MarginAccountNewOrderSideEnum::Buy,
4803 "r#type_example".to_string(),
4804 )
4805 .build()
4806 .unwrap();
4807
4808 match client.margin_account_new_order(params).await {
4809 Ok(_) => panic!("Expected an error"),
4810 Err(err) => {
4811 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4812 }
4813 }
4814 });
4815 }
4816
4817 #[test]
4818 fn margin_account_new_oto_required_params_success() {
4819 TOKIO_SHARED_RT.block_on(async {
4820 let client = MockTradeApiClient { force_error: false };
4821
4822 let params = MarginAccountNewOtoParams::builder("symbol_example".to_string(),"working_type_example".to_string(),"working_side_example".to_string(),dec!(1.0),dec!(1.0),dec!(1.0),"Order Types".to_string(),"pending_side_example".to_string(),dec!(1.0),).build().unwrap();
4823
4824 let resp_json: Value = serde_json::from_str(r#"{"orderListId":13551,"contingencyType":"OTO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"JDuOrsu0Ge8GTyvx8J7VTD","transactionTime":1725521998054,"symbol":"BTCUSDT","isIsolated":false,"orders":[{"symbol":"BTCUSDT","orderId":29896699,"clientOrderId":"y8RB6tQEMuHUXybqbtzTxk"},{"symbol":"BTCUSDT","orderId":29896700,"clientOrderId":"dKQEdh5HhXb7Lpp85jz1dQ"}],"orderReports":[{"symbol":"BTCUSDT","orderId":29896699,"orderListId":13551,"clientOrderId":"y8RB6tQEMuHUXybqbtzTxk","transactTime":1725521998054,"price":"80000.00000000","origQty":"0.02000000","executedQty":"0","cummulativeQuoteQty":"0","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL","selfTradePreventionMode":"NONE"},{"symbol":"BTCUSDT","orderId":29896700,"orderListId":13551,"clientOrderId":"dKQEdh5HhXb7Lpp85jz1dQ","transactTime":1725521998054,"price":"50000.00000000","origQty":"0.02000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4825 let expected_response : models::MarginAccountNewOtoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOtoResponse");
4826
4827 let resp = client.margin_account_new_oto(params).await.expect("Expected a response");
4828 let data_future = resp.data();
4829 let actual_response = data_future.await.unwrap();
4830 assert_eq!(actual_response, expected_response);
4831 });
4832 }
4833
4834 #[test]
4835 fn margin_account_new_oto_optional_params_success() {
4836 TOKIO_SHARED_RT.block_on(async {
4837 let client = MockTradeApiClient { force_error: false };
4838
4839 let params = MarginAccountNewOtoParams::builder("symbol_example".to_string(),"working_type_example".to_string(),"working_side_example".to_string(),dec!(1.0),dec!(1.0),dec!(1.0),"Order Types".to_string(),"pending_side_example".to_string(),dec!(1.0),).is_isolated("false".to_string()).list_client_order_id("1".to_string()).new_order_resp_type(MarginAccountNewOtoNewOrderRespTypeEnum::Ack).side_effect_type("NO_SIDE_EFFECT".to_string()).self_trade_prevention_mode("NONE".to_string()).auto_repay_at_cancel(true).working_client_order_id("1".to_string()).working_time_in_force("working_time_in_force_example".to_string()).pending_client_order_id("1".to_string()).pending_price(dec!(1.0)).pending_stop_price(dec!(1.0)).pending_trailing_delta(dec!(1.0)).pending_iceberg_qty(dec!(1.0)).pending_time_in_force("pending_time_in_force_example".to_string()).build().unwrap();
4840
4841 let resp_json: Value = serde_json::from_str(r#"{"orderListId":13551,"contingencyType":"OTO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"JDuOrsu0Ge8GTyvx8J7VTD","transactionTime":1725521998054,"symbol":"BTCUSDT","isIsolated":false,"orders":[{"symbol":"BTCUSDT","orderId":29896699,"clientOrderId":"y8RB6tQEMuHUXybqbtzTxk"},{"symbol":"BTCUSDT","orderId":29896700,"clientOrderId":"dKQEdh5HhXb7Lpp85jz1dQ"}],"orderReports":[{"symbol":"BTCUSDT","orderId":29896699,"orderListId":13551,"clientOrderId":"y8RB6tQEMuHUXybqbtzTxk","transactTime":1725521998054,"price":"80000.00000000","origQty":"0.02000000","executedQty":"0","cummulativeQuoteQty":"0","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL","selfTradePreventionMode":"NONE"},{"symbol":"BTCUSDT","orderId":29896700,"orderListId":13551,"clientOrderId":"dKQEdh5HhXb7Lpp85jz1dQ","transactTime":1725521998054,"price":"50000.00000000","origQty":"0.02000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4842 let expected_response : models::MarginAccountNewOtoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOtoResponse");
4843
4844 let resp = client.margin_account_new_oto(params).await.expect("Expected a response");
4845 let data_future = resp.data();
4846 let actual_response = data_future.await.unwrap();
4847 assert_eq!(actual_response, expected_response);
4848 });
4849 }
4850
4851 #[test]
4852 fn margin_account_new_oto_response_error() {
4853 TOKIO_SHARED_RT.block_on(async {
4854 let client = MockTradeApiClient { force_error: true };
4855
4856 let params = MarginAccountNewOtoParams::builder(
4857 "symbol_example".to_string(),
4858 "working_type_example".to_string(),
4859 "working_side_example".to_string(),
4860 dec!(1.0),
4861 dec!(1.0),
4862 dec!(1.0),
4863 "Order Types".to_string(),
4864 "pending_side_example".to_string(),
4865 dec!(1.0),
4866 )
4867 .build()
4868 .unwrap();
4869
4870 match client.margin_account_new_oto(params).await {
4871 Ok(_) => panic!("Expected an error"),
4872 Err(err) => {
4873 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4874 }
4875 }
4876 });
4877 }
4878
4879 #[test]
4880 fn margin_account_new_otoco_required_params_success() {
4881 TOKIO_SHARED_RT.block_on(async {
4882 let client = MockTradeApiClient { force_error: false };
4883
4884 let params = MarginAccountNewOtocoParams::builder("symbol_example".to_string(),"working_type_example".to_string(),"working_side_example".to_string(),dec!(1.0),dec!(1.0),"pending_side_example".to_string(),dec!(1.0),"pending_above_type_example".to_string(),).build().unwrap();
4885
4886 let resp_json: Value = serde_json::from_str(r#"{"orderListId":13509,"contingencyType":"OTO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"u2AUo48LLef5qVenRtwJZy","transactionTime":1725521881300,"symbol":"BNBUSDT","isIsolated":false,"orders":[{"symbol":"BNBUSDT","orderId":28282534,"clientOrderId":"IfYDxvrZI4kiyqYpRH13iI"},{"symbol":"BNBUSDT","orderId":28282535,"clientOrderId":"0HCSsPRxVfW8BkTUy9z4np"},{"symbol":"BNBUSDT","orderId":28282536,"clientOrderId":"dypsgdxWnLY75kwT930cbD"}],"orderReports":[{"symbol":"BNBUSDT","orderId":28282534,"orderListId":13509,"clientOrderId":"IfYDxvrZI4kiyqYpRH13iI","transactTime":1725521881300,"price":"300.00000000","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"symbol":"BNBUSDT","orderId":28282535,"orderListId":13509,"clientOrderId":"0HCSsPRxVfW8BkTUy9z4np","transactTime":1725521881300,"price":"0E-8","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"STOP_LOSS","side":"SELL","stopPrice":"299.00000000","selfTradePreventionMode":"NONE"},{"symbol":"BNBUSDT","orderId":28282536,"orderListId":13509,"clientOrderId":"dypsgdxWnLY75kwT930cbD","transactTime":1725521881300,"price":"301.00000000","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"LIMIT_MAKER","side":"SELL","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4887 let expected_response : models::MarginAccountNewOtocoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOtocoResponse");
4888
4889 let resp = client.margin_account_new_otoco(params).await.expect("Expected a response");
4890 let data_future = resp.data();
4891 let actual_response = data_future.await.unwrap();
4892 assert_eq!(actual_response, expected_response);
4893 });
4894 }
4895
4896 #[test]
4897 fn margin_account_new_otoco_optional_params_success() {
4898 TOKIO_SHARED_RT.block_on(async {
4899 let client = MockTradeApiClient { force_error: false };
4900
4901 let params = MarginAccountNewOtocoParams::builder("symbol_example".to_string(),"working_type_example".to_string(),"working_side_example".to_string(),dec!(1.0),dec!(1.0),"pending_side_example".to_string(),dec!(1.0),"pending_above_type_example".to_string(),).is_isolated("false".to_string()).side_effect_type("NO_SIDE_EFFECT".to_string()).auto_repay_at_cancel(true).list_client_order_id("1".to_string()).new_order_resp_type(MarginAccountNewOtocoNewOrderRespTypeEnum::Ack).self_trade_prevention_mode("NONE".to_string()).working_client_order_id("1".to_string()).working_iceberg_qty(dec!(1.0)).working_time_in_force("working_time_in_force_example".to_string()).pending_above_client_order_id("1".to_string()).pending_above_price(dec!(1.0)).pending_above_stop_price(dec!(1.0)).pending_above_trailing_delta(dec!(1.0)).pending_above_iceberg_qty(dec!(1.0)).pending_above_time_in_force("pending_above_time_in_force_example".to_string()).pending_below_type("pending_below_type_example".to_string()).pending_below_client_order_id("1".to_string()).pending_below_price(dec!(1.0)).pending_below_stop_price(dec!(1.0)).pending_below_trailing_delta(dec!(1.0)).pending_below_iceberg_qty(dec!(1.0)).pending_below_time_in_force("pending_below_time_in_force_example".to_string()).build().unwrap();
4902
4903 let resp_json: Value = serde_json::from_str(r#"{"orderListId":13509,"contingencyType":"OTO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"u2AUo48LLef5qVenRtwJZy","transactionTime":1725521881300,"symbol":"BNBUSDT","isIsolated":false,"orders":[{"symbol":"BNBUSDT","orderId":28282534,"clientOrderId":"IfYDxvrZI4kiyqYpRH13iI"},{"symbol":"BNBUSDT","orderId":28282535,"clientOrderId":"0HCSsPRxVfW8BkTUy9z4np"},{"symbol":"BNBUSDT","orderId":28282536,"clientOrderId":"dypsgdxWnLY75kwT930cbD"}],"orderReports":[{"symbol":"BNBUSDT","orderId":28282534,"orderListId":13509,"clientOrderId":"IfYDxvrZI4kiyqYpRH13iI","transactTime":1725521881300,"price":"300.00000000","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"BUY","selfTradePreventionMode":"NONE"},{"symbol":"BNBUSDT","orderId":28282535,"orderListId":13509,"clientOrderId":"0HCSsPRxVfW8BkTUy9z4np","transactTime":1725521881300,"price":"0E-8","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"STOP_LOSS","side":"SELL","stopPrice":"299.00000000","selfTradePreventionMode":"NONE"},{"symbol":"BNBUSDT","orderId":28282536,"orderListId":13509,"clientOrderId":"dypsgdxWnLY75kwT930cbD","transactTime":1725521881300,"price":"301.00000000","origQty":"1.00000000","executedQty":"0","cummulativeQuoteQty":"0","status":"PENDING_NEW","timeInForce":"GTC","type":"LIMIT_MAKER","side":"SELL","selfTradePreventionMode":"NONE"}]}"#).unwrap();
4904 let expected_response : models::MarginAccountNewOtocoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginAccountNewOtocoResponse");
4905
4906 let resp = client.margin_account_new_otoco(params).await.expect("Expected a response");
4907 let data_future = resp.data();
4908 let actual_response = data_future.await.unwrap();
4909 assert_eq!(actual_response, expected_response);
4910 });
4911 }
4912
4913 #[test]
4914 fn margin_account_new_otoco_response_error() {
4915 TOKIO_SHARED_RT.block_on(async {
4916 let client = MockTradeApiClient { force_error: true };
4917
4918 let params = MarginAccountNewOtocoParams::builder(
4919 "symbol_example".to_string(),
4920 "working_type_example".to_string(),
4921 "working_side_example".to_string(),
4922 dec!(1.0),
4923 dec!(1.0),
4924 "pending_side_example".to_string(),
4925 dec!(1.0),
4926 "pending_above_type_example".to_string(),
4927 )
4928 .build()
4929 .unwrap();
4930
4931 match client.margin_account_new_otoco(params).await {
4932 Ok(_) => panic!("Expected an error"),
4933 Err(err) => {
4934 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4935 }
4936 }
4937 });
4938 }
4939
4940 #[test]
4941 fn margin_manual_liquidation_required_params_success() {
4942 TOKIO_SHARED_RT.block_on(async {
4943 let client = MockTradeApiClient { force_error: false };
4944
4945 let params = MarginManualLiquidationParams::builder("r#type_example".to_string(),).build().unwrap();
4946
4947 let resp_json: Value = serde_json::from_str(r#"{"asset":"ETH","interest":"0.00083334","principal":"0.001","liabilityAsset":"USDT","liabilityQty":0.3552}"#).unwrap();
4948 let expected_response : models::MarginManualLiquidationResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginManualLiquidationResponse");
4949
4950 let resp = client.margin_manual_liquidation(params).await.expect("Expected a response");
4951 let data_future = resp.data();
4952 let actual_response = data_future.await.unwrap();
4953 assert_eq!(actual_response, expected_response);
4954 });
4955 }
4956
4957 #[test]
4958 fn margin_manual_liquidation_optional_params_success() {
4959 TOKIO_SHARED_RT.block_on(async {
4960 let client = MockTradeApiClient { force_error: false };
4961
4962 let params = MarginManualLiquidationParams::builder("r#type_example".to_string(),).symbol("symbol_example".to_string()).recv_window(5000).build().unwrap();
4963
4964 let resp_json: Value = serde_json::from_str(r#"{"asset":"ETH","interest":"0.00083334","principal":"0.001","liabilityAsset":"USDT","liabilityQty":0.3552}"#).unwrap();
4965 let expected_response : models::MarginManualLiquidationResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::MarginManualLiquidationResponse");
4966
4967 let resp = client.margin_manual_liquidation(params).await.expect("Expected a response");
4968 let data_future = resp.data();
4969 let actual_response = data_future.await.unwrap();
4970 assert_eq!(actual_response, expected_response);
4971 });
4972 }
4973
4974 #[test]
4975 fn margin_manual_liquidation_response_error() {
4976 TOKIO_SHARED_RT.block_on(async {
4977 let client = MockTradeApiClient { force_error: true };
4978
4979 let params = MarginManualLiquidationParams::builder("r#type_example".to_string())
4980 .build()
4981 .unwrap();
4982
4983 match client.margin_manual_liquidation(params).await {
4984 Ok(_) => panic!("Expected an error"),
4985 Err(err) => {
4986 assert_eq!(err.to_string(), "Connector client error: ResponseError");
4987 }
4988 }
4989 });
4990 }
4991
4992 #[test]
4993 fn query_current_margin_order_count_usage_required_params_success() {
4994 TOKIO_SHARED_RT.block_on(async {
4995 let client = MockTradeApiClient { force_error: false };
4996
4997 let params = QueryCurrentMarginOrderCountUsageParams::builder().build().unwrap();
4998
4999 let resp_json: Value = serde_json::from_str(r#"[{"rateLimitType":"ORDERS","interval":"SECOND","intervalNum":10,"limit":10000,"count":0},{"rateLimitType":"ORDERS","interval":"DAY","intervalNum":1,"limit":20000,"count":0}]"#).unwrap();
5000 let expected_response : Vec<models::QueryCurrentMarginOrderCountUsageResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>");
5001
5002 let resp = client.query_current_margin_order_count_usage(params).await.expect("Expected a response");
5003 let data_future = resp.data();
5004 let actual_response = data_future.await.unwrap();
5005 assert_eq!(actual_response, expected_response);
5006 });
5007 }
5008
5009 #[test]
5010 fn query_current_margin_order_count_usage_optional_params_success() {
5011 TOKIO_SHARED_RT.block_on(async {
5012 let client = MockTradeApiClient { force_error: false };
5013
5014 let params = QueryCurrentMarginOrderCountUsageParams::builder().is_isolated("false".to_string()).symbol("symbol_example".to_string()).recv_window(5000).build().unwrap();
5015
5016 let resp_json: Value = serde_json::from_str(r#"[{"rateLimitType":"ORDERS","interval":"SECOND","intervalNum":10,"limit":10000,"count":0},{"rateLimitType":"ORDERS","interval":"DAY","intervalNum":1,"limit":20000,"count":0}]"#).unwrap();
5017 let expected_response : Vec<models::QueryCurrentMarginOrderCountUsageResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryCurrentMarginOrderCountUsageResponseInner>");
5018
5019 let resp = client.query_current_margin_order_count_usage(params).await.expect("Expected a response");
5020 let data_future = resp.data();
5021 let actual_response = data_future.await.unwrap();
5022 assert_eq!(actual_response, expected_response);
5023 });
5024 }
5025
5026 #[test]
5027 fn query_current_margin_order_count_usage_response_error() {
5028 TOKIO_SHARED_RT.block_on(async {
5029 let client = MockTradeApiClient { force_error: true };
5030
5031 let params = QueryCurrentMarginOrderCountUsageParams::builder()
5032 .build()
5033 .unwrap();
5034
5035 match client.query_current_margin_order_count_usage(params).await {
5036 Ok(_) => panic!("Expected an error"),
5037 Err(err) => {
5038 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5039 }
5040 }
5041 });
5042 }
5043
5044 #[test]
5045 fn query_margin_accounts_all_oco_required_params_success() {
5046 TOKIO_SHARED_RT.block_on(async {
5047 let client = MockTradeApiClient { force_error: false };
5048
5049 let params = QueryMarginAccountsAllOcoParams::builder().build().unwrap();
5050
5051 let resp_json: Value = serde_json::from_str(r#"[{"orderListId":29,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"amEEAXryFzFwYF1FeRpUoZ","transactionTime":1565245913483,"symbol":"LTCBTC","isIsolated":true,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"oD7aesZqjEGlZrbtRpy5zB"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"Jr1h6xirOxgeJOUuYQS7V3"}]},{"orderListId":28,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"hG7hFNxJV6cZy3Ze4AUT4d","transactionTime":1565245913407,"symbol":"LTCBTC","orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"j6lFOfbmFMRjTYA7rRJ0LP"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"z0KCjOdditiLS5ekAFtK81"}]}]"#).unwrap();
5052 let expected_response : Vec<models::QueryMarginAccountsAllOcoResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsAllOcoResponseInner>");
5053
5054 let resp = client.query_margin_accounts_all_oco(params).await.expect("Expected a response");
5055 let data_future = resp.data();
5056 let actual_response = data_future.await.unwrap();
5057 assert_eq!(actual_response, expected_response);
5058 });
5059 }
5060
5061 #[test]
5062 fn query_margin_accounts_all_oco_optional_params_success() {
5063 TOKIO_SHARED_RT.block_on(async {
5064 let client = MockTradeApiClient { force_error: false };
5065
5066 let params = QueryMarginAccountsAllOcoParams::builder().is_isolated("false".to_string()).symbol("symbol_example".to_string()).from_id(1).start_time(1623319461670).end_time(1641782889000).limit(500).recv_window(5000).build().unwrap();
5067
5068 let resp_json: Value = serde_json::from_str(r#"[{"orderListId":29,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"amEEAXryFzFwYF1FeRpUoZ","transactionTime":1565245913483,"symbol":"LTCBTC","isIsolated":true,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"oD7aesZqjEGlZrbtRpy5zB"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"Jr1h6xirOxgeJOUuYQS7V3"}]},{"orderListId":28,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"hG7hFNxJV6cZy3Ze4AUT4d","transactionTime":1565245913407,"symbol":"LTCBTC","orders":[{"symbol":"LTCBTC","orderId":2,"clientOrderId":"j6lFOfbmFMRjTYA7rRJ0LP"},{"symbol":"LTCBTC","orderId":3,"clientOrderId":"z0KCjOdditiLS5ekAFtK81"}]}]"#).unwrap();
5069 let expected_response : Vec<models::QueryMarginAccountsAllOcoResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsAllOcoResponseInner>");
5070
5071 let resp = client.query_margin_accounts_all_oco(params).await.expect("Expected a response");
5072 let data_future = resp.data();
5073 let actual_response = data_future.await.unwrap();
5074 assert_eq!(actual_response, expected_response);
5075 });
5076 }
5077
5078 #[test]
5079 fn query_margin_accounts_all_oco_response_error() {
5080 TOKIO_SHARED_RT.block_on(async {
5081 let client = MockTradeApiClient { force_error: true };
5082
5083 let params = QueryMarginAccountsAllOcoParams::builder().build().unwrap();
5084
5085 match client.query_margin_accounts_all_oco(params).await {
5086 Ok(_) => panic!("Expected an error"),
5087 Err(err) => {
5088 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5089 }
5090 }
5091 });
5092 }
5093
5094 #[test]
5095 fn query_margin_accounts_all_orders_required_params_success() {
5096 TOKIO_SHARED_RT.block_on(async {
5097 let client = MockTradeApiClient { force_error: false };
5098
5099 let params = QueryMarginAccountsAllOrdersParams::builder("symbol_example".to_string(),).build().unwrap();
5100
5101 let resp_json: Value = serde_json::from_str(r#"[{"clientOrderId":"D2KDy4DIeS56PvkM13f8cP","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":false,"orderId":41295,"origQty":"5.31000000","price":"0.22500000","side":"SELL","status":"CANCELED","stopPrice":"0.18000000","symbol":"BNBBTC","isIsolated":false,"time":1565769338806,"timeInForce":"GTC","type":"TAKE_PROFIT_LIMIT","selfTradePreventionMode":"NONE","updateTime":1565769342148},{"clientOrderId":"gXYtqhcEAs2Rn9SUD9nRKx","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"1.00000000","isWorking":true,"orderId":41296,"origQty":"6.65000000","price":"0.18000000","side":"SELL","status":"CANCELED","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":false,"time":1565769348687,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1565769352226}]"#).unwrap();
5102 let expected_response : Vec<models::QueryMarginAccountsAllOrdersResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsAllOrdersResponseInner>");
5103
5104 let resp = client.query_margin_accounts_all_orders(params).await.expect("Expected a response");
5105 let data_future = resp.data();
5106 let actual_response = data_future.await.unwrap();
5107 assert_eq!(actual_response, expected_response);
5108 });
5109 }
5110
5111 #[test]
5112 fn query_margin_accounts_all_orders_optional_params_success() {
5113 TOKIO_SHARED_RT.block_on(async {
5114 let client = MockTradeApiClient { force_error: false };
5115
5116 let params = QueryMarginAccountsAllOrdersParams::builder("symbol_example".to_string(),).is_isolated("false".to_string()).order_id(1).start_time(1623319461670).end_time(1641782889000).limit(500).recv_window(5000).build().unwrap();
5117
5118 let resp_json: Value = serde_json::from_str(r#"[{"clientOrderId":"D2KDy4DIeS56PvkM13f8cP","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":false,"orderId":41295,"origQty":"5.31000000","price":"0.22500000","side":"SELL","status":"CANCELED","stopPrice":"0.18000000","symbol":"BNBBTC","isIsolated":false,"time":1565769338806,"timeInForce":"GTC","type":"TAKE_PROFIT_LIMIT","selfTradePreventionMode":"NONE","updateTime":1565769342148},{"clientOrderId":"gXYtqhcEAs2Rn9SUD9nRKx","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"1.00000000","isWorking":true,"orderId":41296,"origQty":"6.65000000","price":"0.18000000","side":"SELL","status":"CANCELED","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":false,"time":1565769348687,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1565769352226}]"#).unwrap();
5119 let expected_response : Vec<models::QueryMarginAccountsAllOrdersResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsAllOrdersResponseInner>");
5120
5121 let resp = client.query_margin_accounts_all_orders(params).await.expect("Expected a response");
5122 let data_future = resp.data();
5123 let actual_response = data_future.await.unwrap();
5124 assert_eq!(actual_response, expected_response);
5125 });
5126 }
5127
5128 #[test]
5129 fn query_margin_accounts_all_orders_response_error() {
5130 TOKIO_SHARED_RT.block_on(async {
5131 let client = MockTradeApiClient { force_error: true };
5132
5133 let params = QueryMarginAccountsAllOrdersParams::builder("symbol_example".to_string())
5134 .build()
5135 .unwrap();
5136
5137 match client.query_margin_accounts_all_orders(params).await {
5138 Ok(_) => panic!("Expected an error"),
5139 Err(err) => {
5140 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5141 }
5142 }
5143 });
5144 }
5145
5146 #[test]
5147 fn query_margin_accounts_oco_required_params_success() {
5148 TOKIO_SHARED_RT.block_on(async {
5149 let client = MockTradeApiClient { force_error: false };
5150
5151 let params = QueryMarginAccountsOcoParams::builder().build().unwrap();
5152
5153 let resp_json: Value = serde_json::from_str(r#"{"orderListId":27,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"h2USkA5YQpaXHPIrkd96xE","transactionTime":1565245656253,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"qD1gy3kc3Gx0rihm9Y3xwS"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"ARzZ9I00CPM8i3NhmU9Ega"}]}"#).unwrap();
5154 let expected_response : models::QueryMarginAccountsOcoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryMarginAccountsOcoResponse");
5155
5156 let resp = client.query_margin_accounts_oco(params).await.expect("Expected a response");
5157 let data_future = resp.data();
5158 let actual_response = data_future.await.unwrap();
5159 assert_eq!(actual_response, expected_response);
5160 });
5161 }
5162
5163 #[test]
5164 fn query_margin_accounts_oco_optional_params_success() {
5165 TOKIO_SHARED_RT.block_on(async {
5166 let client = MockTradeApiClient { force_error: false };
5167
5168 let params = QueryMarginAccountsOcoParams::builder().is_isolated("false".to_string()).symbol("symbol_example".to_string()).order_list_id(1).orig_client_order_id("1".to_string()).recv_window(5000).build().unwrap();
5169
5170 let resp_json: Value = serde_json::from_str(r#"{"orderListId":27,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"h2USkA5YQpaXHPIrkd96xE","transactionTime":1565245656253,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"qD1gy3kc3Gx0rihm9Y3xwS"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"ARzZ9I00CPM8i3NhmU9Ega"}]}"#).unwrap();
5171 let expected_response : models::QueryMarginAccountsOcoResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryMarginAccountsOcoResponse");
5172
5173 let resp = client.query_margin_accounts_oco(params).await.expect("Expected a response");
5174 let data_future = resp.data();
5175 let actual_response = data_future.await.unwrap();
5176 assert_eq!(actual_response, expected_response);
5177 });
5178 }
5179
5180 #[test]
5181 fn query_margin_accounts_oco_response_error() {
5182 TOKIO_SHARED_RT.block_on(async {
5183 let client = MockTradeApiClient { force_error: true };
5184
5185 let params = QueryMarginAccountsOcoParams::builder().build().unwrap();
5186
5187 match client.query_margin_accounts_oco(params).await {
5188 Ok(_) => panic!("Expected an error"),
5189 Err(err) => {
5190 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5191 }
5192 }
5193 });
5194 }
5195
5196 #[test]
5197 fn query_margin_accounts_open_oco_required_params_success() {
5198 TOKIO_SHARED_RT.block_on(async {
5199 let client = MockTradeApiClient { force_error: false };
5200
5201 let params = QueryMarginAccountsOpenOcoParams::builder().build().unwrap();
5202
5203 let resp_json: Value = serde_json::from_str(r#"[{"orderListId":31,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"wuB13fmulKj3YjdqWEcsnp","transactionTime":1565246080644,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"r3EH2N76dHfLoSZWIUw1bT"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"Cv1SnyPD3qhqpbjpYEHbd2"}]}]"#).unwrap();
5204 let expected_response : Vec<models::QueryMarginAccountsOpenOcoResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsOpenOcoResponseInner>");
5205
5206 let resp = client.query_margin_accounts_open_oco(params).await.expect("Expected a response");
5207 let data_future = resp.data();
5208 let actual_response = data_future.await.unwrap();
5209 assert_eq!(actual_response, expected_response);
5210 });
5211 }
5212
5213 #[test]
5214 fn query_margin_accounts_open_oco_optional_params_success() {
5215 TOKIO_SHARED_RT.block_on(async {
5216 let client = MockTradeApiClient { force_error: false };
5217
5218 let params = QueryMarginAccountsOpenOcoParams::builder().is_isolated("false".to_string()).symbol("symbol_example".to_string()).recv_window(5000).build().unwrap();
5219
5220 let resp_json: Value = serde_json::from_str(r#"[{"orderListId":31,"contingencyType":"OCO","listStatusType":"EXEC_STARTED","listOrderStatus":"EXECUTING","listClientOrderId":"wuB13fmulKj3YjdqWEcsnp","transactionTime":1565246080644,"symbol":"LTCBTC","isIsolated":false,"orders":[{"symbol":"LTCBTC","orderId":4,"clientOrderId":"r3EH2N76dHfLoSZWIUw1bT"},{"symbol":"LTCBTC","orderId":5,"clientOrderId":"Cv1SnyPD3qhqpbjpYEHbd2"}]}]"#).unwrap();
5221 let expected_response : Vec<models::QueryMarginAccountsOpenOcoResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsOpenOcoResponseInner>");
5222
5223 let resp = client.query_margin_accounts_open_oco(params).await.expect("Expected a response");
5224 let data_future = resp.data();
5225 let actual_response = data_future.await.unwrap();
5226 assert_eq!(actual_response, expected_response);
5227 });
5228 }
5229
5230 #[test]
5231 fn query_margin_accounts_open_oco_response_error() {
5232 TOKIO_SHARED_RT.block_on(async {
5233 let client = MockTradeApiClient { force_error: true };
5234
5235 let params = QueryMarginAccountsOpenOcoParams::builder().build().unwrap();
5236
5237 match client.query_margin_accounts_open_oco(params).await {
5238 Ok(_) => panic!("Expected an error"),
5239 Err(err) => {
5240 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5241 }
5242 }
5243 });
5244 }
5245
5246 #[test]
5247 fn query_margin_accounts_open_orders_required_params_success() {
5248 TOKIO_SHARED_RT.block_on(async {
5249 let client = MockTradeApiClient { force_error: false };
5250
5251 let params = QueryMarginAccountsOpenOrdersParams::builder().build().unwrap();
5252
5253 let resp_json: Value = serde_json::from_str(r#"[{"clientOrderId":"qhcZw71gAkCCTv0t0k8LUK","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":true,"orderId":211842552,"origQty":"0.30000000","price":"0.00475010","side":"SELL","status":"NEW","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":true,"time":1562040170089,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1562040170089}]"#).unwrap();
5254 let expected_response : Vec<models::QueryMarginAccountsOpenOrdersResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsOpenOrdersResponseInner>");
5255
5256 let resp = client.query_margin_accounts_open_orders(params).await.expect("Expected a response");
5257 let data_future = resp.data();
5258 let actual_response = data_future.await.unwrap();
5259 assert_eq!(actual_response, expected_response);
5260 });
5261 }
5262
5263 #[test]
5264 fn query_margin_accounts_open_orders_optional_params_success() {
5265 TOKIO_SHARED_RT.block_on(async {
5266 let client = MockTradeApiClient { force_error: false };
5267
5268 let params = QueryMarginAccountsOpenOrdersParams::builder().symbol("symbol_example".to_string()).is_isolated("false".to_string()).recv_window(5000).build().unwrap();
5269
5270 let resp_json: Value = serde_json::from_str(r#"[{"clientOrderId":"qhcZw71gAkCCTv0t0k8LUK","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":true,"orderId":211842552,"origQty":"0.30000000","price":"0.00475010","side":"SELL","status":"NEW","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":true,"time":1562040170089,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1562040170089}]"#).unwrap();
5271 let expected_response : Vec<models::QueryMarginAccountsOpenOrdersResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsOpenOrdersResponseInner>");
5272
5273 let resp = client.query_margin_accounts_open_orders(params).await.expect("Expected a response");
5274 let data_future = resp.data();
5275 let actual_response = data_future.await.unwrap();
5276 assert_eq!(actual_response, expected_response);
5277 });
5278 }
5279
5280 #[test]
5281 fn query_margin_accounts_open_orders_response_error() {
5282 TOKIO_SHARED_RT.block_on(async {
5283 let client = MockTradeApiClient { force_error: true };
5284
5285 let params = QueryMarginAccountsOpenOrdersParams::builder()
5286 .build()
5287 .unwrap();
5288
5289 match client.query_margin_accounts_open_orders(params).await {
5290 Ok(_) => panic!("Expected an error"),
5291 Err(err) => {
5292 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5293 }
5294 }
5295 });
5296 }
5297
5298 #[test]
5299 fn query_margin_accounts_order_required_params_success() {
5300 TOKIO_SHARED_RT.block_on(async {
5301 let client = MockTradeApiClient { force_error: false };
5302
5303 let params = QueryMarginAccountsOrderParams::builder("symbol_example".to_string(),).build().unwrap();
5304
5305 let resp_json: Value = serde_json::from_str(r#"{"clientOrderId":"ZwfQzuDIGpceVhKW5DvCmO","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":true,"orderId":213205622,"origQty":"0.30000000","price":"0.00493630","side":"SELL","status":"NEW","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":true,"time":1562133008725,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1562133008725}"#).unwrap();
5306 let expected_response : models::QueryMarginAccountsOrderResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryMarginAccountsOrderResponse");
5307
5308 let resp = client.query_margin_accounts_order(params).await.expect("Expected a response");
5309 let data_future = resp.data();
5310 let actual_response = data_future.await.unwrap();
5311 assert_eq!(actual_response, expected_response);
5312 });
5313 }
5314
5315 #[test]
5316 fn query_margin_accounts_order_optional_params_success() {
5317 TOKIO_SHARED_RT.block_on(async {
5318 let client = MockTradeApiClient { force_error: false };
5319
5320 let params = QueryMarginAccountsOrderParams::builder("symbol_example".to_string(),).is_isolated("false".to_string()).order_id(1).orig_client_order_id("1".to_string()).recv_window(5000).build().unwrap();
5321
5322 let resp_json: Value = serde_json::from_str(r#"{"clientOrderId":"ZwfQzuDIGpceVhKW5DvCmO","cummulativeQuoteQty":"0.00000000","executedQty":"0.00000000","icebergQty":"0.00000000","isWorking":true,"orderId":213205622,"origQty":"0.30000000","price":"0.00493630","side":"SELL","status":"NEW","stopPrice":"0.00000000","symbol":"BNBBTC","isIsolated":true,"time":1562133008725,"timeInForce":"GTC","type":"LIMIT","selfTradePreventionMode":"NONE","updateTime":1562133008725}"#).unwrap();
5323 let expected_response : models::QueryMarginAccountsOrderResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryMarginAccountsOrderResponse");
5324
5325 let resp = client.query_margin_accounts_order(params).await.expect("Expected a response");
5326 let data_future = resp.data();
5327 let actual_response = data_future.await.unwrap();
5328 assert_eq!(actual_response, expected_response);
5329 });
5330 }
5331
5332 #[test]
5333 fn query_margin_accounts_order_response_error() {
5334 TOKIO_SHARED_RT.block_on(async {
5335 let client = MockTradeApiClient { force_error: true };
5336
5337 let params = QueryMarginAccountsOrderParams::builder("symbol_example".to_string())
5338 .build()
5339 .unwrap();
5340
5341 match client.query_margin_accounts_order(params).await {
5342 Ok(_) => panic!("Expected an error"),
5343 Err(err) => {
5344 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5345 }
5346 }
5347 });
5348 }
5349
5350 #[test]
5351 fn query_margin_accounts_trade_list_required_params_success() {
5352 TOKIO_SHARED_RT.block_on(async {
5353 let client = MockTradeApiClient { force_error: false };
5354
5355 let params = QueryMarginAccountsTradeListParams::builder("symbol_example".to_string(),).build().unwrap();
5356
5357 let resp_json: Value = serde_json::from_str(r#"[{"commission":"0.00006000","commissionAsset":"BTC","id":34,"isBestMatch":true,"isBuyer":false,"isMaker":false,"orderId":39324,"price":"0.02000000","qty":"3.00000000","symbol":"BNBBTC","isIsolated":false,"time":1561973357171}]"#).unwrap();
5358 let expected_response : Vec<models::QueryMarginAccountsTradeListResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsTradeListResponseInner>");
5359
5360 let resp = client.query_margin_accounts_trade_list(params).await.expect("Expected a response");
5361 let data_future = resp.data();
5362 let actual_response = data_future.await.unwrap();
5363 assert_eq!(actual_response, expected_response);
5364 });
5365 }
5366
5367 #[test]
5368 fn query_margin_accounts_trade_list_optional_params_success() {
5369 TOKIO_SHARED_RT.block_on(async {
5370 let client = MockTradeApiClient { force_error: false };
5371
5372 let params = QueryMarginAccountsTradeListParams::builder("symbol_example".to_string(),).is_isolated("false".to_string()).order_id(1).start_time(1623319461670).end_time(1641782889000).from_id(1).limit(500).recv_window(5000).build().unwrap();
5373
5374 let resp_json: Value = serde_json::from_str(r#"[{"commission":"0.00006000","commissionAsset":"BTC","id":34,"isBestMatch":true,"isBuyer":false,"isMaker":false,"orderId":39324,"price":"0.02000000","qty":"3.00000000","symbol":"BNBBTC","isIsolated":false,"time":1561973357171}]"#).unwrap();
5375 let expected_response : Vec<models::QueryMarginAccountsTradeListResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryMarginAccountsTradeListResponseInner>");
5376
5377 let resp = client.query_margin_accounts_trade_list(params).await.expect("Expected a response");
5378 let data_future = resp.data();
5379 let actual_response = data_future.await.unwrap();
5380 assert_eq!(actual_response, expected_response);
5381 });
5382 }
5383
5384 #[test]
5385 fn query_margin_accounts_trade_list_response_error() {
5386 TOKIO_SHARED_RT.block_on(async {
5387 let client = MockTradeApiClient { force_error: true };
5388
5389 let params = QueryMarginAccountsTradeListParams::builder("symbol_example".to_string())
5390 .build()
5391 .unwrap();
5392
5393 match client.query_margin_accounts_trade_list(params).await {
5394 Ok(_) => panic!("Expected an error"),
5395 Err(err) => {
5396 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5397 }
5398 }
5399 });
5400 }
5401
5402 #[test]
5403 fn query_prevented_matches_required_params_success() {
5404 TOKIO_SHARED_RT.block_on(async {
5405 let client = MockTradeApiClient { force_error: false };
5406
5407 let params = QueryPreventedMatchesParams::builder("symbol_example".to_string(),).build().unwrap();
5408
5409 let resp_json: Value = serde_json::from_str(r#"[{"symbol":"BTCUSDT","preventedMatchId":1,"takerOrderId":5,"makerSymbol":"BTCUSDT","makerOrderId":3,"tradeGroupId":1,"selfTradePreventionMode":"EXPIRE_MAKER","price":"1.100000","makerPreventedQuantity":"1.300000","transactTime":1669101687094}]"#).unwrap();
5410 let expected_response : Vec<models::QueryPreventedMatchesResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryPreventedMatchesResponseInner>");
5411
5412 let resp = client.query_prevented_matches(params).await.expect("Expected a response");
5413 let data_future = resp.data();
5414 let actual_response = data_future.await.unwrap();
5415 assert_eq!(actual_response, expected_response);
5416 });
5417 }
5418
5419 #[test]
5420 fn query_prevented_matches_optional_params_success() {
5421 TOKIO_SHARED_RT.block_on(async {
5422 let client = MockTradeApiClient { force_error: false };
5423
5424 let params = QueryPreventedMatchesParams::builder("symbol_example".to_string(),).prevented_match_id(1).order_id(1).from_prevented_match_id(1).recv_window(5000).is_isolated("false".to_string()).build().unwrap();
5425
5426 let resp_json: Value = serde_json::from_str(r#"[{"symbol":"BTCUSDT","preventedMatchId":1,"takerOrderId":5,"makerSymbol":"BTCUSDT","makerOrderId":3,"tradeGroupId":1,"selfTradePreventionMode":"EXPIRE_MAKER","price":"1.100000","makerPreventedQuantity":"1.300000","transactTime":1669101687094}]"#).unwrap();
5427 let expected_response : Vec<models::QueryPreventedMatchesResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QueryPreventedMatchesResponseInner>");
5428
5429 let resp = client.query_prevented_matches(params).await.expect("Expected a response");
5430 let data_future = resp.data();
5431 let actual_response = data_future.await.unwrap();
5432 assert_eq!(actual_response, expected_response);
5433 });
5434 }
5435
5436 #[test]
5437 fn query_prevented_matches_response_error() {
5438 TOKIO_SHARED_RT.block_on(async {
5439 let client = MockTradeApiClient { force_error: true };
5440
5441 let params = QueryPreventedMatchesParams::builder("symbol_example".to_string())
5442 .build()
5443 .unwrap();
5444
5445 match client.query_prevented_matches(params).await {
5446 Ok(_) => panic!("Expected an error"),
5447 Err(err) => {
5448 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5449 }
5450 }
5451 });
5452 }
5453
5454 #[test]
5455 fn query_special_key_required_params_success() {
5456 TOKIO_SHARED_RT.block_on(async {
5457 let client = MockTradeApiClient { force_error: false };
5458
5459 let params = QuerySpecialKeyParams::builder().build().unwrap();
5460
5461 let resp_json: Value = serde_json::from_str(r#"{"apiKey":"npOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoGx","ip":"0.0.0.0,192.168.0.1,192.168.0.2","apiName":"testName","type":"RSA","permissionMode":"TRADE"}"#).unwrap();
5462 let expected_response : models::QuerySpecialKeyResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QuerySpecialKeyResponse");
5463
5464 let resp = client.query_special_key(params).await.expect("Expected a response");
5465 let data_future = resp.data();
5466 let actual_response = data_future.await.unwrap();
5467 assert_eq!(actual_response, expected_response);
5468 });
5469 }
5470
5471 #[test]
5472 fn query_special_key_optional_params_success() {
5473 TOKIO_SHARED_RT.block_on(async {
5474 let client = MockTradeApiClient { force_error: false };
5475
5476 let params = QuerySpecialKeyParams::builder().symbol("symbol_example".to_string()).recv_window(5000).build().unwrap();
5477
5478 let resp_json: Value = serde_json::from_str(r#"{"apiKey":"npOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoGx","ip":"0.0.0.0,192.168.0.1,192.168.0.2","apiName":"testName","type":"RSA","permissionMode":"TRADE"}"#).unwrap();
5479 let expected_response : models::QuerySpecialKeyResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QuerySpecialKeyResponse");
5480
5481 let resp = client.query_special_key(params).await.expect("Expected a response");
5482 let data_future = resp.data();
5483 let actual_response = data_future.await.unwrap();
5484 assert_eq!(actual_response, expected_response);
5485 });
5486 }
5487
5488 #[test]
5489 fn query_special_key_response_error() {
5490 TOKIO_SHARED_RT.block_on(async {
5491 let client = MockTradeApiClient { force_error: true };
5492
5493 let params = QuerySpecialKeyParams::builder().build().unwrap();
5494
5495 match client.query_special_key(params).await {
5496 Ok(_) => panic!("Expected an error"),
5497 Err(err) => {
5498 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5499 }
5500 }
5501 });
5502 }
5503
5504 #[test]
5505 fn query_special_key_list_required_params_success() {
5506 TOKIO_SHARED_RT.block_on(async {
5507 let client = MockTradeApiClient { force_error: false };
5508
5509 let params = QuerySpecialKeyListParams::builder().build().unwrap();
5510
5511 let resp_json: Value = serde_json::from_str(r#"[{"apiName":"testName1","apiKey":"znpOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoG","ip":"192.168.0.1,192.168.0.2","type":"RSA","permissionMode":"TRADE"},{"apiName":"testName2","apiKey":"znpOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoG","ip":"192.168.0.1,192.168.0.2","type":"Ed25519","permissionMode":"READ"}]"#).unwrap();
5512 let expected_response : Vec<models::QuerySpecialKeyListResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QuerySpecialKeyListResponseInner>");
5513
5514 let resp = client.query_special_key_list(params).await.expect("Expected a response");
5515 let data_future = resp.data();
5516 let actual_response = data_future.await.unwrap();
5517 assert_eq!(actual_response, expected_response);
5518 });
5519 }
5520
5521 #[test]
5522 fn query_special_key_list_optional_params_success() {
5523 TOKIO_SHARED_RT.block_on(async {
5524 let client = MockTradeApiClient { force_error: false };
5525
5526 let params = QuerySpecialKeyListParams::builder().symbol("symbol_example".to_string()).recv_window(5000).build().unwrap();
5527
5528 let resp_json: Value = serde_json::from_str(r#"[{"apiName":"testName1","apiKey":"znpOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoG","ip":"192.168.0.1,192.168.0.2","type":"RSA","permissionMode":"TRADE"},{"apiName":"testName2","apiKey":"znpOzOAeLVgr2TuxWfNo43AaPWpBbJEoKezh1o8mSQb6ryE2odE11A4AoVlJbQoG","ip":"192.168.0.1,192.168.0.2","type":"Ed25519","permissionMode":"READ"}]"#).unwrap();
5529 let expected_response : Vec<models::QuerySpecialKeyListResponseInner> = serde_json::from_value(resp_json.clone()).expect("should parse into Vec<models::QuerySpecialKeyListResponseInner>");
5530
5531 let resp = client.query_special_key_list(params).await.expect("Expected a response");
5532 let data_future = resp.data();
5533 let actual_response = data_future.await.unwrap();
5534 assert_eq!(actual_response, expected_response);
5535 });
5536 }
5537
5538 #[test]
5539 fn query_special_key_list_response_error() {
5540 TOKIO_SHARED_RT.block_on(async {
5541 let client = MockTradeApiClient { force_error: true };
5542
5543 let params = QuerySpecialKeyListParams::builder().build().unwrap();
5544
5545 match client.query_special_key_list(params).await {
5546 Ok(_) => panic!("Expected an error"),
5547 Err(err) => {
5548 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5549 }
5550 }
5551 });
5552 }
5553
5554 #[test]
5555 fn small_liability_exchange_required_params_success() {
5556 TOKIO_SHARED_RT.block_on(async {
5557 let client = MockTradeApiClient { force_error: false };
5558
5559 let params = SmallLiabilityExchangeParams::builder(["BTC".to_string()].to_vec())
5560 .build()
5561 .unwrap();
5562
5563 let expected_response = Value::Null;
5564
5565 let resp = client
5566 .small_liability_exchange(params)
5567 .await
5568 .expect("Expected a response");
5569 let data_future = resp.data();
5570 let actual_response = data_future.await.unwrap();
5571 assert_eq!(actual_response, expected_response);
5572 });
5573 }
5574
5575 #[test]
5576 fn small_liability_exchange_optional_params_success() {
5577 TOKIO_SHARED_RT.block_on(async {
5578 let client = MockTradeApiClient { force_error: false };
5579
5580 let params = SmallLiabilityExchangeParams::builder(["BTC".to_string()].to_vec())
5581 .recv_window(5000)
5582 .build()
5583 .unwrap();
5584
5585 let expected_response = Value::Null;
5586
5587 let resp = client
5588 .small_liability_exchange(params)
5589 .await
5590 .expect("Expected a response");
5591 let data_future = resp.data();
5592 let actual_response = data_future.await.unwrap();
5593 assert_eq!(actual_response, expected_response);
5594 });
5595 }
5596
5597 #[test]
5598 fn small_liability_exchange_response_error() {
5599 TOKIO_SHARED_RT.block_on(async {
5600 let client = MockTradeApiClient { force_error: true };
5601
5602 let params = SmallLiabilityExchangeParams::builder(["BTC".to_string()].to_vec())
5603 .build()
5604 .unwrap();
5605
5606 match client.small_liability_exchange(params).await {
5607 Ok(_) => panic!("Expected an error"),
5608 Err(err) => {
5609 assert_eq!(err.to_string(), "Connector client error: ResponseError");
5610 }
5611 }
5612 });
5613 }
5614}