binance/spot/apis/
portfolio_margin_pro_api.rs

1/*
2 * Binance Spot API
3 *
4 * OpenAPI specification for Binance exchange - Spot API
5 *
6 * The version of the OpenAPI document: 0.2.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::spot::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`create_portfolio_asset_collection_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct CreatePortfolioAssetCollectionV1Params {
20    pub asset: String,
21    pub timestamp: i64,
22    pub recv_window: Option<i64>
23}
24
25/// struct for passing parameters to the method [`create_portfolio_auto_collection_v1`]
26#[derive(Clone, Debug, Default)]
27pub struct CreatePortfolioAutoCollectionV1Params {
28    pub timestamp: i64,
29    pub recv_window: Option<i64>
30}
31
32/// struct for passing parameters to the method [`create_portfolio_bnb_transfer_v1`]
33#[derive(Clone, Debug, Default)]
34pub struct CreatePortfolioBnbTransferV1Params {
35    pub amount: String,
36    pub timestamp: i64,
37    pub transfer_side: String,
38    pub recv_window: Option<i64>
39}
40
41/// struct for passing parameters to the method [`create_portfolio_mint_v1`]
42#[derive(Clone, Debug, Default)]
43pub struct CreatePortfolioMintV1Params {
44    pub amount: String,
45    pub from_asset: String,
46    pub target_asset: String,
47    pub timestamp: i64,
48    pub recv_window: Option<i64>
49}
50
51/// struct for passing parameters to the method [`create_portfolio_redeem_v1`]
52#[derive(Clone, Debug, Default)]
53pub struct CreatePortfolioRedeemV1Params {
54    pub amount: String,
55    pub from_asset: String,
56    pub target_asset: String,
57    pub timestamp: i64,
58    pub recv_window: Option<i64>
59}
60
61/// struct for passing parameters to the method [`create_portfolio_repay_futures_negative_balance_v1`]
62#[derive(Clone, Debug, Default)]
63pub struct CreatePortfolioRepayFuturesNegativeBalanceV1Params {
64    pub timestamp: i64,
65    pub from: Option<String>,
66    pub recv_window: Option<i64>
67}
68
69/// struct for passing parameters to the method [`create_portfolio_repay_futures_switch_v1`]
70#[derive(Clone, Debug, Default)]
71pub struct CreatePortfolioRepayFuturesSwitchV1Params {
72    pub auto_repay: String,
73    pub timestamp: i64,
74    pub recv_window: Option<i64>
75}
76
77/// struct for passing parameters to the method [`create_portfolio_repay_v1`]
78#[derive(Clone, Debug, Default)]
79pub struct CreatePortfolioRepayV1Params {
80    pub timestamp: i64,
81    pub from: Option<String>,
82    pub recv_window: Option<i64>
83}
84
85/// struct for passing parameters to the method [`get_portfolio_account_v1`]
86#[derive(Clone, Debug, Default)]
87pub struct GetPortfolioAccountV1Params {
88    pub timestamp: i64,
89    pub recv_window: Option<i64>
90}
91
92/// struct for passing parameters to the method [`get_portfolio_account_v2`]
93#[derive(Clone, Debug, Default)]
94pub struct GetPortfolioAccountV2Params {
95    pub timestamp: i64,
96    pub recv_window: Option<i64>
97}
98
99/// struct for passing parameters to the method [`get_portfolio_asset_index_price_v1`]
100#[derive(Clone, Debug, Default)]
101pub struct GetPortfolioAssetIndexPriceV1Params {
102    pub asset: Option<String>
103}
104
105/// struct for passing parameters to the method [`get_portfolio_balance_v1`]
106#[derive(Clone, Debug, Default)]
107pub struct GetPortfolioBalanceV1Params {
108    pub timestamp: i64,
109    pub asset: Option<String>,
110    pub recv_window: Option<i64>
111}
112
113/// struct for passing parameters to the method [`get_portfolio_collateral_rate_v2`]
114#[derive(Clone, Debug, Default)]
115pub struct GetPortfolioCollateralRateV2Params {
116    pub timestamp: i64,
117    pub recv_window: Option<i64>
118}
119
120/// struct for passing parameters to the method [`get_portfolio_interest_history_v1`]
121#[derive(Clone, Debug, Default)]
122pub struct GetPortfolioInterestHistoryV1Params {
123    pub timestamp: i64,
124    pub asset: Option<String>,
125    pub start_time: Option<i64>,
126    pub end_time: Option<i64>,
127    /// Default:10 Max:100
128    pub size: Option<i64>,
129    pub recv_window: Option<i64>
130}
131
132/// struct for passing parameters to the method [`get_portfolio_pm_loan_history_v1`]
133#[derive(Clone, Debug, Default)]
134pub struct GetPortfolioPmLoanHistoryV1Params {
135    pub timestamp: i64,
136    pub start_time: Option<i64>,
137    pub end_time: Option<i64>,
138    /// Currently querying page. Start from 1. Default:1
139    pub current: Option<i64>,
140    /// Default:10 Max:100
141    pub size: Option<i64>,
142    pub recv_window: Option<i64>
143}
144
145/// struct for passing parameters to the method [`get_portfolio_pm_loan_v1`]
146#[derive(Clone, Debug, Default)]
147pub struct GetPortfolioPmLoanV1Params {
148    pub timestamp: i64,
149    pub recv_window: Option<i64>
150}
151
152/// struct for passing parameters to the method [`get_portfolio_repay_futures_switch_v1`]
153#[derive(Clone, Debug, Default)]
154pub struct GetPortfolioRepayFuturesSwitchV1Params {
155    pub timestamp: i64,
156    pub recv_window: Option<i64>
157}
158
159
160/// struct for typed errors of method [`create_portfolio_asset_collection_v1`]
161#[derive(Debug, Clone, Serialize, Deserialize)]
162#[serde(untagged)]
163pub enum CreatePortfolioAssetCollectionV1Error {
164    Status4XX(models::ApiError),
165    Status5XX(models::ApiError),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`create_portfolio_auto_collection_v1`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum CreatePortfolioAutoCollectionV1Error {
173    Status4XX(models::ApiError),
174    Status5XX(models::ApiError),
175    UnknownValue(serde_json::Value),
176}
177
178/// struct for typed errors of method [`create_portfolio_bnb_transfer_v1`]
179#[derive(Debug, Clone, Serialize, Deserialize)]
180#[serde(untagged)]
181pub enum CreatePortfolioBnbTransferV1Error {
182    Status4XX(models::ApiError),
183    Status5XX(models::ApiError),
184    UnknownValue(serde_json::Value),
185}
186
187/// struct for typed errors of method [`create_portfolio_mint_v1`]
188#[derive(Debug, Clone, Serialize, Deserialize)]
189#[serde(untagged)]
190pub enum CreatePortfolioMintV1Error {
191    Status4XX(models::ApiError),
192    Status5XX(models::ApiError),
193    UnknownValue(serde_json::Value),
194}
195
196/// struct for typed errors of method [`create_portfolio_redeem_v1`]
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum CreatePortfolioRedeemV1Error {
200    Status4XX(models::ApiError),
201    Status5XX(models::ApiError),
202    UnknownValue(serde_json::Value),
203}
204
205/// struct for typed errors of method [`create_portfolio_repay_futures_negative_balance_v1`]
206#[derive(Debug, Clone, Serialize, Deserialize)]
207#[serde(untagged)]
208pub enum CreatePortfolioRepayFuturesNegativeBalanceV1Error {
209    Status4XX(models::ApiError),
210    Status5XX(models::ApiError),
211    UnknownValue(serde_json::Value),
212}
213
214/// struct for typed errors of method [`create_portfolio_repay_futures_switch_v1`]
215#[derive(Debug, Clone, Serialize, Deserialize)]
216#[serde(untagged)]
217pub enum CreatePortfolioRepayFuturesSwitchV1Error {
218    Status4XX(models::ApiError),
219    Status5XX(models::ApiError),
220    UnknownValue(serde_json::Value),
221}
222
223/// struct for typed errors of method [`create_portfolio_repay_v1`]
224#[derive(Debug, Clone, Serialize, Deserialize)]
225#[serde(untagged)]
226pub enum CreatePortfolioRepayV1Error {
227    Status4XX(models::ApiError),
228    Status5XX(models::ApiError),
229    UnknownValue(serde_json::Value),
230}
231
232/// struct for typed errors of method [`get_portfolio_account_v1`]
233#[derive(Debug, Clone, Serialize, Deserialize)]
234#[serde(untagged)]
235pub enum GetPortfolioAccountV1Error {
236    Status4XX(models::ApiError),
237    Status5XX(models::ApiError),
238    UnknownValue(serde_json::Value),
239}
240
241/// struct for typed errors of method [`get_portfolio_account_v2`]
242#[derive(Debug, Clone, Serialize, Deserialize)]
243#[serde(untagged)]
244pub enum GetPortfolioAccountV2Error {
245    Status4XX(models::ApiError),
246    Status5XX(models::ApiError),
247    UnknownValue(serde_json::Value),
248}
249
250/// struct for typed errors of method [`get_portfolio_asset_index_price_v1`]
251#[derive(Debug, Clone, Serialize, Deserialize)]
252#[serde(untagged)]
253pub enum GetPortfolioAssetIndexPriceV1Error {
254    Status4XX(models::ApiError),
255    Status5XX(models::ApiError),
256    UnknownValue(serde_json::Value),
257}
258
259/// struct for typed errors of method [`get_portfolio_balance_v1`]
260#[derive(Debug, Clone, Serialize, Deserialize)]
261#[serde(untagged)]
262pub enum GetPortfolioBalanceV1Error {
263    Status4XX(models::ApiError),
264    Status5XX(models::ApiError),
265    UnknownValue(serde_json::Value),
266}
267
268/// struct for typed errors of method [`get_portfolio_collateral_rate_v1`]
269#[derive(Debug, Clone, Serialize, Deserialize)]
270#[serde(untagged)]
271pub enum GetPortfolioCollateralRateV1Error {
272    Status4XX(models::ApiError),
273    Status5XX(models::ApiError),
274    UnknownValue(serde_json::Value),
275}
276
277/// struct for typed errors of method [`get_portfolio_collateral_rate_v2`]
278#[derive(Debug, Clone, Serialize, Deserialize)]
279#[serde(untagged)]
280pub enum GetPortfolioCollateralRateV2Error {
281    Status4XX(models::ApiError),
282    Status5XX(models::ApiError),
283    UnknownValue(serde_json::Value),
284}
285
286/// struct for typed errors of method [`get_portfolio_interest_history_v1`]
287#[derive(Debug, Clone, Serialize, Deserialize)]
288#[serde(untagged)]
289pub enum GetPortfolioInterestHistoryV1Error {
290    Status4XX(models::ApiError),
291    Status5XX(models::ApiError),
292    UnknownValue(serde_json::Value),
293}
294
295/// struct for typed errors of method [`get_portfolio_margin_asset_leverage_v1`]
296#[derive(Debug, Clone, Serialize, Deserialize)]
297#[serde(untagged)]
298pub enum GetPortfolioMarginAssetLeverageV1Error {
299    Status4XX(models::ApiError),
300    Status5XX(models::ApiError),
301    UnknownValue(serde_json::Value),
302}
303
304/// struct for typed errors of method [`get_portfolio_pm_loan_history_v1`]
305#[derive(Debug, Clone, Serialize, Deserialize)]
306#[serde(untagged)]
307pub enum GetPortfolioPmLoanHistoryV1Error {
308    Status4XX(models::ApiError),
309    Status5XX(models::ApiError),
310    UnknownValue(serde_json::Value),
311}
312
313/// struct for typed errors of method [`get_portfolio_pm_loan_v1`]
314#[derive(Debug, Clone, Serialize, Deserialize)]
315#[serde(untagged)]
316pub enum GetPortfolioPmLoanV1Error {
317    Status4XX(models::ApiError),
318    Status5XX(models::ApiError),
319    UnknownValue(serde_json::Value),
320}
321
322/// struct for typed errors of method [`get_portfolio_repay_futures_switch_v1`]
323#[derive(Debug, Clone, Serialize, Deserialize)]
324#[serde(untagged)]
325pub enum GetPortfolioRepayFuturesSwitchV1Error {
326    Status4XX(models::ApiError),
327    Status5XX(models::ApiError),
328    UnknownValue(serde_json::Value),
329}
330
331
332/// Transfers specific asset from Futures Account to Margin account
333pub async fn create_portfolio_asset_collection_v1(configuration: &configuration::Configuration, params: CreatePortfolioAssetCollectionV1Params) -> Result<models::CreatePortfolioAssetCollectionV1Resp, Error<CreatePortfolioAssetCollectionV1Error>> {
334
335    let uri_str = format!("{}/sapi/v1/portfolio/asset-collection", configuration.base_path);
336    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
337
338    // Create a mutable vector for query parameters
339    let mut query_params: Vec<(String, String)> = Vec::new();
340
341
342    // Create header parameters collection
343    let mut header_params = std::collections::HashMap::new();
344
345    // Handle Binance Auth first if configured
346    if let Some(ref binance_auth) = configuration.binance_auth {
347        // Add API key to headers
348        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
349        
350        // Generate request body for signing (if any)
351        let body_string: Option<Vec<u8>> = None;
352        
353        // Sign the request
354        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
355            Ok(sig) => sig,
356            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
357        };
358        
359        // Add signature to query params
360        query_params.push(("signature".to_string(), signature));
361    }
362
363    // Apply all query parameters
364    if !query_params.is_empty() {
365        req_builder = req_builder.query(&query_params);
366    }
367
368
369    // Add user agent if configured
370    if let Some(ref user_agent) = configuration.user_agent {
371        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
372    }
373
374    // Apply all header parameters
375    for (header_name, header_value) in header_params {
376        req_builder = req_builder.header(&header_name, &header_value);
377    }
378
379    let mut multipart_form_params = std::collections::HashMap::new();
380    multipart_form_params.insert("asset", params.asset.to_string());
381    if let Some(param_value) = params.recv_window {
382        multipart_form_params.insert("recvWindow", param_value.to_string());
383    }
384    multipart_form_params.insert("timestamp", params.timestamp.to_string());
385    req_builder = req_builder.form(&multipart_form_params);
386
387    let req = req_builder.build()?;
388    let resp = configuration.client.execute(req).await?;
389
390    let status = resp.status();
391    let content_type = resp
392        .headers()
393        .get("content-type")
394        .and_then(|v| v.to_str().ok())
395        .unwrap_or("application/octet-stream");
396    let content_type = super::ContentType::from(content_type);
397
398    if !status.is_client_error() && !status.is_server_error() {
399        let content = resp.text().await?;
400        match content_type {
401            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
402            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioAssetCollectionV1Resp`"))),
403            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::CreatePortfolioAssetCollectionV1Resp`")))),
404        }
405    } else {
406        let content = resp.text().await?;
407        let entity: Option<CreatePortfolioAssetCollectionV1Error> = serde_json::from_str(&content).ok();
408        Err(Error::ResponseError(ResponseContent { status, content, entity }))
409    }
410}
411
412/// Transfers all assets from Futures Account to Margin account
413pub async fn create_portfolio_auto_collection_v1(configuration: &configuration::Configuration, params: CreatePortfolioAutoCollectionV1Params) -> Result<models::CreatePortfolioAutoCollectionV1Resp, Error<CreatePortfolioAutoCollectionV1Error>> {
414
415    let uri_str = format!("{}/sapi/v1/portfolio/auto-collection", configuration.base_path);
416    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
417
418    // Create a mutable vector for query parameters
419    let mut query_params: Vec<(String, String)> = Vec::new();
420
421
422    // Create header parameters collection
423    let mut header_params = std::collections::HashMap::new();
424
425    // Handle Binance Auth first if configured
426    if let Some(ref binance_auth) = configuration.binance_auth {
427        // Add API key to headers
428        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
429        
430        // Generate request body for signing (if any)
431        let body_string: Option<Vec<u8>> = None;
432        
433        // Sign the request
434        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
435            Ok(sig) => sig,
436            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
437        };
438        
439        // Add signature to query params
440        query_params.push(("signature".to_string(), signature));
441    }
442
443    // Apply all query parameters
444    if !query_params.is_empty() {
445        req_builder = req_builder.query(&query_params);
446    }
447
448
449    // Add user agent if configured
450    if let Some(ref user_agent) = configuration.user_agent {
451        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
452    }
453
454    // Apply all header parameters
455    for (header_name, header_value) in header_params {
456        req_builder = req_builder.header(&header_name, &header_value);
457    }
458
459    let mut multipart_form_params = std::collections::HashMap::new();
460    if let Some(param_value) = params.recv_window {
461        multipart_form_params.insert("recvWindow", param_value.to_string());
462    }
463    multipart_form_params.insert("timestamp", params.timestamp.to_string());
464    req_builder = req_builder.form(&multipart_form_params);
465
466    let req = req_builder.build()?;
467    let resp = configuration.client.execute(req).await?;
468
469    let status = resp.status();
470    let content_type = resp
471        .headers()
472        .get("content-type")
473        .and_then(|v| v.to_str().ok())
474        .unwrap_or("application/octet-stream");
475    let content_type = super::ContentType::from(content_type);
476
477    if !status.is_client_error() && !status.is_server_error() {
478        let content = resp.text().await?;
479        match content_type {
480            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
481            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioAutoCollectionV1Resp`"))),
482            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::CreatePortfolioAutoCollectionV1Resp`")))),
483        }
484    } else {
485        let content = resp.text().await?;
486        let entity: Option<CreatePortfolioAutoCollectionV1Error> = serde_json::from_str(&content).ok();
487        Err(Error::ResponseError(ResponseContent { status, content, entity }))
488    }
489}
490
491/// BNB transfer can be between Margin Account and USDM Account
492pub async fn create_portfolio_bnb_transfer_v1(configuration: &configuration::Configuration, params: CreatePortfolioBnbTransferV1Params) -> Result<models::CreatePortfolioBnbTransferV1Resp, Error<CreatePortfolioBnbTransferV1Error>> {
493
494    let uri_str = format!("{}/sapi/v1/portfolio/bnb-transfer", configuration.base_path);
495    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
496
497    // Create a mutable vector for query parameters
498    let mut query_params: Vec<(String, String)> = Vec::new();
499
500
501    // Create header parameters collection
502    let mut header_params = std::collections::HashMap::new();
503
504    // Handle Binance Auth first if configured
505    if let Some(ref binance_auth) = configuration.binance_auth {
506        // Add API key to headers
507        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
508        
509        // Generate request body for signing (if any)
510        let body_string: Option<Vec<u8>> = None;
511        
512        // Sign the request
513        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
514            Ok(sig) => sig,
515            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
516        };
517        
518        // Add signature to query params
519        query_params.push(("signature".to_string(), signature));
520    }
521
522    // Apply all query parameters
523    if !query_params.is_empty() {
524        req_builder = req_builder.query(&query_params);
525    }
526
527
528    // Add user agent if configured
529    if let Some(ref user_agent) = configuration.user_agent {
530        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
531    }
532
533    // Apply all header parameters
534    for (header_name, header_value) in header_params {
535        req_builder = req_builder.header(&header_name, &header_value);
536    }
537
538    let mut multipart_form_params = std::collections::HashMap::new();
539    multipart_form_params.insert("amount", params.amount.to_string());
540    if let Some(param_value) = params.recv_window {
541        multipart_form_params.insert("recvWindow", param_value.to_string());
542    }
543    multipart_form_params.insert("timestamp", params.timestamp.to_string());
544    multipart_form_params.insert("transferSide", params.transfer_side.to_string());
545    req_builder = req_builder.form(&multipart_form_params);
546
547    let req = req_builder.build()?;
548    let resp = configuration.client.execute(req).await?;
549
550    let status = resp.status();
551    let content_type = resp
552        .headers()
553        .get("content-type")
554        .and_then(|v| v.to_str().ok())
555        .unwrap_or("application/octet-stream");
556    let content_type = super::ContentType::from(content_type);
557
558    if !status.is_client_error() && !status.is_server_error() {
559        let content = resp.text().await?;
560        match content_type {
561            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
562            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioBnbTransferV1Resp`"))),
563            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::CreatePortfolioBnbTransferV1Resp`")))),
564        }
565    } else {
566        let content = resp.text().await?;
567        let entity: Option<CreatePortfolioBnbTransferV1Error> = serde_json::from_str(&content).ok();
568        Err(Error::ResponseError(ResponseContent { status, content, entity }))
569    }
570}
571
572/// Mint BFUSD for all types of Portfolio Margin account
573pub async fn create_portfolio_mint_v1(configuration: &configuration::Configuration, params: CreatePortfolioMintV1Params) -> Result<models::CreatePortfolioMintV1Resp, Error<CreatePortfolioMintV1Error>> {
574
575    let uri_str = format!("{}/sapi/v1/portfolio/mint", configuration.base_path);
576    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
577
578    // Create a mutable vector for query parameters
579    let mut query_params: Vec<(String, String)> = Vec::new();
580
581
582    // Create header parameters collection
583    let mut header_params = std::collections::HashMap::new();
584
585    // Handle Binance Auth first if configured
586    if let Some(ref binance_auth) = configuration.binance_auth {
587        // Add API key to headers
588        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
589        
590        // Generate request body for signing (if any)
591        let body_string: Option<Vec<u8>> = None;
592        
593        // Sign the request
594        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
595            Ok(sig) => sig,
596            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
597        };
598        
599        // Add signature to query params
600        query_params.push(("signature".to_string(), signature));
601    }
602
603    // Apply all query parameters
604    if !query_params.is_empty() {
605        req_builder = req_builder.query(&query_params);
606    }
607
608
609    // Add user agent if configured
610    if let Some(ref user_agent) = configuration.user_agent {
611        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
612    }
613
614    // Apply all header parameters
615    for (header_name, header_value) in header_params {
616        req_builder = req_builder.header(&header_name, &header_value);
617    }
618
619    let mut multipart_form_params = std::collections::HashMap::new();
620    multipart_form_params.insert("amount", params.amount.to_string());
621    multipart_form_params.insert("fromAsset", params.from_asset.to_string());
622    if let Some(param_value) = params.recv_window {
623        multipart_form_params.insert("recvWindow", param_value.to_string());
624    }
625    multipart_form_params.insert("targetAsset", params.target_asset.to_string());
626    multipart_form_params.insert("timestamp", params.timestamp.to_string());
627    req_builder = req_builder.form(&multipart_form_params);
628
629    let req = req_builder.build()?;
630    let resp = configuration.client.execute(req).await?;
631
632    let status = resp.status();
633    let content_type = resp
634        .headers()
635        .get("content-type")
636        .and_then(|v| v.to_str().ok())
637        .unwrap_or("application/octet-stream");
638    let content_type = super::ContentType::from(content_type);
639
640    if !status.is_client_error() && !status.is_server_error() {
641        let content = resp.text().await?;
642        match content_type {
643            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
644            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioMintV1Resp`"))),
645            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::CreatePortfolioMintV1Resp`")))),
646        }
647    } else {
648        let content = resp.text().await?;
649        let entity: Option<CreatePortfolioMintV1Error> = serde_json::from_str(&content).ok();
650        Err(Error::ResponseError(ResponseContent { status, content, entity }))
651    }
652}
653
654/// Redeem BFUSD for all types of Portfolio Margin account
655pub async fn create_portfolio_redeem_v1(configuration: &configuration::Configuration, params: CreatePortfolioRedeemV1Params) -> Result<models::CreatePortfolioRedeemV1Resp, Error<CreatePortfolioRedeemV1Error>> {
656
657    let uri_str = format!("{}/sapi/v1/portfolio/redeem", configuration.base_path);
658    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
659
660    // Create a mutable vector for query parameters
661    let mut query_params: Vec<(String, String)> = Vec::new();
662
663
664    // Create header parameters collection
665    let mut header_params = std::collections::HashMap::new();
666
667    // Handle Binance Auth first if configured
668    if let Some(ref binance_auth) = configuration.binance_auth {
669        // Add API key to headers
670        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
671        
672        // Generate request body for signing (if any)
673        let body_string: Option<Vec<u8>> = None;
674        
675        // Sign the request
676        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
677            Ok(sig) => sig,
678            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
679        };
680        
681        // Add signature to query params
682        query_params.push(("signature".to_string(), signature));
683    }
684
685    // Apply all query parameters
686    if !query_params.is_empty() {
687        req_builder = req_builder.query(&query_params);
688    }
689
690
691    // Add user agent if configured
692    if let Some(ref user_agent) = configuration.user_agent {
693        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
694    }
695
696    // Apply all header parameters
697    for (header_name, header_value) in header_params {
698        req_builder = req_builder.header(&header_name, &header_value);
699    }
700
701    let mut multipart_form_params = std::collections::HashMap::new();
702    multipart_form_params.insert("amount", params.amount.to_string());
703    multipart_form_params.insert("fromAsset", params.from_asset.to_string());
704    if let Some(param_value) = params.recv_window {
705        multipart_form_params.insert("recvWindow", param_value.to_string());
706    }
707    multipart_form_params.insert("targetAsset", params.target_asset.to_string());
708    multipart_form_params.insert("timestamp", params.timestamp.to_string());
709    req_builder = req_builder.form(&multipart_form_params);
710
711    let req = req_builder.build()?;
712    let resp = configuration.client.execute(req).await?;
713
714    let status = resp.status();
715    let content_type = resp
716        .headers()
717        .get("content-type")
718        .and_then(|v| v.to_str().ok())
719        .unwrap_or("application/octet-stream");
720    let content_type = super::ContentType::from(content_type);
721
722    if !status.is_client_error() && !status.is_server_error() {
723        let content = resp.text().await?;
724        match content_type {
725            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
726            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioRedeemV1Resp`"))),
727            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::CreatePortfolioRedeemV1Resp`")))),
728        }
729    } else {
730        let content = resp.text().await?;
731        let entity: Option<CreatePortfolioRedeemV1Error> = serde_json::from_str(&content).ok();
732        Err(Error::ResponseError(ResponseContent { status, content, entity }))
733    }
734}
735
736/// Repay futures Negative Balance
737pub async fn create_portfolio_repay_futures_negative_balance_v1(configuration: &configuration::Configuration, params: CreatePortfolioRepayFuturesNegativeBalanceV1Params) -> Result<models::CreatePortfolioRepayFuturesNegativeBalanceV1Resp, Error<CreatePortfolioRepayFuturesNegativeBalanceV1Error>> {
738
739    let uri_str = format!("{}/sapi/v1/portfolio/repay-futures-negative-balance", configuration.base_path);
740    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
741
742    // Create a mutable vector for query parameters
743    let mut query_params: Vec<(String, String)> = Vec::new();
744
745
746    // Create header parameters collection
747    let mut header_params = std::collections::HashMap::new();
748
749    // Handle Binance Auth first if configured
750    if let Some(ref binance_auth) = configuration.binance_auth {
751        // Add API key to headers
752        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
753        
754        // Generate request body for signing (if any)
755        let body_string: Option<Vec<u8>> = None;
756        
757        // Sign the request
758        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
759            Ok(sig) => sig,
760            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
761        };
762        
763        // Add signature to query params
764        query_params.push(("signature".to_string(), signature));
765    }
766
767    // Apply all query parameters
768    if !query_params.is_empty() {
769        req_builder = req_builder.query(&query_params);
770    }
771
772
773    // Add user agent if configured
774    if let Some(ref user_agent) = configuration.user_agent {
775        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
776    }
777
778    // Apply all header parameters
779    for (header_name, header_value) in header_params {
780        req_builder = req_builder.header(&header_name, &header_value);
781    }
782
783    let mut multipart_form_params = std::collections::HashMap::new();
784    if let Some(param_value) = params.from {
785        multipart_form_params.insert("from", param_value.to_string());
786    }
787    if let Some(param_value) = params.recv_window {
788        multipart_form_params.insert("recvWindow", param_value.to_string());
789    }
790    multipart_form_params.insert("timestamp", params.timestamp.to_string());
791    req_builder = req_builder.form(&multipart_form_params);
792
793    let req = req_builder.build()?;
794    let resp = configuration.client.execute(req).await?;
795
796    let status = resp.status();
797    let content_type = resp
798        .headers()
799        .get("content-type")
800        .and_then(|v| v.to_str().ok())
801        .unwrap_or("application/octet-stream");
802    let content_type = super::ContentType::from(content_type);
803
804    if !status.is_client_error() && !status.is_server_error() {
805        let content = resp.text().await?;
806        match content_type {
807            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
808            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioRepayFuturesNegativeBalanceV1Resp`"))),
809            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::CreatePortfolioRepayFuturesNegativeBalanceV1Resp`")))),
810        }
811    } else {
812        let content = resp.text().await?;
813        let entity: Option<CreatePortfolioRepayFuturesNegativeBalanceV1Error> = serde_json::from_str(&content).ok();
814        Err(Error::ResponseError(ResponseContent { status, content, entity }))
815    }
816}
817
818/// Change Auto-repay-futures Status
819pub async fn create_portfolio_repay_futures_switch_v1(configuration: &configuration::Configuration, params: CreatePortfolioRepayFuturesSwitchV1Params) -> Result<models::CreatePortfolioRepayFuturesSwitchV1Resp, Error<CreatePortfolioRepayFuturesSwitchV1Error>> {
820
821    let uri_str = format!("{}/sapi/v1/portfolio/repay-futures-switch", configuration.base_path);
822    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
823
824    // Create a mutable vector for query parameters
825    let mut query_params: Vec<(String, String)> = Vec::new();
826
827
828    // Create header parameters collection
829    let mut header_params = std::collections::HashMap::new();
830
831    // Handle Binance Auth first if configured
832    if let Some(ref binance_auth) = configuration.binance_auth {
833        // Add API key to headers
834        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
835        
836        // Generate request body for signing (if any)
837        let body_string: Option<Vec<u8>> = None;
838        
839        // Sign the request
840        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
841            Ok(sig) => sig,
842            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
843        };
844        
845        // Add signature to query params
846        query_params.push(("signature".to_string(), signature));
847    }
848
849    // Apply all query parameters
850    if !query_params.is_empty() {
851        req_builder = req_builder.query(&query_params);
852    }
853
854
855    // Add user agent if configured
856    if let Some(ref user_agent) = configuration.user_agent {
857        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
858    }
859
860    // Apply all header parameters
861    for (header_name, header_value) in header_params {
862        req_builder = req_builder.header(&header_name, &header_value);
863    }
864
865    let mut multipart_form_params = std::collections::HashMap::new();
866    multipart_form_params.insert("autoRepay", params.auto_repay.to_string());
867    if let Some(param_value) = params.recv_window {
868        multipart_form_params.insert("recvWindow", param_value.to_string());
869    }
870    multipart_form_params.insert("timestamp", params.timestamp.to_string());
871    req_builder = req_builder.form(&multipart_form_params);
872
873    let req = req_builder.build()?;
874    let resp = configuration.client.execute(req).await?;
875
876    let status = resp.status();
877    let content_type = resp
878        .headers()
879        .get("content-type")
880        .and_then(|v| v.to_str().ok())
881        .unwrap_or("application/octet-stream");
882    let content_type = super::ContentType::from(content_type);
883
884    if !status.is_client_error() && !status.is_server_error() {
885        let content = resp.text().await?;
886        match content_type {
887            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
888            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioRepayFuturesSwitchV1Resp`"))),
889            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::CreatePortfolioRepayFuturesSwitchV1Resp`")))),
890        }
891    } else {
892        let content = resp.text().await?;
893        let entity: Option<CreatePortfolioRepayFuturesSwitchV1Error> = serde_json::from_str(&content).ok();
894        Err(Error::ResponseError(ResponseContent { status, content, entity }))
895    }
896}
897
898/// Repay Portfolio Margin Pro Bankruptcy Loan
899pub async fn create_portfolio_repay_v1(configuration: &configuration::Configuration, params: CreatePortfolioRepayV1Params) -> Result<models::CreatePortfolioRepayV1Resp, Error<CreatePortfolioRepayV1Error>> {
900
901    let uri_str = format!("{}/sapi/v1/portfolio/repay", configuration.base_path);
902    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
903
904    // Create a mutable vector for query parameters
905    let mut query_params: Vec<(String, String)> = Vec::new();
906
907
908    // Create header parameters collection
909    let mut header_params = std::collections::HashMap::new();
910
911    // Handle Binance Auth first if configured
912    if let Some(ref binance_auth) = configuration.binance_auth {
913        // Add API key to headers
914        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
915        
916        // Generate request body for signing (if any)
917        let body_string: Option<Vec<u8>> = None;
918        
919        // Sign the request
920        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
921            Ok(sig) => sig,
922            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
923        };
924        
925        // Add signature to query params
926        query_params.push(("signature".to_string(), signature));
927    }
928
929    // Apply all query parameters
930    if !query_params.is_empty() {
931        req_builder = req_builder.query(&query_params);
932    }
933
934
935    // Add user agent if configured
936    if let Some(ref user_agent) = configuration.user_agent {
937        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
938    }
939
940    // Apply all header parameters
941    for (header_name, header_value) in header_params {
942        req_builder = req_builder.header(&header_name, &header_value);
943    }
944
945    let mut multipart_form_params = std::collections::HashMap::new();
946    if let Some(param_value) = params.from {
947        multipart_form_params.insert("from", param_value.to_string());
948    }
949    if let Some(param_value) = params.recv_window {
950        multipart_form_params.insert("recvWindow", param_value.to_string());
951    }
952    multipart_form_params.insert("timestamp", params.timestamp.to_string());
953    req_builder = req_builder.form(&multipart_form_params);
954
955    let req = req_builder.build()?;
956    let resp = configuration.client.execute(req).await?;
957
958    let status = resp.status();
959    let content_type = resp
960        .headers()
961        .get("content-type")
962        .and_then(|v| v.to_str().ok())
963        .unwrap_or("application/octet-stream");
964    let content_type = super::ContentType::from(content_type);
965
966    if !status.is_client_error() && !status.is_server_error() {
967        let content = resp.text().await?;
968        match content_type {
969            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
970            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreatePortfolioRepayV1Resp`"))),
971            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::CreatePortfolioRepayV1Resp`")))),
972        }
973    } else {
974        let content = resp.text().await?;
975        let entity: Option<CreatePortfolioRepayV1Error> = serde_json::from_str(&content).ok();
976        Err(Error::ResponseError(ResponseContent { status, content, entity }))
977    }
978}
979
980/// Get Portfolio Margin Pro Account Info
981pub async fn get_portfolio_account_v1(configuration: &configuration::Configuration, params: GetPortfolioAccountV1Params) -> Result<models::GetPortfolioAccountV1Resp, Error<GetPortfolioAccountV1Error>> {
982
983    let uri_str = format!("{}/sapi/v1/portfolio/account", configuration.base_path);
984    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
985
986    // Create a mutable vector for query parameters
987    let mut query_params: Vec<(String, String)> = Vec::new();
988
989    if let Some(ref param_value) = params.recv_window {
990        query_params.push(("recvWindow".to_string(), param_value.to_string()));
991    }
992    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
993
994    // Create header parameters collection
995    let mut header_params = std::collections::HashMap::new();
996
997    // Handle Binance Auth first if configured
998    if let Some(ref binance_auth) = configuration.binance_auth {
999        // Add API key to headers
1000        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1001        
1002        // Generate request body for signing (if any)
1003        let body_string: Option<Vec<u8>> = None;
1004        
1005        // Sign the request
1006        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1007            Ok(sig) => sig,
1008            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1009        };
1010        
1011        // Add signature to query params
1012        query_params.push(("signature".to_string(), signature));
1013    }
1014
1015    // Apply all query parameters
1016    if !query_params.is_empty() {
1017        req_builder = req_builder.query(&query_params);
1018    }
1019
1020
1021    // Add user agent if configured
1022    if let Some(ref user_agent) = configuration.user_agent {
1023        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1024    }
1025
1026    // Apply all header parameters
1027    for (header_name, header_value) in header_params {
1028        req_builder = req_builder.header(&header_name, &header_value);
1029    }
1030
1031
1032    let req = req_builder.build()?;
1033    let resp = configuration.client.execute(req).await?;
1034
1035    let status = resp.status();
1036    let content_type = resp
1037        .headers()
1038        .get("content-type")
1039        .and_then(|v| v.to_str().ok())
1040        .unwrap_or("application/octet-stream");
1041    let content_type = super::ContentType::from(content_type);
1042
1043    if !status.is_client_error() && !status.is_server_error() {
1044        let content = resp.text().await?;
1045        match content_type {
1046            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1047            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPortfolioAccountV1Resp`"))),
1048            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::GetPortfolioAccountV1Resp`")))),
1049        }
1050    } else {
1051        let content = resp.text().await?;
1052        let entity: Option<GetPortfolioAccountV1Error> = serde_json::from_str(&content).ok();
1053        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1054    }
1055}
1056
1057/// Get Portfolio Margin Pro SPAN Account Info (For Portfolio Margin Pro SPAN users only)
1058pub async fn get_portfolio_account_v2(configuration: &configuration::Configuration, params: GetPortfolioAccountV2Params) -> Result<(), Error<GetPortfolioAccountV2Error>> {
1059
1060    let uri_str = format!("{}/sapi/v2/portfolio/account", configuration.base_path);
1061    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1062
1063    // Create a mutable vector for query parameters
1064    let mut query_params: Vec<(String, String)> = Vec::new();
1065
1066    if let Some(ref param_value) = params.recv_window {
1067        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1068    }
1069    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1070
1071    // Create header parameters collection
1072    let mut header_params = std::collections::HashMap::new();
1073
1074    // Handle Binance Auth first if configured
1075    if let Some(ref binance_auth) = configuration.binance_auth {
1076        // Add API key to headers
1077        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1078        
1079        // Generate request body for signing (if any)
1080        let body_string: Option<Vec<u8>> = None;
1081        
1082        // Sign the request
1083        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1084            Ok(sig) => sig,
1085            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1086        };
1087        
1088        // Add signature to query params
1089        query_params.push(("signature".to_string(), signature));
1090    }
1091
1092    // Apply all query parameters
1093    if !query_params.is_empty() {
1094        req_builder = req_builder.query(&query_params);
1095    }
1096
1097
1098    // Add user agent if configured
1099    if let Some(ref user_agent) = configuration.user_agent {
1100        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1101    }
1102
1103    // Apply all header parameters
1104    for (header_name, header_value) in header_params {
1105        req_builder = req_builder.header(&header_name, &header_value);
1106    }
1107
1108
1109    let req = req_builder.build()?;
1110    let resp = configuration.client.execute(req).await?;
1111
1112    let status = resp.status();
1113
1114    if !status.is_client_error() && !status.is_server_error() {
1115        Ok(())
1116    } else {
1117        let content = resp.text().await?;
1118        let entity: Option<GetPortfolioAccountV2Error> = serde_json::from_str(&content).ok();
1119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1120    }
1121}
1122
1123/// Query Portfolio Margin Asset Index Price
1124pub async fn get_portfolio_asset_index_price_v1(configuration: &configuration::Configuration, params: GetPortfolioAssetIndexPriceV1Params) -> Result<Vec<models::GetPortfolioAssetIndexPriceV1RespItem>, Error<GetPortfolioAssetIndexPriceV1Error>> {
1125
1126    let uri_str = format!("{}/sapi/v1/portfolio/asset-index-price", configuration.base_path);
1127    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1128
1129    // Create a mutable vector for query parameters
1130    let mut query_params: Vec<(String, String)> = Vec::new();
1131
1132    if let Some(ref param_value) = params.asset {
1133        query_params.push(("asset".to_string(), param_value.to_string()));
1134    }
1135
1136    // Create header parameters collection
1137    let mut header_params = std::collections::HashMap::new();
1138
1139    // Handle Binance Auth first if configured
1140    if let Some(ref binance_auth) = configuration.binance_auth {
1141        // Add API key to headers
1142        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1143        
1144        // Generate request body for signing (if any)
1145        let body_string: Option<Vec<u8>> = None;
1146        
1147        // Sign the request
1148        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1149            Ok(sig) => sig,
1150            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1151        };
1152        
1153        // Add signature to query params
1154        query_params.push(("signature".to_string(), signature));
1155    }
1156
1157    // Apply all query parameters
1158    if !query_params.is_empty() {
1159        req_builder = req_builder.query(&query_params);
1160    }
1161
1162
1163    // Add user agent if configured
1164    if let Some(ref user_agent) = configuration.user_agent {
1165        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1166    }
1167
1168    // Apply all header parameters
1169    for (header_name, header_value) in header_params {
1170        req_builder = req_builder.header(&header_name, &header_value);
1171    }
1172
1173
1174    let req = req_builder.build()?;
1175    let resp = configuration.client.execute(req).await?;
1176
1177    let status = resp.status();
1178    let content_type = resp
1179        .headers()
1180        .get("content-type")
1181        .and_then(|v| v.to_str().ok())
1182        .unwrap_or("application/octet-stream");
1183    let content_type = super::ContentType::from(content_type);
1184
1185    if !status.is_client_error() && !status.is_server_error() {
1186        let content = resp.text().await?;
1187        match content_type {
1188            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1189            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetPortfolioAssetIndexPriceV1RespItem&gt;`"))),
1190            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::GetPortfolioAssetIndexPriceV1RespItem&gt;`")))),
1191        }
1192    } else {
1193        let content = resp.text().await?;
1194        let entity: Option<GetPortfolioAssetIndexPriceV1Error> = serde_json::from_str(&content).ok();
1195        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1196    }
1197}
1198
1199/// Query Portfolio Margin Pro account balance
1200pub async fn get_portfolio_balance_v1(configuration: &configuration::Configuration, params: GetPortfolioBalanceV1Params) -> Result<Vec<models::GetPortfolioBalanceV1RespItem>, Error<GetPortfolioBalanceV1Error>> {
1201
1202    let uri_str = format!("{}/sapi/v1/portfolio/balance", configuration.base_path);
1203    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1204
1205    // Create a mutable vector for query parameters
1206    let mut query_params: Vec<(String, String)> = Vec::new();
1207
1208    if let Some(ref param_value) = params.asset {
1209        query_params.push(("asset".to_string(), param_value.to_string()));
1210    }
1211    if let Some(ref param_value) = params.recv_window {
1212        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1213    }
1214    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1215
1216    // Create header parameters collection
1217    let mut header_params = std::collections::HashMap::new();
1218
1219    // Handle Binance Auth first if configured
1220    if let Some(ref binance_auth) = configuration.binance_auth {
1221        // Add API key to headers
1222        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1223        
1224        // Generate request body for signing (if any)
1225        let body_string: Option<Vec<u8>> = None;
1226        
1227        // Sign the request
1228        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1229            Ok(sig) => sig,
1230            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1231        };
1232        
1233        // Add signature to query params
1234        query_params.push(("signature".to_string(), signature));
1235    }
1236
1237    // Apply all query parameters
1238    if !query_params.is_empty() {
1239        req_builder = req_builder.query(&query_params);
1240    }
1241
1242
1243    // Add user agent if configured
1244    if let Some(ref user_agent) = configuration.user_agent {
1245        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1246    }
1247
1248    // Apply all header parameters
1249    for (header_name, header_value) in header_params {
1250        req_builder = req_builder.header(&header_name, &header_value);
1251    }
1252
1253
1254    let req = req_builder.build()?;
1255    let resp = configuration.client.execute(req).await?;
1256
1257    let status = resp.status();
1258    let content_type = resp
1259        .headers()
1260        .get("content-type")
1261        .and_then(|v| v.to_str().ok())
1262        .unwrap_or("application/octet-stream");
1263    let content_type = super::ContentType::from(content_type);
1264
1265    if !status.is_client_error() && !status.is_server_error() {
1266        let content = resp.text().await?;
1267        match content_type {
1268            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1269            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetPortfolioBalanceV1RespItem&gt;`"))),
1270            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::GetPortfolioBalanceV1RespItem&gt;`")))),
1271        }
1272    } else {
1273        let content = resp.text().await?;
1274        let entity: Option<GetPortfolioBalanceV1Error> = serde_json::from_str(&content).ok();
1275        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1276    }
1277}
1278
1279/// Portfolio Margin Collateral Rate
1280pub async fn get_portfolio_collateral_rate_v1(configuration: &configuration::Configuration) -> Result<Vec<models::GetPortfolioCollateralRateV1RespItem>, Error<GetPortfolioCollateralRateV1Error>> {
1281
1282    let uri_str = format!("{}/sapi/v1/portfolio/collateralRate", configuration.base_path);
1283    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1284
1285    // Create a mutable vector for query parameters
1286    let mut query_params: Vec<(String, String)> = Vec::new();
1287
1288
1289    // Create header parameters collection
1290    let mut header_params = std::collections::HashMap::new();
1291
1292    // Handle Binance Auth first if configured
1293    if let Some(ref binance_auth) = configuration.binance_auth {
1294        // Add API key to headers
1295        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1296        
1297        // Generate request body for signing (if any)
1298        let body_string: Option<Vec<u8>> = None;
1299        
1300        // Sign the request
1301        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1302            Ok(sig) => sig,
1303            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1304        };
1305        
1306        // Add signature to query params
1307        query_params.push(("signature".to_string(), signature));
1308    }
1309
1310    // Apply all query parameters
1311    if !query_params.is_empty() {
1312        req_builder = req_builder.query(&query_params);
1313    }
1314
1315
1316    // Add user agent if configured
1317    if let Some(ref user_agent) = configuration.user_agent {
1318        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1319    }
1320
1321    // Apply all header parameters
1322    for (header_name, header_value) in header_params {
1323        req_builder = req_builder.header(&header_name, &header_value);
1324    }
1325
1326
1327    let req = req_builder.build()?;
1328    let resp = configuration.client.execute(req).await?;
1329
1330    let status = resp.status();
1331    let content_type = resp
1332        .headers()
1333        .get("content-type")
1334        .and_then(|v| v.to_str().ok())
1335        .unwrap_or("application/octet-stream");
1336    let content_type = super::ContentType::from(content_type);
1337
1338    if !status.is_client_error() && !status.is_server_error() {
1339        let content = resp.text().await?;
1340        match content_type {
1341            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1342            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetPortfolioCollateralRateV1RespItem&gt;`"))),
1343            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::GetPortfolioCollateralRateV1RespItem&gt;`")))),
1344        }
1345    } else {
1346        let content = resp.text().await?;
1347        let entity: Option<GetPortfolioCollateralRateV1Error> = serde_json::from_str(&content).ok();
1348        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1349    }
1350}
1351
1352/// Portfolio Margin PRO Tiered Collateral Rate
1353pub async fn get_portfolio_collateral_rate_v2(configuration: &configuration::Configuration, params: GetPortfolioCollateralRateV2Params) -> Result<Vec<models::GetPortfolioCollateralRateV2RespItem>, Error<GetPortfolioCollateralRateV2Error>> {
1354
1355    let uri_str = format!("{}/sapi/v2/portfolio/collateralRate", configuration.base_path);
1356    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1357
1358    // Create a mutable vector for query parameters
1359    let mut query_params: Vec<(String, String)> = Vec::new();
1360
1361    if let Some(ref param_value) = params.recv_window {
1362        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1363    }
1364    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1365
1366    // Create header parameters collection
1367    let mut header_params = std::collections::HashMap::new();
1368
1369    // Handle Binance Auth first if configured
1370    if let Some(ref binance_auth) = configuration.binance_auth {
1371        // Add API key to headers
1372        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1373        
1374        // Generate request body for signing (if any)
1375        let body_string: Option<Vec<u8>> = None;
1376        
1377        // Sign the request
1378        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1379            Ok(sig) => sig,
1380            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1381        };
1382        
1383        // Add signature to query params
1384        query_params.push(("signature".to_string(), signature));
1385    }
1386
1387    // Apply all query parameters
1388    if !query_params.is_empty() {
1389        req_builder = req_builder.query(&query_params);
1390    }
1391
1392
1393    // Add user agent if configured
1394    if let Some(ref user_agent) = configuration.user_agent {
1395        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1396    }
1397
1398    // Apply all header parameters
1399    for (header_name, header_value) in header_params {
1400        req_builder = req_builder.header(&header_name, &header_value);
1401    }
1402
1403
1404    let req = req_builder.build()?;
1405    let resp = configuration.client.execute(req).await?;
1406
1407    let status = resp.status();
1408    let content_type = resp
1409        .headers()
1410        .get("content-type")
1411        .and_then(|v| v.to_str().ok())
1412        .unwrap_or("application/octet-stream");
1413    let content_type = super::ContentType::from(content_type);
1414
1415    if !status.is_client_error() && !status.is_server_error() {
1416        let content = resp.text().await?;
1417        match content_type {
1418            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1419            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetPortfolioCollateralRateV2RespItem&gt;`"))),
1420            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::GetPortfolioCollateralRateV2RespItem&gt;`")))),
1421        }
1422    } else {
1423        let content = resp.text().await?;
1424        let entity: Option<GetPortfolioCollateralRateV2Error> = serde_json::from_str(&content).ok();
1425        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1426    }
1427}
1428
1429/// Query interest history of negative balance for portfolio margin.
1430pub async fn get_portfolio_interest_history_v1(configuration: &configuration::Configuration, params: GetPortfolioInterestHistoryV1Params) -> Result<Vec<models::GetPortfolioInterestHistoryV1RespItem>, Error<GetPortfolioInterestHistoryV1Error>> {
1431
1432    let uri_str = format!("{}/sapi/v1/portfolio/interest-history", configuration.base_path);
1433    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1434
1435    // Create a mutable vector for query parameters
1436    let mut query_params: Vec<(String, String)> = Vec::new();
1437
1438    if let Some(ref param_value) = params.asset {
1439        query_params.push(("asset".to_string(), param_value.to_string()));
1440    }
1441    if let Some(ref param_value) = params.start_time {
1442        query_params.push(("startTime".to_string(), param_value.to_string()));
1443    }
1444    if let Some(ref param_value) = params.end_time {
1445        query_params.push(("endTime".to_string(), param_value.to_string()));
1446    }
1447    if let Some(ref param_value) = params.size {
1448        query_params.push(("size".to_string(), param_value.to_string()));
1449    }
1450    if let Some(ref param_value) = params.recv_window {
1451        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1452    }
1453    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1454
1455    // Create header parameters collection
1456    let mut header_params = std::collections::HashMap::new();
1457
1458    // Handle Binance Auth first if configured
1459    if let Some(ref binance_auth) = configuration.binance_auth {
1460        // Add API key to headers
1461        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1462        
1463        // Generate request body for signing (if any)
1464        let body_string: Option<Vec<u8>> = None;
1465        
1466        // Sign the request
1467        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1468            Ok(sig) => sig,
1469            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1470        };
1471        
1472        // Add signature to query params
1473        query_params.push(("signature".to_string(), signature));
1474    }
1475
1476    // Apply all query parameters
1477    if !query_params.is_empty() {
1478        req_builder = req_builder.query(&query_params);
1479    }
1480
1481
1482    // Add user agent if configured
1483    if let Some(ref user_agent) = configuration.user_agent {
1484        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1485    }
1486
1487    // Apply all header parameters
1488    for (header_name, header_value) in header_params {
1489        req_builder = req_builder.header(&header_name, &header_value);
1490    }
1491
1492
1493    let req = req_builder.build()?;
1494    let resp = configuration.client.execute(req).await?;
1495
1496    let status = resp.status();
1497    let content_type = resp
1498        .headers()
1499        .get("content-type")
1500        .and_then(|v| v.to_str().ok())
1501        .unwrap_or("application/octet-stream");
1502    let content_type = super::ContentType::from(content_type);
1503
1504    if !status.is_client_error() && !status.is_server_error() {
1505        let content = resp.text().await?;
1506        match content_type {
1507            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1508            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetPortfolioInterestHistoryV1RespItem&gt;`"))),
1509            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::GetPortfolioInterestHistoryV1RespItem&gt;`")))),
1510        }
1511    } else {
1512        let content = resp.text().await?;
1513        let entity: Option<GetPortfolioInterestHistoryV1Error> = serde_json::from_str(&content).ok();
1514        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1515    }
1516}
1517
1518/// Get Portfolio Margin Asset Leverage
1519pub async fn get_portfolio_margin_asset_leverage_v1(configuration: &configuration::Configuration) -> Result<Vec<models::GetPortfolioMarginAssetLeverageV1RespItem>, Error<GetPortfolioMarginAssetLeverageV1Error>> {
1520
1521    let uri_str = format!("{}/sapi/v1/portfolio/margin-asset-leverage", configuration.base_path);
1522    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1523
1524    // Create a mutable vector for query parameters
1525    let mut query_params: Vec<(String, String)> = Vec::new();
1526
1527
1528    // Create header parameters collection
1529    let mut header_params = std::collections::HashMap::new();
1530
1531    // Handle Binance Auth first if configured
1532    if let Some(ref binance_auth) = configuration.binance_auth {
1533        // Add API key to headers
1534        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1535        
1536        // Generate request body for signing (if any)
1537        let body_string: Option<Vec<u8>> = None;
1538        
1539        // Sign the request
1540        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1541            Ok(sig) => sig,
1542            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1543        };
1544        
1545        // Add signature to query params
1546        query_params.push(("signature".to_string(), signature));
1547    }
1548
1549    // Apply all query parameters
1550    if !query_params.is_empty() {
1551        req_builder = req_builder.query(&query_params);
1552    }
1553
1554
1555    // Add user agent if configured
1556    if let Some(ref user_agent) = configuration.user_agent {
1557        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1558    }
1559
1560    // Apply all header parameters
1561    for (header_name, header_value) in header_params {
1562        req_builder = req_builder.header(&header_name, &header_value);
1563    }
1564
1565
1566    let req = req_builder.build()?;
1567    let resp = configuration.client.execute(req).await?;
1568
1569    let status = resp.status();
1570    let content_type = resp
1571        .headers()
1572        .get("content-type")
1573        .and_then(|v| v.to_str().ok())
1574        .unwrap_or("application/octet-stream");
1575    let content_type = super::ContentType::from(content_type);
1576
1577    if !status.is_client_error() && !status.is_server_error() {
1578        let content = resp.text().await?;
1579        match content_type {
1580            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1581            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetPortfolioMarginAssetLeverageV1RespItem&gt;`"))),
1582            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::GetPortfolioMarginAssetLeverageV1RespItem&gt;`")))),
1583        }
1584    } else {
1585        let content = resp.text().await?;
1586        let entity: Option<GetPortfolioMarginAssetLeverageV1Error> = serde_json::from_str(&content).ok();
1587        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1588    }
1589}
1590
1591/// Query repay history of pmloan for portfolio margin pro.
1592pub async fn get_portfolio_pm_loan_history_v1(configuration: &configuration::Configuration, params: GetPortfolioPmLoanHistoryV1Params) -> Result<models::GetPortfolioPmLoanHistoryV1Resp, Error<GetPortfolioPmLoanHistoryV1Error>> {
1593
1594    let uri_str = format!("{}/sapi/v1/portfolio/pmLoan-history", configuration.base_path);
1595    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1596
1597    // Create a mutable vector for query parameters
1598    let mut query_params: Vec<(String, String)> = Vec::new();
1599
1600    if let Some(ref param_value) = params.start_time {
1601        query_params.push(("startTime".to_string(), param_value.to_string()));
1602    }
1603    if let Some(ref param_value) = params.end_time {
1604        query_params.push(("endTime".to_string(), param_value.to_string()));
1605    }
1606    if let Some(ref param_value) = params.current {
1607        query_params.push(("current".to_string(), param_value.to_string()));
1608    }
1609    if let Some(ref param_value) = params.size {
1610        query_params.push(("size".to_string(), param_value.to_string()));
1611    }
1612    if let Some(ref param_value) = params.recv_window {
1613        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1614    }
1615    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1616
1617    // Create header parameters collection
1618    let mut header_params = std::collections::HashMap::new();
1619
1620    // Handle Binance Auth first if configured
1621    if let Some(ref binance_auth) = configuration.binance_auth {
1622        // Add API key to headers
1623        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1624        
1625        // Generate request body for signing (if any)
1626        let body_string: Option<Vec<u8>> = None;
1627        
1628        // Sign the request
1629        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1630            Ok(sig) => sig,
1631            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1632        };
1633        
1634        // Add signature to query params
1635        query_params.push(("signature".to_string(), signature));
1636    }
1637
1638    // Apply all query parameters
1639    if !query_params.is_empty() {
1640        req_builder = req_builder.query(&query_params);
1641    }
1642
1643
1644    // Add user agent if configured
1645    if let Some(ref user_agent) = configuration.user_agent {
1646        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1647    }
1648
1649    // Apply all header parameters
1650    for (header_name, header_value) in header_params {
1651        req_builder = req_builder.header(&header_name, &header_value);
1652    }
1653
1654
1655    let req = req_builder.build()?;
1656    let resp = configuration.client.execute(req).await?;
1657
1658    let status = resp.status();
1659    let content_type = resp
1660        .headers()
1661        .get("content-type")
1662        .and_then(|v| v.to_str().ok())
1663        .unwrap_or("application/octet-stream");
1664    let content_type = super::ContentType::from(content_type);
1665
1666    if !status.is_client_error() && !status.is_server_error() {
1667        let content = resp.text().await?;
1668        match content_type {
1669            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1670            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPortfolioPmLoanHistoryV1Resp`"))),
1671            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::GetPortfolioPmLoanHistoryV1Resp`")))),
1672        }
1673    } else {
1674        let content = resp.text().await?;
1675        let entity: Option<GetPortfolioPmLoanHistoryV1Error> = serde_json::from_str(&content).ok();
1676        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1677    }
1678}
1679
1680/// Query Portfolio Margin Pro Bankruptcy Loan Amount
1681pub async fn get_portfolio_pm_loan_v1(configuration: &configuration::Configuration, params: GetPortfolioPmLoanV1Params) -> Result<models::GetPortfolioPmLoanV1Resp, Error<GetPortfolioPmLoanV1Error>> {
1682
1683    let uri_str = format!("{}/sapi/v1/portfolio/pmLoan", configuration.base_path);
1684    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1685
1686    // Create a mutable vector for query parameters
1687    let mut query_params: Vec<(String, String)> = Vec::new();
1688
1689    if let Some(ref param_value) = params.recv_window {
1690        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1691    }
1692    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1693
1694    // Create header parameters collection
1695    let mut header_params = std::collections::HashMap::new();
1696
1697    // Handle Binance Auth first if configured
1698    if let Some(ref binance_auth) = configuration.binance_auth {
1699        // Add API key to headers
1700        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1701        
1702        // Generate request body for signing (if any)
1703        let body_string: Option<Vec<u8>> = None;
1704        
1705        // Sign the request
1706        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1707            Ok(sig) => sig,
1708            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1709        };
1710        
1711        // Add signature to query params
1712        query_params.push(("signature".to_string(), signature));
1713    }
1714
1715    // Apply all query parameters
1716    if !query_params.is_empty() {
1717        req_builder = req_builder.query(&query_params);
1718    }
1719
1720
1721    // Add user agent if configured
1722    if let Some(ref user_agent) = configuration.user_agent {
1723        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1724    }
1725
1726    // Apply all header parameters
1727    for (header_name, header_value) in header_params {
1728        req_builder = req_builder.header(&header_name, &header_value);
1729    }
1730
1731
1732    let req = req_builder.build()?;
1733    let resp = configuration.client.execute(req).await?;
1734
1735    let status = resp.status();
1736    let content_type = resp
1737        .headers()
1738        .get("content-type")
1739        .and_then(|v| v.to_str().ok())
1740        .unwrap_or("application/octet-stream");
1741    let content_type = super::ContentType::from(content_type);
1742
1743    if !status.is_client_error() && !status.is_server_error() {
1744        let content = resp.text().await?;
1745        match content_type {
1746            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1747            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPortfolioPmLoanV1Resp`"))),
1748            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::GetPortfolioPmLoanV1Resp`")))),
1749        }
1750    } else {
1751        let content = resp.text().await?;
1752        let entity: Option<GetPortfolioPmLoanV1Error> = serde_json::from_str(&content).ok();
1753        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1754    }
1755}
1756
1757/// Query Auto-repay-futures Status
1758pub async fn get_portfolio_repay_futures_switch_v1(configuration: &configuration::Configuration, params: GetPortfolioRepayFuturesSwitchV1Params) -> Result<models::GetPortfolioRepayFuturesSwitchV1Resp, Error<GetPortfolioRepayFuturesSwitchV1Error>> {
1759
1760    let uri_str = format!("{}/sapi/v1/portfolio/repay-futures-switch", configuration.base_path);
1761    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1762
1763    // Create a mutable vector for query parameters
1764    let mut query_params: Vec<(String, String)> = Vec::new();
1765
1766    if let Some(ref param_value) = params.recv_window {
1767        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1768    }
1769    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1770
1771    // Create header parameters collection
1772    let mut header_params = std::collections::HashMap::new();
1773
1774    // Handle Binance Auth first if configured
1775    if let Some(ref binance_auth) = configuration.binance_auth {
1776        // Add API key to headers
1777        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1778        
1779        // Generate request body for signing (if any)
1780        let body_string: Option<Vec<u8>> = None;
1781        
1782        // Sign the request
1783        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1784            Ok(sig) => sig,
1785            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1786        };
1787        
1788        // Add signature to query params
1789        query_params.push(("signature".to_string(), signature));
1790    }
1791
1792    // Apply all query parameters
1793    if !query_params.is_empty() {
1794        req_builder = req_builder.query(&query_params);
1795    }
1796
1797
1798    // Add user agent if configured
1799    if let Some(ref user_agent) = configuration.user_agent {
1800        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1801    }
1802
1803    // Apply all header parameters
1804    for (header_name, header_value) in header_params {
1805        req_builder = req_builder.header(&header_name, &header_value);
1806    }
1807
1808
1809    let req = req_builder.build()?;
1810    let resp = configuration.client.execute(req).await?;
1811
1812    let status = resp.status();
1813    let content_type = resp
1814        .headers()
1815        .get("content-type")
1816        .and_then(|v| v.to_str().ok())
1817        .unwrap_or("application/octet-stream");
1818    let content_type = super::ContentType::from(content_type);
1819
1820    if !status.is_client_error() && !status.is_server_error() {
1821        let content = resp.text().await?;
1822        match content_type {
1823            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1824            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetPortfolioRepayFuturesSwitchV1Resp`"))),
1825            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::GetPortfolioRepayFuturesSwitchV1Resp`")))),
1826        }
1827    } else {
1828        let content = resp.text().await?;
1829        let entity: Option<GetPortfolioRepayFuturesSwitchV1Error> = serde_json::from_str(&content).ok();
1830        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1831    }
1832}
1833