binance/spot/apis/
convert_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.2
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_convert_accept_quote_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct CreateConvertAcceptQuoteV1Params {
20    pub quote_id: String,
21    pub timestamp: i64,
22    pub recv_window: Option<i64>
23}
24
25/// struct for passing parameters to the method [`create_convert_get_quote_v1`]
26#[derive(Clone, Debug, Default)]
27pub struct CreateConvertGetQuoteV1Params {
28    pub from_asset: String,
29    pub timestamp: i64,
30    pub to_asset: String,
31    pub from_amount: Option<String>,
32    pub recv_window: Option<i64>,
33    pub to_amount: Option<String>,
34    pub valid_time: Option<String>,
35    pub wallet_type: Option<String>
36}
37
38/// struct for passing parameters to the method [`create_convert_limit_cancel_order_v1`]
39#[derive(Clone, Debug, Default)]
40pub struct CreateConvertLimitCancelOrderV1Params {
41    pub order_id: i64,
42    pub timestamp: i64,
43    pub recv_window: Option<i64>
44}
45
46/// struct for passing parameters to the method [`create_convert_limit_place_order_v1`]
47#[derive(Clone, Debug, Default)]
48pub struct CreateConvertLimitPlaceOrderV1Params {
49    pub base_asset: String,
50    pub expired_type: String,
51    pub limit_price: String,
52    pub quote_asset: String,
53    pub side: String,
54    pub timestamp: i64,
55    pub base_amount: Option<String>,
56    pub quote_amount: Option<String>,
57    pub recv_window: Option<i64>,
58    pub wallet_type: Option<String>
59}
60
61/// struct for passing parameters to the method [`create_convert_limit_query_open_orders_v1`]
62#[derive(Clone, Debug, Default)]
63pub struct CreateConvertLimitQueryOpenOrdersV1Params {
64    pub timestamp: i64,
65    pub recv_window: Option<i64>
66}
67
68/// struct for passing parameters to the method [`get_convert_asset_info_v1`]
69#[derive(Clone, Debug, Default)]
70pub struct GetConvertAssetInfoV1Params {
71    pub timestamp: i64,
72    /// The value cannot be greater than 60000
73    pub recv_window: Option<i64>
74}
75
76/// struct for passing parameters to the method [`get_convert_exchange_info_v1`]
77#[derive(Clone, Debug, Default)]
78pub struct GetConvertExchangeInfoV1Params {
79    /// User spends coin
80    pub from_asset: Option<String>,
81    /// User receives coin
82    pub to_asset: Option<String>
83}
84
85/// struct for passing parameters to the method [`get_convert_order_status_v1`]
86#[derive(Clone, Debug, Default)]
87pub struct GetConvertOrderStatusV1Params {
88    /// Either orderId or quoteId is required
89    pub order_id: Option<String>,
90    /// Either orderId or quoteId is required
91    pub quote_id: Option<String>
92}
93
94/// struct for passing parameters to the method [`get_convert_trade_flow_v1`]
95#[derive(Clone, Debug, Default)]
96pub struct GetConvertTradeFlowV1Params {
97    pub start_time: i64,
98    pub end_time: i64,
99    pub timestamp: i64,
100    /// Default 100, Max 1000
101    pub limit: Option<i32>,
102    pub recv_window: Option<i64>
103}
104
105
106/// struct for typed errors of method [`create_convert_accept_quote_v1`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum CreateConvertAcceptQuoteV1Error {
110    Status4XX(models::ApiError),
111    Status5XX(models::ApiError),
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`create_convert_get_quote_v1`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum CreateConvertGetQuoteV1Error {
119    Status4XX(models::ApiError),
120    Status5XX(models::ApiError),
121    UnknownValue(serde_json::Value),
122}
123
124/// struct for typed errors of method [`create_convert_limit_cancel_order_v1`]
125#[derive(Debug, Clone, Serialize, Deserialize)]
126#[serde(untagged)]
127pub enum CreateConvertLimitCancelOrderV1Error {
128    Status4XX(models::ApiError),
129    Status5XX(models::ApiError),
130    UnknownValue(serde_json::Value),
131}
132
133/// struct for typed errors of method [`create_convert_limit_place_order_v1`]
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum CreateConvertLimitPlaceOrderV1Error {
137    Status4XX(models::ApiError),
138    Status5XX(models::ApiError),
139    UnknownValue(serde_json::Value),
140}
141
142/// struct for typed errors of method [`create_convert_limit_query_open_orders_v1`]
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum CreateConvertLimitQueryOpenOrdersV1Error {
146    Status4XX(models::ApiError),
147    Status5XX(models::ApiError),
148    UnknownValue(serde_json::Value),
149}
150
151/// struct for typed errors of method [`get_convert_asset_info_v1`]
152#[derive(Debug, Clone, Serialize, Deserialize)]
153#[serde(untagged)]
154pub enum GetConvertAssetInfoV1Error {
155    Status4XX(models::ApiError),
156    Status5XX(models::ApiError),
157    UnknownValue(serde_json::Value),
158}
159
160/// struct for typed errors of method [`get_convert_exchange_info_v1`]
161#[derive(Debug, Clone, Serialize, Deserialize)]
162#[serde(untagged)]
163pub enum GetConvertExchangeInfoV1Error {
164    Status4XX(models::ApiError),
165    Status5XX(models::ApiError),
166    UnknownValue(serde_json::Value),
167}
168
169/// struct for typed errors of method [`get_convert_order_status_v1`]
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[serde(untagged)]
172pub enum GetConvertOrderStatusV1Error {
173    Status4XX(models::ApiError),
174    Status5XX(models::ApiError),
175    UnknownValue(serde_json::Value),
176}
177
178/// struct for typed errors of method [`get_convert_trade_flow_v1`]
179#[derive(Debug, Clone, Serialize, Deserialize)]
180#[serde(untagged)]
181pub enum GetConvertTradeFlowV1Error {
182    Status4XX(models::ApiError),
183    Status5XX(models::ApiError),
184    UnknownValue(serde_json::Value),
185}
186
187
188/// Accept the offered quote by quote ID.
189pub async fn create_convert_accept_quote_v1(configuration: &configuration::Configuration, params: CreateConvertAcceptQuoteV1Params) -> Result<models::CreateConvertAcceptQuoteV1Resp, Error<CreateConvertAcceptQuoteV1Error>> {
190
191    let uri_str = format!("{}/sapi/v1/convert/acceptQuote", configuration.base_path);
192    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
193
194    // Create a mutable vector for query parameters
195    let mut query_params: Vec<(String, String)> = Vec::new();
196
197
198    // Create header parameters collection
199    let mut header_params = std::collections::HashMap::new();
200
201    // Handle Binance Auth first if configured
202    if let Some(ref binance_auth) = configuration.binance_auth {
203        // Add API key to headers
204        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
205        
206        // Generate request body for signing (if any)
207        let body_string: Option<Vec<u8>> = None;
208        
209        // Sign the request
210        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
211            Ok(sig) => sig,
212            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
213        };
214        
215        // Add signature to query params
216        query_params.push(("signature".to_string(), signature));
217    }
218
219    // Apply all query parameters
220    if !query_params.is_empty() {
221        req_builder = req_builder.query(&query_params);
222    }
223
224
225    // Add user agent if configured
226    if let Some(ref user_agent) = configuration.user_agent {
227        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228    }
229
230    // Apply all header parameters
231    for (header_name, header_value) in header_params {
232        req_builder = req_builder.header(&header_name, &header_value);
233    }
234
235    let mut multipart_form_params = std::collections::HashMap::new();
236    multipart_form_params.insert("quoteId", params.quote_id.to_string());
237    if let Some(param_value) = params.recv_window {
238        multipart_form_params.insert("recvWindow", param_value.to_string());
239    }
240    multipart_form_params.insert("timestamp", params.timestamp.to_string());
241    req_builder = req_builder.form(&multipart_form_params);
242
243    let req = req_builder.build()?;
244    let resp = configuration.client.execute(req).await?;
245
246    let status = resp.status();
247    let content_type = resp
248        .headers()
249        .get("content-type")
250        .and_then(|v| v.to_str().ok())
251        .unwrap_or("application/octet-stream");
252    let content_type = super::ContentType::from(content_type);
253
254    if !status.is_client_error() && !status.is_server_error() {
255        let content = resp.text().await?;
256        match content_type {
257            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
258            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateConvertAcceptQuoteV1Resp`"))),
259            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::CreateConvertAcceptQuoteV1Resp`")))),
260        }
261    } else {
262        let content = resp.text().await?;
263        let entity: Option<CreateConvertAcceptQuoteV1Error> = serde_json::from_str(&content).ok();
264        Err(Error::ResponseError(ResponseContent { status, content, entity }))
265    }
266}
267
268/// Request a quote for the requested token pairs
269pub async fn create_convert_get_quote_v1(configuration: &configuration::Configuration, params: CreateConvertGetQuoteV1Params) -> Result<models::CreateConvertGetQuoteV1Resp, Error<CreateConvertGetQuoteV1Error>> {
270
271    let uri_str = format!("{}/sapi/v1/convert/getQuote", configuration.base_path);
272    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
273
274    // Create a mutable vector for query parameters
275    let mut query_params: Vec<(String, String)> = Vec::new();
276
277
278    // Create header parameters collection
279    let mut header_params = std::collections::HashMap::new();
280
281    // Handle Binance Auth first if configured
282    if let Some(ref binance_auth) = configuration.binance_auth {
283        // Add API key to headers
284        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
285        
286        // Generate request body for signing (if any)
287        let body_string: Option<Vec<u8>> = None;
288        
289        // Sign the request
290        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
291            Ok(sig) => sig,
292            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
293        };
294        
295        // Add signature to query params
296        query_params.push(("signature".to_string(), signature));
297    }
298
299    // Apply all query parameters
300    if !query_params.is_empty() {
301        req_builder = req_builder.query(&query_params);
302    }
303
304
305    // Add user agent if configured
306    if let Some(ref user_agent) = configuration.user_agent {
307        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
308    }
309
310    // Apply all header parameters
311    for (header_name, header_value) in header_params {
312        req_builder = req_builder.header(&header_name, &header_value);
313    }
314
315    let mut multipart_form_params = std::collections::HashMap::new();
316    if let Some(param_value) = params.from_amount {
317        multipart_form_params.insert("fromAmount", param_value.to_string());
318    }
319    multipart_form_params.insert("fromAsset", params.from_asset.to_string());
320    if let Some(param_value) = params.recv_window {
321        multipart_form_params.insert("recvWindow", param_value.to_string());
322    }
323    multipart_form_params.insert("timestamp", params.timestamp.to_string());
324    if let Some(param_value) = params.to_amount {
325        multipart_form_params.insert("toAmount", param_value.to_string());
326    }
327    multipart_form_params.insert("toAsset", params.to_asset.to_string());
328    if let Some(param_value) = params.valid_time {
329        multipart_form_params.insert("validTime", param_value.to_string());
330    }
331    if let Some(param_value) = params.wallet_type {
332        multipart_form_params.insert("walletType", param_value.to_string());
333    }
334    req_builder = req_builder.form(&multipart_form_params);
335
336    let req = req_builder.build()?;
337    let resp = configuration.client.execute(req).await?;
338
339    let status = resp.status();
340    let content_type = resp
341        .headers()
342        .get("content-type")
343        .and_then(|v| v.to_str().ok())
344        .unwrap_or("application/octet-stream");
345    let content_type = super::ContentType::from(content_type);
346
347    if !status.is_client_error() && !status.is_server_error() {
348        let content = resp.text().await?;
349        match content_type {
350            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
351            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateConvertGetQuoteV1Resp`"))),
352            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::CreateConvertGetQuoteV1Resp`")))),
353        }
354    } else {
355        let content = resp.text().await?;
356        let entity: Option<CreateConvertGetQuoteV1Error> = serde_json::from_str(&content).ok();
357        Err(Error::ResponseError(ResponseContent { status, content, entity }))
358    }
359}
360
361/// Enable users to cancel a limit order
362pub async fn create_convert_limit_cancel_order_v1(configuration: &configuration::Configuration, params: CreateConvertLimitCancelOrderV1Params) -> Result<models::CreateConvertLimitCancelOrderV1Resp, Error<CreateConvertLimitCancelOrderV1Error>> {
363
364    let uri_str = format!("{}/sapi/v1/convert/limit/cancelOrder", configuration.base_path);
365    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
366
367    // Create a mutable vector for query parameters
368    let mut query_params: Vec<(String, String)> = Vec::new();
369
370
371    // Create header parameters collection
372    let mut header_params = std::collections::HashMap::new();
373
374    // Handle Binance Auth first if configured
375    if let Some(ref binance_auth) = configuration.binance_auth {
376        // Add API key to headers
377        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
378        
379        // Generate request body for signing (if any)
380        let body_string: Option<Vec<u8>> = None;
381        
382        // Sign the request
383        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
384            Ok(sig) => sig,
385            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
386        };
387        
388        // Add signature to query params
389        query_params.push(("signature".to_string(), signature));
390    }
391
392    // Apply all query parameters
393    if !query_params.is_empty() {
394        req_builder = req_builder.query(&query_params);
395    }
396
397
398    // Add user agent if configured
399    if let Some(ref user_agent) = configuration.user_agent {
400        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
401    }
402
403    // Apply all header parameters
404    for (header_name, header_value) in header_params {
405        req_builder = req_builder.header(&header_name, &header_value);
406    }
407
408    let mut multipart_form_params = std::collections::HashMap::new();
409    multipart_form_params.insert("orderId", params.order_id.to_string());
410    if let Some(param_value) = params.recv_window {
411        multipart_form_params.insert("recvWindow", param_value.to_string());
412    }
413    multipart_form_params.insert("timestamp", params.timestamp.to_string());
414    req_builder = req_builder.form(&multipart_form_params);
415
416    let req = req_builder.build()?;
417    let resp = configuration.client.execute(req).await?;
418
419    let status = resp.status();
420    let content_type = resp
421        .headers()
422        .get("content-type")
423        .and_then(|v| v.to_str().ok())
424        .unwrap_or("application/octet-stream");
425    let content_type = super::ContentType::from(content_type);
426
427    if !status.is_client_error() && !status.is_server_error() {
428        let content = resp.text().await?;
429        match content_type {
430            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
431            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateConvertLimitCancelOrderV1Resp`"))),
432            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::CreateConvertLimitCancelOrderV1Resp`")))),
433        }
434    } else {
435        let content = resp.text().await?;
436        let entity: Option<CreateConvertLimitCancelOrderV1Error> = serde_json::from_str(&content).ok();
437        Err(Error::ResponseError(ResponseContent { status, content, entity }))
438    }
439}
440
441/// Enable users to place a limit order
442pub async fn create_convert_limit_place_order_v1(configuration: &configuration::Configuration, params: CreateConvertLimitPlaceOrderV1Params) -> Result<models::CreateConvertLimitPlaceOrderV1Resp, Error<CreateConvertLimitPlaceOrderV1Error>> {
443
444    let uri_str = format!("{}/sapi/v1/convert/limit/placeOrder", configuration.base_path);
445    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
446
447    // Create a mutable vector for query parameters
448    let mut query_params: Vec<(String, String)> = Vec::new();
449
450
451    // Create header parameters collection
452    let mut header_params = std::collections::HashMap::new();
453
454    // Handle Binance Auth first if configured
455    if let Some(ref binance_auth) = configuration.binance_auth {
456        // Add API key to headers
457        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
458        
459        // Generate request body for signing (if any)
460        let body_string: Option<Vec<u8>> = None;
461        
462        // Sign the request
463        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
464            Ok(sig) => sig,
465            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
466        };
467        
468        // Add signature to query params
469        query_params.push(("signature".to_string(), signature));
470    }
471
472    // Apply all query parameters
473    if !query_params.is_empty() {
474        req_builder = req_builder.query(&query_params);
475    }
476
477
478    // Add user agent if configured
479    if let Some(ref user_agent) = configuration.user_agent {
480        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
481    }
482
483    // Apply all header parameters
484    for (header_name, header_value) in header_params {
485        req_builder = req_builder.header(&header_name, &header_value);
486    }
487
488    let mut multipart_form_params = std::collections::HashMap::new();
489    if let Some(param_value) = params.base_amount {
490        multipart_form_params.insert("baseAmount", param_value.to_string());
491    }
492    multipart_form_params.insert("baseAsset", params.base_asset.to_string());
493    multipart_form_params.insert("expiredType", params.expired_type.to_string());
494    multipart_form_params.insert("limitPrice", params.limit_price.to_string());
495    if let Some(param_value) = params.quote_amount {
496        multipart_form_params.insert("quoteAmount", param_value.to_string());
497    }
498    multipart_form_params.insert("quoteAsset", params.quote_asset.to_string());
499    if let Some(param_value) = params.recv_window {
500        multipart_form_params.insert("recvWindow", param_value.to_string());
501    }
502    multipart_form_params.insert("side", params.side.to_string());
503    multipart_form_params.insert("timestamp", params.timestamp.to_string());
504    if let Some(param_value) = params.wallet_type {
505        multipart_form_params.insert("walletType", param_value.to_string());
506    }
507    req_builder = req_builder.form(&multipart_form_params);
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::CreateConvertLimitPlaceOrderV1Resp`"))),
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::CreateConvertLimitPlaceOrderV1Resp`")))),
526        }
527    } else {
528        let content = resp.text().await?;
529        let entity: Option<CreateConvertLimitPlaceOrderV1Error> = serde_json::from_str(&content).ok();
530        Err(Error::ResponseError(ResponseContent { status, content, entity }))
531    }
532}
533
534/// Request a quote for the requested token pairs
535pub async fn create_convert_limit_query_open_orders_v1(configuration: &configuration::Configuration, params: CreateConvertLimitQueryOpenOrdersV1Params) -> Result<models::CreateConvertLimitQueryOpenOrdersV1Resp, Error<CreateConvertLimitQueryOpenOrdersV1Error>> {
536
537    let uri_str = format!("{}/sapi/v1/convert/limit/queryOpenOrders", configuration.base_path);
538    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
539
540    // Create a mutable vector for query parameters
541    let mut query_params: Vec<(String, String)> = Vec::new();
542
543
544    // Create header parameters collection
545    let mut header_params = std::collections::HashMap::new();
546
547    // Handle Binance Auth first if configured
548    if let Some(ref binance_auth) = configuration.binance_auth {
549        // Add API key to headers
550        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
551        
552        // Generate request body for signing (if any)
553        let body_string: Option<Vec<u8>> = None;
554        
555        // Sign the request
556        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
557            Ok(sig) => sig,
558            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
559        };
560        
561        // Add signature to query params
562        query_params.push(("signature".to_string(), signature));
563    }
564
565    // Apply all query parameters
566    if !query_params.is_empty() {
567        req_builder = req_builder.query(&query_params);
568    }
569
570
571    // Add user agent if configured
572    if let Some(ref user_agent) = configuration.user_agent {
573        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
574    }
575
576    // Apply all header parameters
577    for (header_name, header_value) in header_params {
578        req_builder = req_builder.header(&header_name, &header_value);
579    }
580
581    let mut multipart_form_params = std::collections::HashMap::new();
582    if let Some(param_value) = params.recv_window {
583        multipart_form_params.insert("recvWindow", param_value.to_string());
584    }
585    multipart_form_params.insert("timestamp", params.timestamp.to_string());
586    req_builder = req_builder.form(&multipart_form_params);
587
588    let req = req_builder.build()?;
589    let resp = configuration.client.execute(req).await?;
590
591    let status = resp.status();
592    let content_type = resp
593        .headers()
594        .get("content-type")
595        .and_then(|v| v.to_str().ok())
596        .unwrap_or("application/octet-stream");
597    let content_type = super::ContentType::from(content_type);
598
599    if !status.is_client_error() && !status.is_server_error() {
600        let content = resp.text().await?;
601        match content_type {
602            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
603            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateConvertLimitQueryOpenOrdersV1Resp`"))),
604            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::CreateConvertLimitQueryOpenOrdersV1Resp`")))),
605        }
606    } else {
607        let content = resp.text().await?;
608        let entity: Option<CreateConvertLimitQueryOpenOrdersV1Error> = serde_json::from_str(&content).ok();
609        Err(Error::ResponseError(ResponseContent { status, content, entity }))
610    }
611}
612
613/// Query for supported asset’s precision information
614pub async fn get_convert_asset_info_v1(configuration: &configuration::Configuration, params: GetConvertAssetInfoV1Params) -> Result<Vec<models::GetConvertAssetInfoV1RespItem>, Error<GetConvertAssetInfoV1Error>> {
615
616    let uri_str = format!("{}/sapi/v1/convert/assetInfo", configuration.base_path);
617    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
618
619    // Create a mutable vector for query parameters
620    let mut query_params: Vec<(String, String)> = Vec::new();
621
622    if let Some(ref param_value) = params.recv_window {
623        query_params.push(("recvWindow".to_string(), param_value.to_string()));
624    }
625    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
626
627    // Create header parameters collection
628    let mut header_params = std::collections::HashMap::new();
629
630    // Handle Binance Auth first if configured
631    if let Some(ref binance_auth) = configuration.binance_auth {
632        // Add API key to headers
633        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
634        
635        // Generate request body for signing (if any)
636        let body_string: Option<Vec<u8>> = None;
637        
638        // Sign the request
639        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
640            Ok(sig) => sig,
641            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
642        };
643        
644        // Add signature to query params
645        query_params.push(("signature".to_string(), signature));
646    }
647
648    // Apply all query parameters
649    if !query_params.is_empty() {
650        req_builder = req_builder.query(&query_params);
651    }
652
653
654    // Add user agent if configured
655    if let Some(ref user_agent) = configuration.user_agent {
656        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
657    }
658
659    // Apply all header parameters
660    for (header_name, header_value) in header_params {
661        req_builder = req_builder.header(&header_name, &header_value);
662    }
663
664
665    let req = req_builder.build()?;
666    let resp = configuration.client.execute(req).await?;
667
668    let status = resp.status();
669    let content_type = resp
670        .headers()
671        .get("content-type")
672        .and_then(|v| v.to_str().ok())
673        .unwrap_or("application/octet-stream");
674    let content_type = super::ContentType::from(content_type);
675
676    if !status.is_client_error() && !status.is_server_error() {
677        let content = resp.text().await?;
678        match content_type {
679            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
680            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetConvertAssetInfoV1RespItem&gt;`"))),
681            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::GetConvertAssetInfoV1RespItem&gt;`")))),
682        }
683    } else {
684        let content = resp.text().await?;
685        let entity: Option<GetConvertAssetInfoV1Error> = serde_json::from_str(&content).ok();
686        Err(Error::ResponseError(ResponseContent { status, content, entity }))
687    }
688}
689
690/// Query for all convertible token pairs and the tokens’ respective upper/lower limits
691pub async fn get_convert_exchange_info_v1(configuration: &configuration::Configuration, params: GetConvertExchangeInfoV1Params) -> Result<Vec<models::GetConvertExchangeInfoV1RespItem>, Error<GetConvertExchangeInfoV1Error>> {
692
693    let uri_str = format!("{}/sapi/v1/convert/exchangeInfo", configuration.base_path);
694    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
695
696    // Create a mutable vector for query parameters
697    let mut query_params: Vec<(String, String)> = Vec::new();
698
699    if let Some(ref param_value) = params.from_asset {
700        query_params.push(("fromAsset".to_string(), param_value.to_string()));
701    }
702    if let Some(ref param_value) = params.to_asset {
703        query_params.push(("toAsset".to_string(), param_value.to_string()));
704    }
705
706    // Create header parameters collection
707    let mut header_params = std::collections::HashMap::new();
708
709    // Handle Binance Auth first if configured
710    if let Some(ref binance_auth) = configuration.binance_auth {
711        // Add API key to headers
712        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
713        
714        // Generate request body for signing (if any)
715        let body_string: Option<Vec<u8>> = None;
716        
717        // Sign the request
718        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
719            Ok(sig) => sig,
720            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
721        };
722        
723        // Add signature to query params
724        query_params.push(("signature".to_string(), signature));
725    }
726
727    // Apply all query parameters
728    if !query_params.is_empty() {
729        req_builder = req_builder.query(&query_params);
730    }
731
732
733    // Add user agent if configured
734    if let Some(ref user_agent) = configuration.user_agent {
735        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
736    }
737
738    // Apply all header parameters
739    for (header_name, header_value) in header_params {
740        req_builder = req_builder.header(&header_name, &header_value);
741    }
742
743
744    let req = req_builder.build()?;
745    let resp = configuration.client.execute(req).await?;
746
747    let status = resp.status();
748    let content_type = resp
749        .headers()
750        .get("content-type")
751        .and_then(|v| v.to_str().ok())
752        .unwrap_or("application/octet-stream");
753    let content_type = super::ContentType::from(content_type);
754
755    if !status.is_client_error() && !status.is_server_error() {
756        let content = resp.text().await?;
757        match content_type {
758            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
759            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetConvertExchangeInfoV1RespItem&gt;`"))),
760            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::GetConvertExchangeInfoV1RespItem&gt;`")))),
761        }
762    } else {
763        let content = resp.text().await?;
764        let entity: Option<GetConvertExchangeInfoV1Error> = serde_json::from_str(&content).ok();
765        Err(Error::ResponseError(ResponseContent { status, content, entity }))
766    }
767}
768
769/// Query order status by order ID.
770pub async fn get_convert_order_status_v1(configuration: &configuration::Configuration, params: GetConvertOrderStatusV1Params) -> Result<models::GetConvertOrderStatusV1Resp, Error<GetConvertOrderStatusV1Error>> {
771
772    let uri_str = format!("{}/sapi/v1/convert/orderStatus", configuration.base_path);
773    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
774
775    // Create a mutable vector for query parameters
776    let mut query_params: Vec<(String, String)> = Vec::new();
777
778    if let Some(ref param_value) = params.order_id {
779        query_params.push(("orderId".to_string(), param_value.to_string()));
780    }
781    if let Some(ref param_value) = params.quote_id {
782        query_params.push(("quoteId".to_string(), param_value.to_string()));
783    }
784
785    // Create header parameters collection
786    let mut header_params = std::collections::HashMap::new();
787
788    // Handle Binance Auth first if configured
789    if let Some(ref binance_auth) = configuration.binance_auth {
790        // Add API key to headers
791        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
792        
793        // Generate request body for signing (if any)
794        let body_string: Option<Vec<u8>> = None;
795        
796        // Sign the request
797        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
798            Ok(sig) => sig,
799            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
800        };
801        
802        // Add signature to query params
803        query_params.push(("signature".to_string(), signature));
804    }
805
806    // Apply all query parameters
807    if !query_params.is_empty() {
808        req_builder = req_builder.query(&query_params);
809    }
810
811
812    // Add user agent if configured
813    if let Some(ref user_agent) = configuration.user_agent {
814        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
815    }
816
817    // Apply all header parameters
818    for (header_name, header_value) in header_params {
819        req_builder = req_builder.header(&header_name, &header_value);
820    }
821
822
823    let req = req_builder.build()?;
824    let resp = configuration.client.execute(req).await?;
825
826    let status = resp.status();
827    let content_type = resp
828        .headers()
829        .get("content-type")
830        .and_then(|v| v.to_str().ok())
831        .unwrap_or("application/octet-stream");
832    let content_type = super::ContentType::from(content_type);
833
834    if !status.is_client_error() && !status.is_server_error() {
835        let content = resp.text().await?;
836        match content_type {
837            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
838            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConvertOrderStatusV1Resp`"))),
839            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::GetConvertOrderStatusV1Resp`")))),
840        }
841    } else {
842        let content = resp.text().await?;
843        let entity: Option<GetConvertOrderStatusV1Error> = serde_json::from_str(&content).ok();
844        Err(Error::ResponseError(ResponseContent { status, content, entity }))
845    }
846}
847
848/// Get Convert Trade History
849pub async fn get_convert_trade_flow_v1(configuration: &configuration::Configuration, params: GetConvertTradeFlowV1Params) -> Result<models::GetConvertTradeFlowV1Resp, Error<GetConvertTradeFlowV1Error>> {
850
851    let uri_str = format!("{}/sapi/v1/convert/tradeFlow", configuration.base_path);
852    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
853
854    // Create a mutable vector for query parameters
855    let mut query_params: Vec<(String, String)> = Vec::new();
856
857    query_params.push(("startTime".to_string(), params.start_time.to_string()));
858    query_params.push(("endTime".to_string(), params.end_time.to_string()));
859    if let Some(ref param_value) = params.limit {
860        query_params.push(("limit".to_string(), param_value.to_string()));
861    }
862    if let Some(ref param_value) = params.recv_window {
863        query_params.push(("recvWindow".to_string(), param_value.to_string()));
864    }
865    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
866
867    // Create header parameters collection
868    let mut header_params = std::collections::HashMap::new();
869
870    // Handle Binance Auth first if configured
871    if let Some(ref binance_auth) = configuration.binance_auth {
872        // Add API key to headers
873        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
874        
875        // Generate request body for signing (if any)
876        let body_string: Option<Vec<u8>> = None;
877        
878        // Sign the request
879        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
880            Ok(sig) => sig,
881            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
882        };
883        
884        // Add signature to query params
885        query_params.push(("signature".to_string(), signature));
886    }
887
888    // Apply all query parameters
889    if !query_params.is_empty() {
890        req_builder = req_builder.query(&query_params);
891    }
892
893
894    // Add user agent if configured
895    if let Some(ref user_agent) = configuration.user_agent {
896        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
897    }
898
899    // Apply all header parameters
900    for (header_name, header_value) in header_params {
901        req_builder = req_builder.header(&header_name, &header_value);
902    }
903
904
905    let req = req_builder.build()?;
906    let resp = configuration.client.execute(req).await?;
907
908    let status = resp.status();
909    let content_type = resp
910        .headers()
911        .get("content-type")
912        .and_then(|v| v.to_str().ok())
913        .unwrap_or("application/octet-stream");
914    let content_type = super::ContentType::from(content_type);
915
916    if !status.is_client_error() && !status.is_server_error() {
917        let content = resp.text().await?;
918        match content_type {
919            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
920            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConvertTradeFlowV1Resp`"))),
921            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::GetConvertTradeFlowV1Resp`")))),
922        }
923    } else {
924        let content = resp.text().await?;
925        let entity: Option<GetConvertTradeFlowV1Error> = serde_json::from_str(&content).ok();
926        Err(Error::ResponseError(ResponseContent { status, content, entity }))
927    }
928}
929