binance/margin/apis/
account_api.rs

1/*
2 * Binance Margin Trading API
3 *
4 * OpenAPI specification for Binance exchange - Margin API
5 *
6 * The version of the OpenAPI document: 0.1.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::margin::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`margin_create_margin_isolated_account_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct MarginCreateMarginIsolatedAccountV1Params {
20    pub symbol: String,
21    pub timestamp: i64,
22    pub recv_window: Option<i64>
23}
24
25/// struct for passing parameters to the method [`margin_create_margin_max_leverage_v1`]
26#[derive(Clone, Debug, Default)]
27pub struct MarginCreateMarginMaxLeverageV1Params {
28    pub max_leverage: i32
29}
30
31/// struct for passing parameters to the method [`margin_delete_margin_isolated_account_v1`]
32#[derive(Clone, Debug, Default)]
33pub struct MarginDeleteMarginIsolatedAccountV1Params {
34    pub symbol: String,
35    pub timestamp: i64,
36    /// No more than 60000
37    pub recv_window: Option<i64>
38}
39
40/// struct for passing parameters to the method [`margin_get_bnb_burn_v1`]
41#[derive(Clone, Debug, Default)]
42pub struct MarginGetBnbBurnV1Params {
43    pub timestamp: i64,
44    /// No more than 60000
45    pub recv_window: Option<i64>
46}
47
48/// struct for passing parameters to the method [`margin_get_margin_account_v1`]
49#[derive(Clone, Debug, Default)]
50pub struct MarginGetMarginAccountV1Params {
51    pub timestamp: i64,
52    /// The value cannot be greater than `60000`
53    pub recv_window: Option<i64>
54}
55
56/// struct for passing parameters to the method [`margin_get_margin_capital_flow_v1`]
57#[derive(Clone, Debug, Default)]
58pub struct MarginGetMarginCapitalFlowV1Params {
59    pub timestamp: i64,
60    pub asset: Option<String>,
61    /// 查询逐仓数据时必填
62    pub symbol: Option<String>,
63    pub r#type: Option<String>,
64    /// 只支持查询最近90天的数据
65    pub start_time: Option<i64>,
66    pub end_time: Option<i64>,
67    /// 如设置fromId, 将返回id &gt; fromId的数据。否则将返回最新数据
68    pub from_id: Option<i64>,
69    /// 每次返回的数据条数限制。默认 500; 最大 1000.
70    pub limit: Option<i64>,
71    /// The value cannot be greater than `60000`
72    pub recv_window: Option<i64>
73}
74
75/// struct for passing parameters to the method [`margin_get_margin_cross_margin_data_v1`]
76#[derive(Clone, Debug, Default)]
77pub struct MarginGetMarginCrossMarginDataV1Params {
78    pub timestamp: i64,
79    /// User&#39;s current specific margin data will be returned if vipLevel is omitted
80    pub vip_level: Option<i32>,
81    pub coin: Option<String>,
82    /// No more than `60000`
83    pub recv_window: Option<i64>
84}
85
86/// struct for passing parameters to the method [`margin_get_margin_isolated_account_limit_v1`]
87#[derive(Clone, Debug, Default)]
88pub struct MarginGetMarginIsolatedAccountLimitV1Params {
89    pub timestamp: i64,
90    /// No more than 60000
91    pub recv_window: Option<i64>
92}
93
94/// struct for passing parameters to the method [`margin_get_margin_isolated_account_v1`]
95#[derive(Clone, Debug, Default)]
96pub struct MarginGetMarginIsolatedAccountV1Params {
97    pub timestamp: i64,
98    /// Max 5 symbols can be sent; separated by &#34;,&#34;. e.g. &#34;BTCUSDT,BNBUSDT,ADAUSDT&#34;
99    pub symbols: Option<String>,
100    /// No more than 60000
101    pub recv_window: Option<i64>
102}
103
104/// struct for passing parameters to the method [`margin_get_margin_isolated_margin_data_v1`]
105#[derive(Clone, Debug, Default)]
106pub struct MarginGetMarginIsolatedMarginDataV1Params {
107    pub timestamp: i64,
108    /// User&#39;s current specific margin data will be returned if vipLevel is omitted
109    pub vip_level: Option<i32>,
110    pub symbol: Option<String>,
111    /// No more than `60000`
112    pub recv_window: Option<i64>
113}
114
115/// struct for passing parameters to the method [`margin_get_margin_trade_coeff_v1`]
116#[derive(Clone, Debug, Default)]
117pub struct MarginGetMarginTradeCoeffV1Params {
118    pub timestamp: i64,
119    pub recv_window: Option<i64>
120}
121
122
123/// struct for typed errors of method [`margin_create_margin_isolated_account_v1`]
124#[derive(Debug, Clone, Serialize, Deserialize)]
125#[serde(untagged)]
126pub enum MarginCreateMarginIsolatedAccountV1Error {
127    Status4XX(models::ApiError),
128    Status5XX(models::ApiError),
129    UnknownValue(serde_json::Value),
130}
131
132/// struct for typed errors of method [`margin_create_margin_max_leverage_v1`]
133#[derive(Debug, Clone, Serialize, Deserialize)]
134#[serde(untagged)]
135pub enum MarginCreateMarginMaxLeverageV1Error {
136    Status4XX(models::ApiError),
137    Status5XX(models::ApiError),
138    UnknownValue(serde_json::Value),
139}
140
141/// struct for typed errors of method [`margin_delete_margin_isolated_account_v1`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum MarginDeleteMarginIsolatedAccountV1Error {
145    Status4XX(models::ApiError),
146    Status5XX(models::ApiError),
147    UnknownValue(serde_json::Value),
148}
149
150/// struct for typed errors of method [`margin_get_bnb_burn_v1`]
151#[derive(Debug, Clone, Serialize, Deserialize)]
152#[serde(untagged)]
153pub enum MarginGetBnbBurnV1Error {
154    Status4XX(models::ApiError),
155    Status5XX(models::ApiError),
156    UnknownValue(serde_json::Value),
157}
158
159/// struct for typed errors of method [`margin_get_margin_account_v1`]
160#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(untagged)]
162pub enum MarginGetMarginAccountV1Error {
163    Status4XX(models::ApiError),
164    Status5XX(models::ApiError),
165    UnknownValue(serde_json::Value),
166}
167
168/// struct for typed errors of method [`margin_get_margin_capital_flow_v1`]
169#[derive(Debug, Clone, Serialize, Deserialize)]
170#[serde(untagged)]
171pub enum MarginGetMarginCapitalFlowV1Error {
172    Status4XX(models::ApiError),
173    Status5XX(models::ApiError),
174    UnknownValue(serde_json::Value),
175}
176
177/// struct for typed errors of method [`margin_get_margin_cross_margin_data_v1`]
178#[derive(Debug, Clone, Serialize, Deserialize)]
179#[serde(untagged)]
180pub enum MarginGetMarginCrossMarginDataV1Error {
181    Status4XX(models::ApiError),
182    Status5XX(models::ApiError),
183    UnknownValue(serde_json::Value),
184}
185
186/// struct for typed errors of method [`margin_get_margin_isolated_account_limit_v1`]
187#[derive(Debug, Clone, Serialize, Deserialize)]
188#[serde(untagged)]
189pub enum MarginGetMarginIsolatedAccountLimitV1Error {
190    Status4XX(models::ApiError),
191    Status5XX(models::ApiError),
192    UnknownValue(serde_json::Value),
193}
194
195/// struct for typed errors of method [`margin_get_margin_isolated_account_v1`]
196#[derive(Debug, Clone, Serialize, Deserialize)]
197#[serde(untagged)]
198pub enum MarginGetMarginIsolatedAccountV1Error {
199    Status4XX(models::ApiError),
200    Status5XX(models::ApiError),
201    UnknownValue(serde_json::Value),
202}
203
204/// struct for typed errors of method [`margin_get_margin_isolated_margin_data_v1`]
205#[derive(Debug, Clone, Serialize, Deserialize)]
206#[serde(untagged)]
207pub enum MarginGetMarginIsolatedMarginDataV1Error {
208    Status4XX(models::ApiError),
209    Status5XX(models::ApiError),
210    UnknownValue(serde_json::Value),
211}
212
213/// struct for typed errors of method [`margin_get_margin_trade_coeff_v1`]
214#[derive(Debug, Clone, Serialize, Deserialize)]
215#[serde(untagged)]
216pub enum MarginGetMarginTradeCoeffV1Error {
217    Status4XX(models::ApiError),
218    Status5XX(models::ApiError),
219    UnknownValue(serde_json::Value),
220}
221
222
223/// Enable isolated margin account for a specific symbol(Only supports activation of previously disabled accounts).
224pub async fn margin_create_margin_isolated_account_v1(configuration: &configuration::Configuration, params: MarginCreateMarginIsolatedAccountV1Params) -> Result<models::MarginCreateMarginIsolatedAccountV1Resp, Error<MarginCreateMarginIsolatedAccountV1Error>> {
225
226    let uri_str = format!("{}/sapi/v1/margin/isolated/account", configuration.base_path);
227    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
228
229    // Create a mutable vector for query parameters
230    let mut query_params: Vec<(String, String)> = Vec::new();
231
232
233    // Create header parameters collection
234    let mut header_params = std::collections::HashMap::new();
235
236    // Handle Binance Auth first if configured
237    if let Some(ref binance_auth) = configuration.binance_auth {
238        // Add API key to headers
239        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
240        
241        // Generate request body for signing (if any)
242        let body_string: Option<Vec<u8>> = None;
243        
244        // Sign the request
245        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
246            Ok(sig) => sig,
247            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
248        };
249        
250        // Add signature to query params
251        query_params.push(("signature".to_string(), signature));
252    }
253
254    // Apply all query parameters
255    if !query_params.is_empty() {
256        req_builder = req_builder.query(&query_params);
257    }
258
259
260    // Add user agent if configured
261    if let Some(ref user_agent) = configuration.user_agent {
262        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
263    }
264
265    // Apply all header parameters
266    for (header_name, header_value) in header_params {
267        req_builder = req_builder.header(&header_name, &header_value);
268    }
269
270    let mut multipart_form_params = std::collections::HashMap::new();
271    if let Some(param_value) = params.recv_window {
272        multipart_form_params.insert("recvWindow", param_value.to_string());
273    }
274    multipart_form_params.insert("symbol", params.symbol.to_string());
275    multipart_form_params.insert("timestamp", params.timestamp.to_string());
276    req_builder = req_builder.form(&multipart_form_params);
277
278    let req = req_builder.build()?;
279    let resp = configuration.client.execute(req).await?;
280
281    let status = resp.status();
282    let content_type = resp
283        .headers()
284        .get("content-type")
285        .and_then(|v| v.to_str().ok())
286        .unwrap_or("application/octet-stream");
287    let content_type = super::ContentType::from(content_type);
288
289    if !status.is_client_error() && !status.is_server_error() {
290        let content = resp.text().await?;
291        match content_type {
292            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
293            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginCreateMarginIsolatedAccountV1Resp`"))),
294            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginCreateMarginIsolatedAccountV1Resp`")))),
295        }
296    } else {
297        let content = resp.text().await?;
298        let entity: Option<MarginCreateMarginIsolatedAccountV1Error> = serde_json::from_str(&content).ok();
299        Err(Error::ResponseError(ResponseContent { status, content, entity }))
300    }
301}
302
303/// Adjust cross margin max leverage
304pub async fn margin_create_margin_max_leverage_v1(configuration: &configuration::Configuration, params: MarginCreateMarginMaxLeverageV1Params) -> Result<models::MarginCreateMarginMaxLeverageV1Resp, Error<MarginCreateMarginMaxLeverageV1Error>> {
305
306    let uri_str = format!("{}/sapi/v1/margin/max-leverage", configuration.base_path);
307    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
308
309    // Create a mutable vector for query parameters
310    let mut query_params: Vec<(String, String)> = Vec::new();
311
312
313    // Create header parameters collection
314    let mut header_params = std::collections::HashMap::new();
315
316    // Handle Binance Auth first if configured
317    if let Some(ref binance_auth) = configuration.binance_auth {
318        // Add API key to headers
319        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
320        
321        // Generate request body for signing (if any)
322        let body_string: Option<Vec<u8>> = None;
323        
324        // Sign the request
325        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
326            Ok(sig) => sig,
327            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
328        };
329        
330        // Add signature to query params
331        query_params.push(("signature".to_string(), signature));
332    }
333
334    // Apply all query parameters
335    if !query_params.is_empty() {
336        req_builder = req_builder.query(&query_params);
337    }
338
339
340    // Add user agent if configured
341    if let Some(ref user_agent) = configuration.user_agent {
342        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
343    }
344
345    // Apply all header parameters
346    for (header_name, header_value) in header_params {
347        req_builder = req_builder.header(&header_name, &header_value);
348    }
349
350    let mut multipart_form_params = std::collections::HashMap::new();
351    multipart_form_params.insert("maxLeverage", params.max_leverage.to_string());
352    req_builder = req_builder.form(&multipart_form_params);
353
354    let req = req_builder.build()?;
355    let resp = configuration.client.execute(req).await?;
356
357    let status = resp.status();
358    let content_type = resp
359        .headers()
360        .get("content-type")
361        .and_then(|v| v.to_str().ok())
362        .unwrap_or("application/octet-stream");
363    let content_type = super::ContentType::from(content_type);
364
365    if !status.is_client_error() && !status.is_server_error() {
366        let content = resp.text().await?;
367        match content_type {
368            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
369            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginCreateMarginMaxLeverageV1Resp`"))),
370            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginCreateMarginMaxLeverageV1Resp`")))),
371        }
372    } else {
373        let content = resp.text().await?;
374        let entity: Option<MarginCreateMarginMaxLeverageV1Error> = serde_json::from_str(&content).ok();
375        Err(Error::ResponseError(ResponseContent { status, content, entity }))
376    }
377}
378
379/// Disable isolated margin account for a specific symbol. Each trading pair can only be deactivated once every 24 hours.
380pub async fn margin_delete_margin_isolated_account_v1(configuration: &configuration::Configuration, params: MarginDeleteMarginIsolatedAccountV1Params) -> Result<models::MarginDeleteMarginIsolatedAccountV1Resp, Error<MarginDeleteMarginIsolatedAccountV1Error>> {
381
382    let uri_str = format!("{}/sapi/v1/margin/isolated/account", configuration.base_path);
383    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
384
385    // Create a mutable vector for query parameters
386    let mut query_params: Vec<(String, String)> = Vec::new();
387
388    query_params.push(("symbol".to_string(), params.symbol.to_string()));
389    if let Some(ref param_value) = params.recv_window {
390        query_params.push(("recvWindow".to_string(), param_value.to_string()));
391    }
392    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
393
394    // Create header parameters collection
395    let mut header_params = std::collections::HashMap::new();
396
397    // Handle Binance Auth first if configured
398    if let Some(ref binance_auth) = configuration.binance_auth {
399        // Add API key to headers
400        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
401        
402        // Generate request body for signing (if any)
403        let body_string: Option<Vec<u8>> = None;
404        
405        // Sign the request
406        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
407            Ok(sig) => sig,
408            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
409        };
410        
411        // Add signature to query params
412        query_params.push(("signature".to_string(), signature));
413    }
414
415    // Apply all query parameters
416    if !query_params.is_empty() {
417        req_builder = req_builder.query(&query_params);
418    }
419
420
421    // Add user agent if configured
422    if let Some(ref user_agent) = configuration.user_agent {
423        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
424    }
425
426    // Apply all header parameters
427    for (header_name, header_value) in header_params {
428        req_builder = req_builder.header(&header_name, &header_value);
429    }
430
431
432    let req = req_builder.build()?;
433    let resp = configuration.client.execute(req).await?;
434
435    let status = resp.status();
436    let content_type = resp
437        .headers()
438        .get("content-type")
439        .and_then(|v| v.to_str().ok())
440        .unwrap_or("application/octet-stream");
441    let content_type = super::ContentType::from(content_type);
442
443    if !status.is_client_error() && !status.is_server_error() {
444        let content = resp.text().await?;
445        match content_type {
446            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
447            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginDeleteMarginIsolatedAccountV1Resp`"))),
448            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginDeleteMarginIsolatedAccountV1Resp`")))),
449        }
450    } else {
451        let content = resp.text().await?;
452        let entity: Option<MarginDeleteMarginIsolatedAccountV1Error> = serde_json::from_str(&content).ok();
453        Err(Error::ResponseError(ResponseContent { status, content, entity }))
454    }
455}
456
457/// Get BNB Burn Status
458pub async fn margin_get_bnb_burn_v1(configuration: &configuration::Configuration, params: MarginGetBnbBurnV1Params) -> Result<models::MarginGetBnbBurnV1Resp, Error<MarginGetBnbBurnV1Error>> {
459
460    let uri_str = format!("{}/sapi/v1/bnbBurn", configuration.base_path);
461    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
462
463    // Create a mutable vector for query parameters
464    let mut query_params: Vec<(String, String)> = Vec::new();
465
466    if let Some(ref param_value) = params.recv_window {
467        query_params.push(("recvWindow".to_string(), param_value.to_string()));
468    }
469    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
470
471    // Create header parameters collection
472    let mut header_params = std::collections::HashMap::new();
473
474    // Handle Binance Auth first if configured
475    if let Some(ref binance_auth) = configuration.binance_auth {
476        // Add API key to headers
477        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
478        
479        // Generate request body for signing (if any)
480        let body_string: Option<Vec<u8>> = None;
481        
482        // Sign the request
483        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
484            Ok(sig) => sig,
485            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
486        };
487        
488        // Add signature to query params
489        query_params.push(("signature".to_string(), signature));
490    }
491
492    // Apply all query parameters
493    if !query_params.is_empty() {
494        req_builder = req_builder.query(&query_params);
495    }
496
497
498    // Add user agent if configured
499    if let Some(ref user_agent) = configuration.user_agent {
500        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
501    }
502
503    // Apply all header parameters
504    for (header_name, header_value) in header_params {
505        req_builder = req_builder.header(&header_name, &header_value);
506    }
507
508
509    let req = req_builder.build()?;
510    let resp = configuration.client.execute(req).await?;
511
512    let status = resp.status();
513    let content_type = resp
514        .headers()
515        .get("content-type")
516        .and_then(|v| v.to_str().ok())
517        .unwrap_or("application/octet-stream");
518    let content_type = super::ContentType::from(content_type);
519
520    if !status.is_client_error() && !status.is_server_error() {
521        let content = resp.text().await?;
522        match content_type {
523            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
524            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetBnbBurnV1Resp`"))),
525            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetBnbBurnV1Resp`")))),
526        }
527    } else {
528        let content = resp.text().await?;
529        let entity: Option<MarginGetBnbBurnV1Error> = serde_json::from_str(&content).ok();
530        Err(Error::ResponseError(ResponseContent { status, content, entity }))
531    }
532}
533
534/// Query Cross Margin Account Details
535pub async fn margin_get_margin_account_v1(configuration: &configuration::Configuration, params: MarginGetMarginAccountV1Params) -> Result<models::MarginGetMarginAccountV1Resp, Error<MarginGetMarginAccountV1Error>> {
536
537    let uri_str = format!("{}/sapi/v1/margin/account", configuration.base_path);
538    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
539
540    // Create a mutable vector for query parameters
541    let mut query_params: Vec<(String, String)> = Vec::new();
542
543    if let Some(ref param_value) = params.recv_window {
544        query_params.push(("recvWindow".to_string(), param_value.to_string()));
545    }
546    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
547
548    // Create header parameters collection
549    let mut header_params = std::collections::HashMap::new();
550
551    // Handle Binance Auth first if configured
552    if let Some(ref binance_auth) = configuration.binance_auth {
553        // Add API key to headers
554        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
555        
556        // Generate request body for signing (if any)
557        let body_string: Option<Vec<u8>> = None;
558        
559        // Sign the request
560        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
561            Ok(sig) => sig,
562            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
563        };
564        
565        // Add signature to query params
566        query_params.push(("signature".to_string(), signature));
567    }
568
569    // Apply all query parameters
570    if !query_params.is_empty() {
571        req_builder = req_builder.query(&query_params);
572    }
573
574
575    // Add user agent if configured
576    if let Some(ref user_agent) = configuration.user_agent {
577        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
578    }
579
580    // Apply all header parameters
581    for (header_name, header_value) in header_params {
582        req_builder = req_builder.header(&header_name, &header_value);
583    }
584
585
586    let req = req_builder.build()?;
587    let resp = configuration.client.execute(req).await?;
588
589    let status = resp.status();
590    let content_type = resp
591        .headers()
592        .get("content-type")
593        .and_then(|v| v.to_str().ok())
594        .unwrap_or("application/octet-stream");
595    let content_type = super::ContentType::from(content_type);
596
597    if !status.is_client_error() && !status.is_server_error() {
598        let content = resp.text().await?;
599        match content_type {
600            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
601            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetMarginAccountV1Resp`"))),
602            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetMarginAccountV1Resp`")))),
603        }
604    } else {
605        let content = resp.text().await?;
606        let entity: Option<MarginGetMarginAccountV1Error> = serde_json::from_str(&content).ok();
607        Err(Error::ResponseError(ResponseContent { status, content, entity }))
608    }
609}
610
611/// Query Cross Isolated Margin Capital Flow
612pub async fn margin_get_margin_capital_flow_v1(configuration: &configuration::Configuration, params: MarginGetMarginCapitalFlowV1Params) -> Result<Vec<models::MarginGetMarginCapitalFlowV1RespItem>, Error<MarginGetMarginCapitalFlowV1Error>> {
613
614    let uri_str = format!("{}/sapi/v1/margin/capital-flow", configuration.base_path);
615    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
616
617    // Create a mutable vector for query parameters
618    let mut query_params: Vec<(String, String)> = Vec::new();
619
620    if let Some(ref param_value) = params.asset {
621        query_params.push(("asset".to_string(), param_value.to_string()));
622    }
623    if let Some(ref param_value) = params.symbol {
624        query_params.push(("symbol".to_string(), param_value.to_string()));
625    }
626    if let Some(ref param_value) = params.r#type {
627        query_params.push(("type".to_string(), param_value.to_string()));
628    }
629    if let Some(ref param_value) = params.start_time {
630        query_params.push(("startTime".to_string(), param_value.to_string()));
631    }
632    if let Some(ref param_value) = params.end_time {
633        query_params.push(("endTime".to_string(), param_value.to_string()));
634    }
635    if let Some(ref param_value) = params.from_id {
636        query_params.push(("fromId".to_string(), param_value.to_string()));
637    }
638    if let Some(ref param_value) = params.limit {
639        query_params.push(("limit".to_string(), param_value.to_string()));
640    }
641    if let Some(ref param_value) = params.recv_window {
642        query_params.push(("recvWindow".to_string(), param_value.to_string()));
643    }
644    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
645
646    // Create header parameters collection
647    let mut header_params = std::collections::HashMap::new();
648
649    // Handle Binance Auth first if configured
650    if let Some(ref binance_auth) = configuration.binance_auth {
651        // Add API key to headers
652        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
653        
654        // Generate request body for signing (if any)
655        let body_string: Option<Vec<u8>> = None;
656        
657        // Sign the request
658        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
659            Ok(sig) => sig,
660            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
661        };
662        
663        // Add signature to query params
664        query_params.push(("signature".to_string(), signature));
665    }
666
667    // Apply all query parameters
668    if !query_params.is_empty() {
669        req_builder = req_builder.query(&query_params);
670    }
671
672
673    // Add user agent if configured
674    if let Some(ref user_agent) = configuration.user_agent {
675        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
676    }
677
678    // Apply all header parameters
679    for (header_name, header_value) in header_params {
680        req_builder = req_builder.header(&header_name, &header_value);
681    }
682
683
684    let req = req_builder.build()?;
685    let resp = configuration.client.execute(req).await?;
686
687    let status = resp.status();
688    let content_type = resp
689        .headers()
690        .get("content-type")
691        .and_then(|v| v.to_str().ok())
692        .unwrap_or("application/octet-stream");
693    let content_type = super::ContentType::from(content_type);
694
695    if !status.is_client_error() && !status.is_server_error() {
696        let content = resp.text().await?;
697        match content_type {
698            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
699            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::MarginGetMarginCapitalFlowV1RespItem&gt;`"))),
700            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::MarginGetMarginCapitalFlowV1RespItem&gt;`")))),
701        }
702    } else {
703        let content = resp.text().await?;
704        let entity: Option<MarginGetMarginCapitalFlowV1Error> = serde_json::from_str(&content).ok();
705        Err(Error::ResponseError(ResponseContent { status, content, entity }))
706    }
707}
708
709/// Get cross margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee
710pub async fn margin_get_margin_cross_margin_data_v1(configuration: &configuration::Configuration, params: MarginGetMarginCrossMarginDataV1Params) -> Result<Vec<models::MarginGetMarginCrossMarginDataV1RespItem>, Error<MarginGetMarginCrossMarginDataV1Error>> {
711
712    let uri_str = format!("{}/sapi/v1/margin/crossMarginData", configuration.base_path);
713    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
714
715    // Create a mutable vector for query parameters
716    let mut query_params: Vec<(String, String)> = Vec::new();
717
718    if let Some(ref param_value) = params.vip_level {
719        query_params.push(("vipLevel".to_string(), param_value.to_string()));
720    }
721    if let Some(ref param_value) = params.coin {
722        query_params.push(("coin".to_string(), param_value.to_string()));
723    }
724    if let Some(ref param_value) = params.recv_window {
725        query_params.push(("recvWindow".to_string(), param_value.to_string()));
726    }
727    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
728
729    // Create header parameters collection
730    let mut header_params = std::collections::HashMap::new();
731
732    // Handle Binance Auth first if configured
733    if let Some(ref binance_auth) = configuration.binance_auth {
734        // Add API key to headers
735        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
736        
737        // Generate request body for signing (if any)
738        let body_string: Option<Vec<u8>> = None;
739        
740        // Sign the request
741        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
742            Ok(sig) => sig,
743            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
744        };
745        
746        // Add signature to query params
747        query_params.push(("signature".to_string(), signature));
748    }
749
750    // Apply all query parameters
751    if !query_params.is_empty() {
752        req_builder = req_builder.query(&query_params);
753    }
754
755
756    // Add user agent if configured
757    if let Some(ref user_agent) = configuration.user_agent {
758        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
759    }
760
761    // Apply all header parameters
762    for (header_name, header_value) in header_params {
763        req_builder = req_builder.header(&header_name, &header_value);
764    }
765
766
767    let req = req_builder.build()?;
768    let resp = configuration.client.execute(req).await?;
769
770    let status = resp.status();
771    let content_type = resp
772        .headers()
773        .get("content-type")
774        .and_then(|v| v.to_str().ok())
775        .unwrap_or("application/octet-stream");
776    let content_type = super::ContentType::from(content_type);
777
778    if !status.is_client_error() && !status.is_server_error() {
779        let content = resp.text().await?;
780        match content_type {
781            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
782            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::MarginGetMarginCrossMarginDataV1RespItem&gt;`"))),
783            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::MarginGetMarginCrossMarginDataV1RespItem&gt;`")))),
784        }
785    } else {
786        let content = resp.text().await?;
787        let entity: Option<MarginGetMarginCrossMarginDataV1Error> = serde_json::from_str(&content).ok();
788        Err(Error::ResponseError(ResponseContent { status, content, entity }))
789    }
790}
791
792/// Query enabled isolated margin account limit.
793pub async fn margin_get_margin_isolated_account_limit_v1(configuration: &configuration::Configuration, params: MarginGetMarginIsolatedAccountLimitV1Params) -> Result<models::MarginGetMarginIsolatedAccountLimitV1Resp, Error<MarginGetMarginIsolatedAccountLimitV1Error>> {
794
795    let uri_str = format!("{}/sapi/v1/margin/isolated/accountLimit", configuration.base_path);
796    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
797
798    // Create a mutable vector for query parameters
799    let mut query_params: Vec<(String, String)> = Vec::new();
800
801    if let Some(ref param_value) = params.recv_window {
802        query_params.push(("recvWindow".to_string(), param_value.to_string()));
803    }
804    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
805
806    // Create header parameters collection
807    let mut header_params = std::collections::HashMap::new();
808
809    // Handle Binance Auth first if configured
810    if let Some(ref binance_auth) = configuration.binance_auth {
811        // Add API key to headers
812        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
813        
814        // Generate request body for signing (if any)
815        let body_string: Option<Vec<u8>> = None;
816        
817        // Sign the request
818        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
819            Ok(sig) => sig,
820            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
821        };
822        
823        // Add signature to query params
824        query_params.push(("signature".to_string(), signature));
825    }
826
827    // Apply all query parameters
828    if !query_params.is_empty() {
829        req_builder = req_builder.query(&query_params);
830    }
831
832
833    // Add user agent if configured
834    if let Some(ref user_agent) = configuration.user_agent {
835        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
836    }
837
838    // Apply all header parameters
839    for (header_name, header_value) in header_params {
840        req_builder = req_builder.header(&header_name, &header_value);
841    }
842
843
844    let req = req_builder.build()?;
845    let resp = configuration.client.execute(req).await?;
846
847    let status = resp.status();
848    let content_type = resp
849        .headers()
850        .get("content-type")
851        .and_then(|v| v.to_str().ok())
852        .unwrap_or("application/octet-stream");
853    let content_type = super::ContentType::from(content_type);
854
855    if !status.is_client_error() && !status.is_server_error() {
856        let content = resp.text().await?;
857        match content_type {
858            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
859            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetMarginIsolatedAccountLimitV1Resp`"))),
860            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetMarginIsolatedAccountLimitV1Resp`")))),
861        }
862    } else {
863        let content = resp.text().await?;
864        let entity: Option<MarginGetMarginIsolatedAccountLimitV1Error> = serde_json::from_str(&content).ok();
865        Err(Error::ResponseError(ResponseContent { status, content, entity }))
866    }
867}
868
869/// Query Isolated Margin Account Info
870pub async fn margin_get_margin_isolated_account_v1(configuration: &configuration::Configuration, params: MarginGetMarginIsolatedAccountV1Params) -> Result<models::MarginGetMarginIsolatedAccountV1Resp, Error<MarginGetMarginIsolatedAccountV1Error>> {
871
872    let uri_str = format!("{}/sapi/v1/margin/isolated/account", configuration.base_path);
873    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
874
875    // Create a mutable vector for query parameters
876    let mut query_params: Vec<(String, String)> = Vec::new();
877
878    if let Some(ref param_value) = params.symbols {
879        query_params.push(("symbols".to_string(), param_value.to_string()));
880    }
881    if let Some(ref param_value) = params.recv_window {
882        query_params.push(("recvWindow".to_string(), param_value.to_string()));
883    }
884    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
885
886    // Create header parameters collection
887    let mut header_params = std::collections::HashMap::new();
888
889    // Handle Binance Auth first if configured
890    if let Some(ref binance_auth) = configuration.binance_auth {
891        // Add API key to headers
892        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
893        
894        // Generate request body for signing (if any)
895        let body_string: Option<Vec<u8>> = None;
896        
897        // Sign the request
898        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
899            Ok(sig) => sig,
900            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
901        };
902        
903        // Add signature to query params
904        query_params.push(("signature".to_string(), signature));
905    }
906
907    // Apply all query parameters
908    if !query_params.is_empty() {
909        req_builder = req_builder.query(&query_params);
910    }
911
912
913    // Add user agent if configured
914    if let Some(ref user_agent) = configuration.user_agent {
915        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
916    }
917
918    // Apply all header parameters
919    for (header_name, header_value) in header_params {
920        req_builder = req_builder.header(&header_name, &header_value);
921    }
922
923
924    let req = req_builder.build()?;
925    let resp = configuration.client.execute(req).await?;
926
927    let status = resp.status();
928    let content_type = resp
929        .headers()
930        .get("content-type")
931        .and_then(|v| v.to_str().ok())
932        .unwrap_or("application/octet-stream");
933    let content_type = super::ContentType::from(content_type);
934
935    if !status.is_client_error() && !status.is_server_error() {
936        let content = resp.text().await?;
937        match content_type {
938            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
939            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetMarginIsolatedAccountV1Resp`"))),
940            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetMarginIsolatedAccountV1Resp`")))),
941        }
942    } else {
943        let content = resp.text().await?;
944        let entity: Option<MarginGetMarginIsolatedAccountV1Error> = serde_json::from_str(&content).ok();
945        Err(Error::ResponseError(ResponseContent { status, content, entity }))
946    }
947}
948
949/// Get isolated margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee
950pub async fn margin_get_margin_isolated_margin_data_v1(configuration: &configuration::Configuration, params: MarginGetMarginIsolatedMarginDataV1Params) -> Result<Vec<models::MarginGetMarginIsolatedMarginDataV1RespItem>, Error<MarginGetMarginIsolatedMarginDataV1Error>> {
951
952    let uri_str = format!("{}/sapi/v1/margin/isolatedMarginData", configuration.base_path);
953    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
954
955    // Create a mutable vector for query parameters
956    let mut query_params: Vec<(String, String)> = Vec::new();
957
958    if let Some(ref param_value) = params.vip_level {
959        query_params.push(("vipLevel".to_string(), param_value.to_string()));
960    }
961    if let Some(ref param_value) = params.symbol {
962        query_params.push(("symbol".to_string(), param_value.to_string()));
963    }
964    if let Some(ref param_value) = params.recv_window {
965        query_params.push(("recvWindow".to_string(), param_value.to_string()));
966    }
967    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
968
969    // Create header parameters collection
970    let mut header_params = std::collections::HashMap::new();
971
972    // Handle Binance Auth first if configured
973    if let Some(ref binance_auth) = configuration.binance_auth {
974        // Add API key to headers
975        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
976        
977        // Generate request body for signing (if any)
978        let body_string: Option<Vec<u8>> = None;
979        
980        // Sign the request
981        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
982            Ok(sig) => sig,
983            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
984        };
985        
986        // Add signature to query params
987        query_params.push(("signature".to_string(), signature));
988    }
989
990    // Apply all query parameters
991    if !query_params.is_empty() {
992        req_builder = req_builder.query(&query_params);
993    }
994
995
996    // Add user agent if configured
997    if let Some(ref user_agent) = configuration.user_agent {
998        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
999    }
1000
1001    // Apply all header parameters
1002    for (header_name, header_value) in header_params {
1003        req_builder = req_builder.header(&header_name, &header_value);
1004    }
1005
1006
1007    let req = req_builder.build()?;
1008    let resp = configuration.client.execute(req).await?;
1009
1010    let status = resp.status();
1011    let content_type = resp
1012        .headers()
1013        .get("content-type")
1014        .and_then(|v| v.to_str().ok())
1015        .unwrap_or("application/octet-stream");
1016    let content_type = super::ContentType::from(content_type);
1017
1018    if !status.is_client_error() && !status.is_server_error() {
1019        let content = resp.text().await?;
1020        match content_type {
1021            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1022            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::MarginGetMarginIsolatedMarginDataV1RespItem&gt;`"))),
1023            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::MarginGetMarginIsolatedMarginDataV1RespItem&gt;`")))),
1024        }
1025    } else {
1026        let content = resp.text().await?;
1027        let entity: Option<MarginGetMarginIsolatedMarginDataV1Error> = serde_json::from_str(&content).ok();
1028        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1029    }
1030}
1031
1032/// Get personal margin level information
1033pub async fn margin_get_margin_trade_coeff_v1(configuration: &configuration::Configuration, params: MarginGetMarginTradeCoeffV1Params) -> Result<models::MarginGetMarginTradeCoeffV1Resp, Error<MarginGetMarginTradeCoeffV1Error>> {
1034
1035    let uri_str = format!("{}/sapi/v1/margin/tradeCoeff", configuration.base_path);
1036    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1037
1038    // Create a mutable vector for query parameters
1039    let mut query_params: Vec<(String, String)> = Vec::new();
1040
1041    if let Some(ref param_value) = params.recv_window {
1042        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1043    }
1044    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1045
1046    // Create header parameters collection
1047    let mut header_params = std::collections::HashMap::new();
1048
1049    // Handle Binance Auth first if configured
1050    if let Some(ref binance_auth) = configuration.binance_auth {
1051        // Add API key to headers
1052        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1053        
1054        // Generate request body for signing (if any)
1055        let body_string: Option<Vec<u8>> = None;
1056        
1057        // Sign the request
1058        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1059            Ok(sig) => sig,
1060            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1061        };
1062        
1063        // Add signature to query params
1064        query_params.push(("signature".to_string(), signature));
1065    }
1066
1067    // Apply all query parameters
1068    if !query_params.is_empty() {
1069        req_builder = req_builder.query(&query_params);
1070    }
1071
1072
1073    // Add user agent if configured
1074    if let Some(ref user_agent) = configuration.user_agent {
1075        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1076    }
1077
1078    // Apply all header parameters
1079    for (header_name, header_value) in header_params {
1080        req_builder = req_builder.header(&header_name, &header_value);
1081    }
1082
1083
1084    let req = req_builder.build()?;
1085    let resp = configuration.client.execute(req).await?;
1086
1087    let status = resp.status();
1088    let content_type = resp
1089        .headers()
1090        .get("content-type")
1091        .and_then(|v| v.to_str().ok())
1092        .unwrap_or("application/octet-stream");
1093    let content_type = super::ContentType::from(content_type);
1094
1095    if !status.is_client_error() && !status.is_server_error() {
1096        let content = resp.text().await?;
1097        match content_type {
1098            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1099            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetMarginTradeCoeffV1Resp`"))),
1100            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetMarginTradeCoeffV1Resp`")))),
1101        }
1102    } else {
1103        let content = resp.text().await?;
1104        let entity: Option<MarginGetMarginTradeCoeffV1Error> = serde_json::from_str(&content).ok();
1105        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1106    }
1107}
1108