binance/derivatives/options/apis/
trade_api.rs

1/*
2 * Binance Options API
3 *
4 * OpenAPI specification for Binance exchange - Options API
5 *
6 * The version of the OpenAPI document: 0.1.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::derivatives::options::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`options_create_batch_orders_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct OptionsCreateBatchOrdersV1Params {
20    pub orders: Vec<models::OptionsCreateBatchOrdersV1ReqOrdersItem>,
21    pub timestamp: i64,
22    pub recv_window: Option<i64>
23}
24
25/// struct for passing parameters to the method [`options_create_order_v1`]
26#[derive(Clone, Debug, Default)]
27pub struct OptionsCreateOrderV1Params {
28    pub quantity: String,
29    pub side: String,
30    pub symbol: String,
31    pub timestamp: i64,
32    pub r#type: String,
33    pub client_order_id: Option<String>,
34    pub is_mmp: Option<bool>,
35    pub new_order_resp_type: Option<String>,
36    pub post_only: Option<bool>,
37    pub price: Option<String>,
38    pub recv_window: Option<i64>,
39    pub reduce_only: Option<bool>,
40    pub time_in_force: Option<String>
41}
42
43/// struct for passing parameters to the method [`options_delete_all_open_orders_by_underlying_v1`]
44#[derive(Clone, Debug, Default)]
45pub struct OptionsDeleteAllOpenOrdersByUnderlyingV1Params {
46    /// Option underlying, e.g BTCUSDT
47    pub underlying: String,
48    pub timestamp: i64,
49    pub recv_window: Option<i64>
50}
51
52/// struct for passing parameters to the method [`options_delete_all_open_orders_v1`]
53#[derive(Clone, Debug, Default)]
54pub struct OptionsDeleteAllOpenOrdersV1Params {
55    /// Option trading pair, e.g BTC-200730-9000-C
56    pub symbol: String,
57    pub timestamp: i64,
58    pub recv_window: Option<i64>
59}
60
61/// struct for passing parameters to the method [`options_delete_batch_orders_v1`]
62#[derive(Clone, Debug, Default)]
63pub struct OptionsDeleteBatchOrdersV1Params {
64    /// Option trading pair, e.g BTC-200730-9000-C
65    pub symbol: String,
66    pub timestamp: i64,
67    /// Order ID, e.g [4611875134427365377,4611875134427365378]
68    pub order_ids: Option<Vec<i64>>,
69    /// User-defined order ID, e.g [&#34;my_id_1&#34;,&#34;my_id_2&#34;]
70    pub client_order_ids: Option<Vec<String>>,
71    pub recv_window: Option<i64>
72}
73
74/// struct for passing parameters to the method [`options_delete_order_v1`]
75#[derive(Clone, Debug, Default)]
76pub struct OptionsDeleteOrderV1Params {
77    /// Option trading pair, e.g BTC-200730-9000-C
78    pub symbol: String,
79    pub timestamp: i64,
80    /// Order ID, e.g 4611875134427365377
81    pub order_id: Option<i64>,
82    /// User-defined order ID, e.g 10000
83    pub client_order_id: Option<String>,
84    pub recv_window: Option<i64>
85}
86
87/// struct for passing parameters to the method [`options_get_exercise_record_v1`]
88#[derive(Clone, Debug, Default)]
89pub struct OptionsGetExerciseRecordV1Params {
90    pub timestamp: i64,
91    /// Option trading pair, e.g BTC-200730-9000-C
92    pub symbol: Option<String>,
93    /// startTime
94    pub start_time: Option<i64>,
95    /// endTime
96    pub end_time: Option<i64>,
97    /// default 1000, max 1000
98    pub limit: Option<i32>,
99    pub recv_window: Option<i64>
100}
101
102/// struct for passing parameters to the method [`options_get_history_orders_v1`]
103#[derive(Clone, Debug, Default)]
104pub struct OptionsGetHistoryOrdersV1Params {
105    /// Option trading pair
106    pub symbol: String,
107    pub timestamp: i64,
108    /// Returns the orderId and subsequent orders, the most recent order is returned by default
109    pub order_id: Option<i64>,
110    /// Start Time, e.g 1593511200000
111    pub start_time: Option<i64>,
112    /// End Time, e.g 1593512200000
113    pub end_time: Option<i64>,
114    /// Number of result sets returned Default:100 Max:1000
115    pub limit: Option<i32>,
116    pub recv_window: Option<i64>
117}
118
119/// struct for passing parameters to the method [`options_get_open_orders_v1`]
120#[derive(Clone, Debug, Default)]
121pub struct OptionsGetOpenOrdersV1Params {
122    pub timestamp: i64,
123    /// return all orders if don&#39;t pass, Option trading pair, e.g BTC-200730-9000-C,
124    pub symbol: Option<String>,
125    /// Returns the orderId and subsequent orders, the most recent order is returned by default
126    pub order_id: Option<i64>,
127    /// Start Time
128    pub start_time: Option<i64>,
129    /// End Time
130    pub end_time: Option<i64>,
131    /// Number of result sets returned Default:100 Max:1000
132    pub limit: Option<i32>,
133    pub recv_window: Option<i64>
134}
135
136/// struct for passing parameters to the method [`options_get_order_v1`]
137#[derive(Clone, Debug, Default)]
138pub struct OptionsGetOrderV1Params {
139    /// Option trading pair, e.g BTC-200730-9000-C
140    pub symbol: String,
141    pub timestamp: i64,
142    /// Order id
143    pub order_id: Option<i64>,
144    /// User-defined order ID cannot be repeated in pending orders
145    pub client_order_id: Option<String>,
146    pub recv_window: Option<i64>
147}
148
149/// struct for passing parameters to the method [`options_get_position_v1`]
150#[derive(Clone, Debug, Default)]
151pub struct OptionsGetPositionV1Params {
152    pub timestamp: i64,
153    /// Option trading pair, e.g BTC-200730-9000-C
154    pub symbol: Option<String>,
155    pub recv_window: Option<i64>
156}
157
158/// struct for passing parameters to the method [`options_get_user_trades_v1`]
159#[derive(Clone, Debug, Default)]
160pub struct OptionsGetUserTradesV1Params {
161    pub timestamp: i64,
162    /// Option symbol, e.g BTC-200730-9000-C
163    pub symbol: Option<String>,
164    /// Trade id to fetch from. Default gets most recent trades, e.g 4611875134427365376
165    pub from_id: Option<i64>,
166    /// Start time, e.g 1593511200000
167    pub start_time: Option<i64>,
168    /// End time, e.g 1593512200000
169    pub end_time: Option<i64>,
170    /// Default 100; max 1000
171    pub limit: Option<i32>,
172    pub recv_window: Option<i64>
173}
174
175
176/// struct for typed errors of method [`options_create_batch_orders_v1`]
177#[derive(Debug, Clone, Serialize, Deserialize)]
178#[serde(untagged)]
179pub enum OptionsCreateBatchOrdersV1Error {
180    Status4XX(models::ApiError),
181    Status5XX(models::ApiError),
182    UnknownValue(serde_json::Value),
183}
184
185/// struct for typed errors of method [`options_create_order_v1`]
186#[derive(Debug, Clone, Serialize, Deserialize)]
187#[serde(untagged)]
188pub enum OptionsCreateOrderV1Error {
189    Status4XX(models::ApiError),
190    Status5XX(models::ApiError),
191    UnknownValue(serde_json::Value),
192}
193
194/// struct for typed errors of method [`options_delete_all_open_orders_by_underlying_v1`]
195#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(untagged)]
197pub enum OptionsDeleteAllOpenOrdersByUnderlyingV1Error {
198    Status4XX(models::ApiError),
199    Status5XX(models::ApiError),
200    UnknownValue(serde_json::Value),
201}
202
203/// struct for typed errors of method [`options_delete_all_open_orders_v1`]
204#[derive(Debug, Clone, Serialize, Deserialize)]
205#[serde(untagged)]
206pub enum OptionsDeleteAllOpenOrdersV1Error {
207    Status4XX(models::ApiError),
208    Status5XX(models::ApiError),
209    UnknownValue(serde_json::Value),
210}
211
212/// struct for typed errors of method [`options_delete_batch_orders_v1`]
213#[derive(Debug, Clone, Serialize, Deserialize)]
214#[serde(untagged)]
215pub enum OptionsDeleteBatchOrdersV1Error {
216    Status4XX(models::ApiError),
217    Status5XX(models::ApiError),
218    UnknownValue(serde_json::Value),
219}
220
221/// struct for typed errors of method [`options_delete_order_v1`]
222#[derive(Debug, Clone, Serialize, Deserialize)]
223#[serde(untagged)]
224pub enum OptionsDeleteOrderV1Error {
225    Status4XX(models::ApiError),
226    Status5XX(models::ApiError),
227    UnknownValue(serde_json::Value),
228}
229
230/// struct for typed errors of method [`options_get_exercise_record_v1`]
231#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum OptionsGetExerciseRecordV1Error {
234    Status4XX(models::ApiError),
235    Status5XX(models::ApiError),
236    UnknownValue(serde_json::Value),
237}
238
239/// struct for typed errors of method [`options_get_history_orders_v1`]
240#[derive(Debug, Clone, Serialize, Deserialize)]
241#[serde(untagged)]
242pub enum OptionsGetHistoryOrdersV1Error {
243    Status4XX(models::ApiError),
244    Status5XX(models::ApiError),
245    UnknownValue(serde_json::Value),
246}
247
248/// struct for typed errors of method [`options_get_open_orders_v1`]
249#[derive(Debug, Clone, Serialize, Deserialize)]
250#[serde(untagged)]
251pub enum OptionsGetOpenOrdersV1Error {
252    Status4XX(models::ApiError),
253    Status5XX(models::ApiError),
254    UnknownValue(serde_json::Value),
255}
256
257/// struct for typed errors of method [`options_get_order_v1`]
258#[derive(Debug, Clone, Serialize, Deserialize)]
259#[serde(untagged)]
260pub enum OptionsGetOrderV1Error {
261    Status4XX(models::ApiError),
262    Status5XX(models::ApiError),
263    UnknownValue(serde_json::Value),
264}
265
266/// struct for typed errors of method [`options_get_position_v1`]
267#[derive(Debug, Clone, Serialize, Deserialize)]
268#[serde(untagged)]
269pub enum OptionsGetPositionV1Error {
270    Status4XX(models::ApiError),
271    Status5XX(models::ApiError),
272    UnknownValue(serde_json::Value),
273}
274
275/// struct for typed errors of method [`options_get_user_trades_v1`]
276#[derive(Debug, Clone, Serialize, Deserialize)]
277#[serde(untagged)]
278pub enum OptionsGetUserTradesV1Error {
279    Status4XX(models::ApiError),
280    Status5XX(models::ApiError),
281    UnknownValue(serde_json::Value),
282}
283
284
285/// Send multiple option orders.
286pub async fn options_create_batch_orders_v1(configuration: &configuration::Configuration, params: OptionsCreateBatchOrdersV1Params) -> Result<Vec<models::OptionsCreateBatchOrdersV1RespInner>, Error<OptionsCreateBatchOrdersV1Error>> {
287
288    let uri_str = format!("{}/eapi/v1/batchOrders", configuration.base_path);
289    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
290
291    // Create a mutable vector for query parameters
292    let mut query_params: Vec<(String, String)> = Vec::new();
293
294
295    // Create header parameters collection
296    let mut header_params = std::collections::HashMap::new();
297
298    // Handle Binance Auth first if configured
299    if let Some(ref binance_auth) = configuration.binance_auth {
300        // Add API key to headers
301        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
302        
303        // Generate request body for signing (if any)
304        let body_string: Option<Vec<u8>> = None;
305        
306        // Sign the request
307        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
308            Ok(sig) => sig,
309            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
310        };
311        
312        // Add signature to query params
313        query_params.push(("signature".to_string(), signature));
314    }
315
316    // Apply all query parameters
317    if !query_params.is_empty() {
318        req_builder = req_builder.query(&query_params);
319    }
320
321
322    // Add user agent if configured
323    if let Some(ref user_agent) = configuration.user_agent {
324        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
325    }
326
327    // Apply all header parameters
328    for (header_name, header_value) in header_params {
329        req_builder = req_builder.header(&header_name, &header_value);
330    }
331
332    let mut multipart_form_params = std::collections::HashMap::new();
333    multipart_form_params.insert("orders", params.orders.into_iter().map(|p| serde_json::to_string(&p).unwrap_or_default()).collect::<Vec<String>>().join(",").to_string());
334    if let Some(param_value) = params.recv_window {
335        multipart_form_params.insert("recvWindow", param_value.to_string());
336    }
337    multipart_form_params.insert("timestamp", params.timestamp.to_string());
338    req_builder = req_builder.form(&multipart_form_params);
339
340    let req = req_builder.build()?;
341    let resp = configuration.client.execute(req).await?;
342
343    let status = resp.status();
344    let content_type = resp
345        .headers()
346        .get("content-type")
347        .and_then(|v| v.to_str().ok())
348        .unwrap_or("application/octet-stream");
349    let content_type = super::ContentType::from(content_type);
350
351    if !status.is_client_error() && !status.is_server_error() {
352        let content = resp.text().await?;
353        match content_type {
354            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
355            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsCreateBatchOrdersV1RespInner&gt;`"))),
356            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::OptionsCreateBatchOrdersV1RespInner&gt;`")))),
357        }
358    } else {
359        let content = resp.text().await?;
360        let entity: Option<OptionsCreateBatchOrdersV1Error> = serde_json::from_str(&content).ok();
361        Err(Error::ResponseError(ResponseContent { status, content, entity }))
362    }
363}
364
365/// Send a new order.
366pub async fn options_create_order_v1(configuration: &configuration::Configuration, params: OptionsCreateOrderV1Params) -> Result<models::OptionsCreateOrderV1Resp, Error<OptionsCreateOrderV1Error>> {
367
368    let uri_str = format!("{}/eapi/v1/order", configuration.base_path);
369    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
370
371    // Create a mutable vector for query parameters
372    let mut query_params: Vec<(String, String)> = Vec::new();
373
374
375    // Create header parameters collection
376    let mut header_params = std::collections::HashMap::new();
377
378    // Handle Binance Auth first if configured
379    if let Some(ref binance_auth) = configuration.binance_auth {
380        // Add API key to headers
381        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
382        
383        // Generate request body for signing (if any)
384        let body_string: Option<Vec<u8>> = None;
385        
386        // Sign the request
387        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
388            Ok(sig) => sig,
389            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
390        };
391        
392        // Add signature to query params
393        query_params.push(("signature".to_string(), signature));
394    }
395
396    // Apply all query parameters
397    if !query_params.is_empty() {
398        req_builder = req_builder.query(&query_params);
399    }
400
401
402    // Add user agent if configured
403    if let Some(ref user_agent) = configuration.user_agent {
404        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
405    }
406
407    // Apply all header parameters
408    for (header_name, header_value) in header_params {
409        req_builder = req_builder.header(&header_name, &header_value);
410    }
411
412    let mut multipart_form_params = std::collections::HashMap::new();
413    if let Some(param_value) = params.client_order_id {
414        multipart_form_params.insert("clientOrderId", param_value.to_string());
415    }
416    if let Some(param_value) = params.is_mmp {
417        multipart_form_params.insert("isMmp", param_value.to_string());
418    }
419    if let Some(param_value) = params.new_order_resp_type {
420        multipart_form_params.insert("newOrderRespType", param_value.to_string());
421    }
422    if let Some(param_value) = params.post_only {
423        multipart_form_params.insert("postOnly", param_value.to_string());
424    }
425    if let Some(param_value) = params.price {
426        multipart_form_params.insert("price", param_value.to_string());
427    }
428    multipart_form_params.insert("quantity", params.quantity.to_string());
429    if let Some(param_value) = params.recv_window {
430        multipart_form_params.insert("recvWindow", param_value.to_string());
431    }
432    if let Some(param_value) = params.reduce_only {
433        multipart_form_params.insert("reduceOnly", param_value.to_string());
434    }
435    multipart_form_params.insert("side", params.side.to_string());
436    multipart_form_params.insert("symbol", params.symbol.to_string());
437    if let Some(param_value) = params.time_in_force {
438        multipart_form_params.insert("timeInForce", param_value.to_string());
439    }
440    multipart_form_params.insert("timestamp", params.timestamp.to_string());
441    multipart_form_params.insert("type", params.r#type.to_string());
442    req_builder = req_builder.form(&multipart_form_params);
443
444    let req = req_builder.build()?;
445    let resp = configuration.client.execute(req).await?;
446
447    let status = resp.status();
448    let content_type = resp
449        .headers()
450        .get("content-type")
451        .and_then(|v| v.to_str().ok())
452        .unwrap_or("application/octet-stream");
453    let content_type = super::ContentType::from(content_type);
454
455    if !status.is_client_error() && !status.is_server_error() {
456        let content = resp.text().await?;
457        match content_type {
458            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
459            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsCreateOrderV1Resp`"))),
460            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::OptionsCreateOrderV1Resp`")))),
461        }
462    } else {
463        let content = resp.text().await?;
464        let entity: Option<OptionsCreateOrderV1Error> = serde_json::from_str(&content).ok();
465        Err(Error::ResponseError(ResponseContent { status, content, entity }))
466    }
467}
468
469/// Cancel all active orders on specified underlying.
470pub async fn options_delete_all_open_orders_by_underlying_v1(configuration: &configuration::Configuration, params: OptionsDeleteAllOpenOrdersByUnderlyingV1Params) -> Result<models::OptionsDeleteAllOpenOrdersByUnderlyingV1Resp, Error<OptionsDeleteAllOpenOrdersByUnderlyingV1Error>> {
471
472    let uri_str = format!("{}/eapi/v1/allOpenOrdersByUnderlying", configuration.base_path);
473    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
474
475    // Create a mutable vector for query parameters
476    let mut query_params: Vec<(String, String)> = Vec::new();
477
478    query_params.push(("underlying".to_string(), params.underlying.to_string()));
479    if let Some(ref param_value) = params.recv_window {
480        query_params.push(("recvWindow".to_string(), param_value.to_string()));
481    }
482    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
483
484    // Create header parameters collection
485    let mut header_params = std::collections::HashMap::new();
486
487    // Handle Binance Auth first if configured
488    if let Some(ref binance_auth) = configuration.binance_auth {
489        // Add API key to headers
490        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
491        
492        // Generate request body for signing (if any)
493        let body_string: Option<Vec<u8>> = None;
494        
495        // Sign the request
496        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
497            Ok(sig) => sig,
498            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
499        };
500        
501        // Add signature to query params
502        query_params.push(("signature".to_string(), signature));
503    }
504
505    // Apply all query parameters
506    if !query_params.is_empty() {
507        req_builder = req_builder.query(&query_params);
508    }
509
510
511    // Add user agent if configured
512    if let Some(ref user_agent) = configuration.user_agent {
513        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
514    }
515
516    // Apply all header parameters
517    for (header_name, header_value) in header_params {
518        req_builder = req_builder.header(&header_name, &header_value);
519    }
520
521
522    let req = req_builder.build()?;
523    let resp = configuration.client.execute(req).await?;
524
525    let status = resp.status();
526    let content_type = resp
527        .headers()
528        .get("content-type")
529        .and_then(|v| v.to_str().ok())
530        .unwrap_or("application/octet-stream");
531    let content_type = super::ContentType::from(content_type);
532
533    if !status.is_client_error() && !status.is_server_error() {
534        let content = resp.text().await?;
535        match content_type {
536            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
537            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsDeleteAllOpenOrdersByUnderlyingV1Resp`"))),
538            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::OptionsDeleteAllOpenOrdersByUnderlyingV1Resp`")))),
539        }
540    } else {
541        let content = resp.text().await?;
542        let entity: Option<OptionsDeleteAllOpenOrdersByUnderlyingV1Error> = serde_json::from_str(&content).ok();
543        Err(Error::ResponseError(ResponseContent { status, content, entity }))
544    }
545}
546
547/// Cancel all active order on a symbol.
548pub async fn options_delete_all_open_orders_v1(configuration: &configuration::Configuration, params: OptionsDeleteAllOpenOrdersV1Params) -> Result<models::OptionsDeleteAllOpenOrdersV1Resp, Error<OptionsDeleteAllOpenOrdersV1Error>> {
549
550    let uri_str = format!("{}/eapi/v1/allOpenOrders", configuration.base_path);
551    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
552
553    // Create a mutable vector for query parameters
554    let mut query_params: Vec<(String, String)> = Vec::new();
555
556    query_params.push(("symbol".to_string(), params.symbol.to_string()));
557    if let Some(ref param_value) = params.recv_window {
558        query_params.push(("recvWindow".to_string(), param_value.to_string()));
559    }
560    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
561
562    // Create header parameters collection
563    let mut header_params = std::collections::HashMap::new();
564
565    // Handle Binance Auth first if configured
566    if let Some(ref binance_auth) = configuration.binance_auth {
567        // Add API key to headers
568        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
569        
570        // Generate request body for signing (if any)
571        let body_string: Option<Vec<u8>> = None;
572        
573        // Sign the request
574        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
575            Ok(sig) => sig,
576            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
577        };
578        
579        // Add signature to query params
580        query_params.push(("signature".to_string(), signature));
581    }
582
583    // Apply all query parameters
584    if !query_params.is_empty() {
585        req_builder = req_builder.query(&query_params);
586    }
587
588
589    // Add user agent if configured
590    if let Some(ref user_agent) = configuration.user_agent {
591        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
592    }
593
594    // Apply all header parameters
595    for (header_name, header_value) in header_params {
596        req_builder = req_builder.header(&header_name, &header_value);
597    }
598
599
600    let req = req_builder.build()?;
601    let resp = configuration.client.execute(req).await?;
602
603    let status = resp.status();
604    let content_type = resp
605        .headers()
606        .get("content-type")
607        .and_then(|v| v.to_str().ok())
608        .unwrap_or("application/octet-stream");
609    let content_type = super::ContentType::from(content_type);
610
611    if !status.is_client_error() && !status.is_server_error() {
612        let content = resp.text().await?;
613        match content_type {
614            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
615            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsDeleteAllOpenOrdersV1Resp`"))),
616            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::OptionsDeleteAllOpenOrdersV1Resp`")))),
617        }
618    } else {
619        let content = resp.text().await?;
620        let entity: Option<OptionsDeleteAllOpenOrdersV1Error> = serde_json::from_str(&content).ok();
621        Err(Error::ResponseError(ResponseContent { status, content, entity }))
622    }
623}
624
625/// Cancel multiple orders.
626pub async fn options_delete_batch_orders_v1(configuration: &configuration::Configuration, params: OptionsDeleteBatchOrdersV1Params) -> Result<Vec<models::OptionsDeleteBatchOrdersV1RespInner>, Error<OptionsDeleteBatchOrdersV1Error>> {
627
628    let uri_str = format!("{}/eapi/v1/batchOrders", configuration.base_path);
629    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
630
631    // Create a mutable vector for query parameters
632    let mut query_params: Vec<(String, String)> = Vec::new();
633
634    query_params.push(("symbol".to_string(), params.symbol.to_string()));
635    if let Some(ref param_value) = params.order_ids {
636        match "multi" {
637            "multi" => {
638                for p in param_value {
639                    query_params.push(("orderIds".to_string(), p.to_string()));
640                }
641            },
642            _ => {
643                let joined = param_value.iter()
644                    .map(|p| p.to_string())
645                    .collect::<Vec<String>>()
646                    .join(",");
647                query_params.push(("orderIds".to_string(), joined));
648            }
649        };
650    }
651    if let Some(ref param_value) = params.client_order_ids {
652        match "multi" {
653            "multi" => {
654                for p in param_value {
655                    query_params.push(("clientOrderIds".to_string(), p.to_string()));
656                }
657            },
658            _ => {
659                let joined = param_value.iter()
660                    .map(|p| p.to_string())
661                    .collect::<Vec<String>>()
662                    .join(",");
663                query_params.push(("clientOrderIds".to_string(), joined));
664            }
665        };
666    }
667    if let Some(ref param_value) = params.recv_window {
668        query_params.push(("recvWindow".to_string(), param_value.to_string()));
669    }
670    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
671
672    // Create header parameters collection
673    let mut header_params = std::collections::HashMap::new();
674
675    // Handle Binance Auth first if configured
676    if let Some(ref binance_auth) = configuration.binance_auth {
677        // Add API key to headers
678        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
679        
680        // Generate request body for signing (if any)
681        let body_string: Option<Vec<u8>> = None;
682        
683        // Sign the request
684        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
685            Ok(sig) => sig,
686            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
687        };
688        
689        // Add signature to query params
690        query_params.push(("signature".to_string(), signature));
691    }
692
693    // Apply all query parameters
694    if !query_params.is_empty() {
695        req_builder = req_builder.query(&query_params);
696    }
697
698
699    // Add user agent if configured
700    if let Some(ref user_agent) = configuration.user_agent {
701        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
702    }
703
704    // Apply all header parameters
705    for (header_name, header_value) in header_params {
706        req_builder = req_builder.header(&header_name, &header_value);
707    }
708
709
710    let req = req_builder.build()?;
711    let resp = configuration.client.execute(req).await?;
712
713    let status = resp.status();
714    let content_type = resp
715        .headers()
716        .get("content-type")
717        .and_then(|v| v.to_str().ok())
718        .unwrap_or("application/octet-stream");
719    let content_type = super::ContentType::from(content_type);
720
721    if !status.is_client_error() && !status.is_server_error() {
722        let content = resp.text().await?;
723        match content_type {
724            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
725            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsDeleteBatchOrdersV1RespInner&gt;`"))),
726            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::OptionsDeleteBatchOrdersV1RespInner&gt;`")))),
727        }
728    } else {
729        let content = resp.text().await?;
730        let entity: Option<OptionsDeleteBatchOrdersV1Error> = serde_json::from_str(&content).ok();
731        Err(Error::ResponseError(ResponseContent { status, content, entity }))
732    }
733}
734
735/// Cancel an active order.
736pub async fn options_delete_order_v1(configuration: &configuration::Configuration, params: OptionsDeleteOrderV1Params) -> Result<models::OptionsDeleteOrderV1Resp, Error<OptionsDeleteOrderV1Error>> {
737
738    let uri_str = format!("{}/eapi/v1/order", configuration.base_path);
739    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
740
741    // Create a mutable vector for query parameters
742    let mut query_params: Vec<(String, String)> = Vec::new();
743
744    query_params.push(("symbol".to_string(), params.symbol.to_string()));
745    if let Some(ref param_value) = params.order_id {
746        query_params.push(("orderId".to_string(), param_value.to_string()));
747    }
748    if let Some(ref param_value) = params.client_order_id {
749        query_params.push(("clientOrderId".to_string(), param_value.to_string()));
750    }
751    if let Some(ref param_value) = params.recv_window {
752        query_params.push(("recvWindow".to_string(), param_value.to_string()));
753    }
754    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
755
756    // Create header parameters collection
757    let mut header_params = std::collections::HashMap::new();
758
759    // Handle Binance Auth first if configured
760    if let Some(ref binance_auth) = configuration.binance_auth {
761        // Add API key to headers
762        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
763        
764        // Generate request body for signing (if any)
765        let body_string: Option<Vec<u8>> = None;
766        
767        // Sign the request
768        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
769            Ok(sig) => sig,
770            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
771        };
772        
773        // Add signature to query params
774        query_params.push(("signature".to_string(), signature));
775    }
776
777    // Apply all query parameters
778    if !query_params.is_empty() {
779        req_builder = req_builder.query(&query_params);
780    }
781
782
783    // Add user agent if configured
784    if let Some(ref user_agent) = configuration.user_agent {
785        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
786    }
787
788    // Apply all header parameters
789    for (header_name, header_value) in header_params {
790        req_builder = req_builder.header(&header_name, &header_value);
791    }
792
793
794    let req = req_builder.build()?;
795    let resp = configuration.client.execute(req).await?;
796
797    let status = resp.status();
798    let content_type = resp
799        .headers()
800        .get("content-type")
801        .and_then(|v| v.to_str().ok())
802        .unwrap_or("application/octet-stream");
803    let content_type = super::ContentType::from(content_type);
804
805    if !status.is_client_error() && !status.is_server_error() {
806        let content = resp.text().await?;
807        match content_type {
808            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
809            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsDeleteOrderV1Resp`"))),
810            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::OptionsDeleteOrderV1Resp`")))),
811        }
812    } else {
813        let content = resp.text().await?;
814        let entity: Option<OptionsDeleteOrderV1Error> = serde_json::from_str(&content).ok();
815        Err(Error::ResponseError(ResponseContent { status, content, entity }))
816    }
817}
818
819/// Get account exercise records.
820pub async fn options_get_exercise_record_v1(configuration: &configuration::Configuration, params: OptionsGetExerciseRecordV1Params) -> Result<Vec<models::OptionsGetExerciseRecordV1RespItem>, Error<OptionsGetExerciseRecordV1Error>> {
821
822    let uri_str = format!("{}/eapi/v1/exerciseRecord", configuration.base_path);
823    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
824
825    // Create a mutable vector for query parameters
826    let mut query_params: Vec<(String, String)> = Vec::new();
827
828    if let Some(ref param_value) = params.symbol {
829        query_params.push(("symbol".to_string(), param_value.to_string()));
830    }
831    if let Some(ref param_value) = params.start_time {
832        query_params.push(("startTime".to_string(), param_value.to_string()));
833    }
834    if let Some(ref param_value) = params.end_time {
835        query_params.push(("endTime".to_string(), param_value.to_string()));
836    }
837    if let Some(ref param_value) = params.limit {
838        query_params.push(("limit".to_string(), param_value.to_string()));
839    }
840    if let Some(ref param_value) = params.recv_window {
841        query_params.push(("recvWindow".to_string(), param_value.to_string()));
842    }
843    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
844
845    // Create header parameters collection
846    let mut header_params = std::collections::HashMap::new();
847
848    // Handle Binance Auth first if configured
849    if let Some(ref binance_auth) = configuration.binance_auth {
850        // Add API key to headers
851        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
852        
853        // Generate request body for signing (if any)
854        let body_string: Option<Vec<u8>> = None;
855        
856        // Sign the request
857        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
858            Ok(sig) => sig,
859            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
860        };
861        
862        // Add signature to query params
863        query_params.push(("signature".to_string(), signature));
864    }
865
866    // Apply all query parameters
867    if !query_params.is_empty() {
868        req_builder = req_builder.query(&query_params);
869    }
870
871
872    // Add user agent if configured
873    if let Some(ref user_agent) = configuration.user_agent {
874        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
875    }
876
877    // Apply all header parameters
878    for (header_name, header_value) in header_params {
879        req_builder = req_builder.header(&header_name, &header_value);
880    }
881
882
883    let req = req_builder.build()?;
884    let resp = configuration.client.execute(req).await?;
885
886    let status = resp.status();
887    let content_type = resp
888        .headers()
889        .get("content-type")
890        .and_then(|v| v.to_str().ok())
891        .unwrap_or("application/octet-stream");
892    let content_type = super::ContentType::from(content_type);
893
894    if !status.is_client_error() && !status.is_server_error() {
895        let content = resp.text().await?;
896        match content_type {
897            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
898            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsGetExerciseRecordV1RespItem&gt;`"))),
899            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::OptionsGetExerciseRecordV1RespItem&gt;`")))),
900        }
901    } else {
902        let content = resp.text().await?;
903        let entity: Option<OptionsGetExerciseRecordV1Error> = serde_json::from_str(&content).ok();
904        Err(Error::ResponseError(ResponseContent { status, content, entity }))
905    }
906}
907
908/// Query all finished orders within 5 days, finished status: CANCELLED FILLED REJECTED.
909pub async fn options_get_history_orders_v1(configuration: &configuration::Configuration, params: OptionsGetHistoryOrdersV1Params) -> Result<Vec<models::OptionsGetHistoryOrdersV1RespItem>, Error<OptionsGetHistoryOrdersV1Error>> {
910
911    let uri_str = format!("{}/eapi/v1/historyOrders", configuration.base_path);
912    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
913
914    // Create a mutable vector for query parameters
915    let mut query_params: Vec<(String, String)> = Vec::new();
916
917    query_params.push(("symbol".to_string(), params.symbol.to_string()));
918    if let Some(ref param_value) = params.order_id {
919        query_params.push(("orderId".to_string(), param_value.to_string()));
920    }
921    if let Some(ref param_value) = params.start_time {
922        query_params.push(("startTime".to_string(), param_value.to_string()));
923    }
924    if let Some(ref param_value) = params.end_time {
925        query_params.push(("endTime".to_string(), param_value.to_string()));
926    }
927    if let Some(ref param_value) = params.limit {
928        query_params.push(("limit".to_string(), param_value.to_string()));
929    }
930    if let Some(ref param_value) = params.recv_window {
931        query_params.push(("recvWindow".to_string(), param_value.to_string()));
932    }
933    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
934
935    // Create header parameters collection
936    let mut header_params = std::collections::HashMap::new();
937
938    // Handle Binance Auth first if configured
939    if let Some(ref binance_auth) = configuration.binance_auth {
940        // Add API key to headers
941        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
942        
943        // Generate request body for signing (if any)
944        let body_string: Option<Vec<u8>> = None;
945        
946        // Sign the request
947        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
948            Ok(sig) => sig,
949            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
950        };
951        
952        // Add signature to query params
953        query_params.push(("signature".to_string(), signature));
954    }
955
956    // Apply all query parameters
957    if !query_params.is_empty() {
958        req_builder = req_builder.query(&query_params);
959    }
960
961
962    // Add user agent if configured
963    if let Some(ref user_agent) = configuration.user_agent {
964        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
965    }
966
967    // Apply all header parameters
968    for (header_name, header_value) in header_params {
969        req_builder = req_builder.header(&header_name, &header_value);
970    }
971
972
973    let req = req_builder.build()?;
974    let resp = configuration.client.execute(req).await?;
975
976    let status = resp.status();
977    let content_type = resp
978        .headers()
979        .get("content-type")
980        .and_then(|v| v.to_str().ok())
981        .unwrap_or("application/octet-stream");
982    let content_type = super::ContentType::from(content_type);
983
984    if !status.is_client_error() && !status.is_server_error() {
985        let content = resp.text().await?;
986        match content_type {
987            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
988            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsGetHistoryOrdersV1RespItem&gt;`"))),
989            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::OptionsGetHistoryOrdersV1RespItem&gt;`")))),
990        }
991    } else {
992        let content = resp.text().await?;
993        let entity: Option<OptionsGetHistoryOrdersV1Error> = serde_json::from_str(&content).ok();
994        Err(Error::ResponseError(ResponseContent { status, content, entity }))
995    }
996}
997
998/// Query current all open orders, status: ACCEPTED PARTIALLY_FILLED
999pub async fn options_get_open_orders_v1(configuration: &configuration::Configuration, params: OptionsGetOpenOrdersV1Params) -> Result<Vec<models::OptionsGetOpenOrdersV1RespItem>, Error<OptionsGetOpenOrdersV1Error>> {
1000
1001    let uri_str = format!("{}/eapi/v1/openOrders", configuration.base_path);
1002    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1003
1004    // Create a mutable vector for query parameters
1005    let mut query_params: Vec<(String, String)> = Vec::new();
1006
1007    if let Some(ref param_value) = params.symbol {
1008        query_params.push(("symbol".to_string(), param_value.to_string()));
1009    }
1010    if let Some(ref param_value) = params.order_id {
1011        query_params.push(("orderId".to_string(), param_value.to_string()));
1012    }
1013    if let Some(ref param_value) = params.start_time {
1014        query_params.push(("startTime".to_string(), param_value.to_string()));
1015    }
1016    if let Some(ref param_value) = params.end_time {
1017        query_params.push(("endTime".to_string(), param_value.to_string()));
1018    }
1019    if let Some(ref param_value) = params.limit {
1020        query_params.push(("limit".to_string(), param_value.to_string()));
1021    }
1022    if let Some(ref param_value) = params.recv_window {
1023        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1024    }
1025    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1026
1027    // Create header parameters collection
1028    let mut header_params = std::collections::HashMap::new();
1029
1030    // Handle Binance Auth first if configured
1031    if let Some(ref binance_auth) = configuration.binance_auth {
1032        // Add API key to headers
1033        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1034        
1035        // Generate request body for signing (if any)
1036        let body_string: Option<Vec<u8>> = None;
1037        
1038        // Sign the request
1039        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1040            Ok(sig) => sig,
1041            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1042        };
1043        
1044        // Add signature to query params
1045        query_params.push(("signature".to_string(), signature));
1046    }
1047
1048    // Apply all query parameters
1049    if !query_params.is_empty() {
1050        req_builder = req_builder.query(&query_params);
1051    }
1052
1053
1054    // Add user agent if configured
1055    if let Some(ref user_agent) = configuration.user_agent {
1056        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1057    }
1058
1059    // Apply all header parameters
1060    for (header_name, header_value) in header_params {
1061        req_builder = req_builder.header(&header_name, &header_value);
1062    }
1063
1064
1065    let req = req_builder.build()?;
1066    let resp = configuration.client.execute(req).await?;
1067
1068    let status = resp.status();
1069    let content_type = resp
1070        .headers()
1071        .get("content-type")
1072        .and_then(|v| v.to_str().ok())
1073        .unwrap_or("application/octet-stream");
1074    let content_type = super::ContentType::from(content_type);
1075
1076    if !status.is_client_error() && !status.is_server_error() {
1077        let content = resp.text().await?;
1078        match content_type {
1079            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1080            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsGetOpenOrdersV1RespItem&gt;`"))),
1081            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::OptionsGetOpenOrdersV1RespItem&gt;`")))),
1082        }
1083    } else {
1084        let content = resp.text().await?;
1085        let entity: Option<OptionsGetOpenOrdersV1Error> = serde_json::from_str(&content).ok();
1086        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1087    }
1088}
1089
1090/// Check an order status.
1091pub async fn options_get_order_v1(configuration: &configuration::Configuration, params: OptionsGetOrderV1Params) -> Result<models::OptionsGetOrderV1Resp, Error<OptionsGetOrderV1Error>> {
1092
1093    let uri_str = format!("{}/eapi/v1/order", configuration.base_path);
1094    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1095
1096    // Create a mutable vector for query parameters
1097    let mut query_params: Vec<(String, String)> = Vec::new();
1098
1099    query_params.push(("symbol".to_string(), params.symbol.to_string()));
1100    if let Some(ref param_value) = params.order_id {
1101        query_params.push(("orderId".to_string(), param_value.to_string()));
1102    }
1103    if let Some(ref param_value) = params.client_order_id {
1104        query_params.push(("clientOrderId".to_string(), param_value.to_string()));
1105    }
1106    if let Some(ref param_value) = params.recv_window {
1107        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1108    }
1109    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1110
1111    // Create header parameters collection
1112    let mut header_params = std::collections::HashMap::new();
1113
1114    // Handle Binance Auth first if configured
1115    if let Some(ref binance_auth) = configuration.binance_auth {
1116        // Add API key to headers
1117        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1118        
1119        // Generate request body for signing (if any)
1120        let body_string: Option<Vec<u8>> = None;
1121        
1122        // Sign the request
1123        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1124            Ok(sig) => sig,
1125            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1126        };
1127        
1128        // Add signature to query params
1129        query_params.push(("signature".to_string(), signature));
1130    }
1131
1132    // Apply all query parameters
1133    if !query_params.is_empty() {
1134        req_builder = req_builder.query(&query_params);
1135    }
1136
1137
1138    // Add user agent if configured
1139    if let Some(ref user_agent) = configuration.user_agent {
1140        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1141    }
1142
1143    // Apply all header parameters
1144    for (header_name, header_value) in header_params {
1145        req_builder = req_builder.header(&header_name, &header_value);
1146    }
1147
1148
1149    let req = req_builder.build()?;
1150    let resp = configuration.client.execute(req).await?;
1151
1152    let status = resp.status();
1153    let content_type = resp
1154        .headers()
1155        .get("content-type")
1156        .and_then(|v| v.to_str().ok())
1157        .unwrap_or("application/octet-stream");
1158    let content_type = super::ContentType::from(content_type);
1159
1160    if !status.is_client_error() && !status.is_server_error() {
1161        let content = resp.text().await?;
1162        match content_type {
1163            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1164            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsGetOrderV1Resp`"))),
1165            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::OptionsGetOrderV1Resp`")))),
1166        }
1167    } else {
1168        let content = resp.text().await?;
1169        let entity: Option<OptionsGetOrderV1Error> = serde_json::from_str(&content).ok();
1170        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1171    }
1172}
1173
1174/// Get current position information.
1175pub async fn options_get_position_v1(configuration: &configuration::Configuration, params: OptionsGetPositionV1Params) -> Result<Vec<models::OptionsGetPositionV1RespItem>, Error<OptionsGetPositionV1Error>> {
1176
1177    let uri_str = format!("{}/eapi/v1/position", configuration.base_path);
1178    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1179
1180    // Create a mutable vector for query parameters
1181    let mut query_params: Vec<(String, String)> = Vec::new();
1182
1183    if let Some(ref param_value) = params.symbol {
1184        query_params.push(("symbol".to_string(), param_value.to_string()));
1185    }
1186    if let Some(ref param_value) = params.recv_window {
1187        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1188    }
1189    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1190
1191    // Create header parameters collection
1192    let mut header_params = std::collections::HashMap::new();
1193
1194    // Handle Binance Auth first if configured
1195    if let Some(ref binance_auth) = configuration.binance_auth {
1196        // Add API key to headers
1197        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1198        
1199        // Generate request body for signing (if any)
1200        let body_string: Option<Vec<u8>> = None;
1201        
1202        // Sign the request
1203        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1204            Ok(sig) => sig,
1205            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1206        };
1207        
1208        // Add signature to query params
1209        query_params.push(("signature".to_string(), signature));
1210    }
1211
1212    // Apply all query parameters
1213    if !query_params.is_empty() {
1214        req_builder = req_builder.query(&query_params);
1215    }
1216
1217
1218    // Add user agent if configured
1219    if let Some(ref user_agent) = configuration.user_agent {
1220        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1221    }
1222
1223    // Apply all header parameters
1224    for (header_name, header_value) in header_params {
1225        req_builder = req_builder.header(&header_name, &header_value);
1226    }
1227
1228
1229    let req = req_builder.build()?;
1230    let resp = configuration.client.execute(req).await?;
1231
1232    let status = resp.status();
1233    let content_type = resp
1234        .headers()
1235        .get("content-type")
1236        .and_then(|v| v.to_str().ok())
1237        .unwrap_or("application/octet-stream");
1238    let content_type = super::ContentType::from(content_type);
1239
1240    if !status.is_client_error() && !status.is_server_error() {
1241        let content = resp.text().await?;
1242        match content_type {
1243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsGetPositionV1RespItem&gt;`"))),
1245            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::OptionsGetPositionV1RespItem&gt;`")))),
1246        }
1247    } else {
1248        let content = resp.text().await?;
1249        let entity: Option<OptionsGetPositionV1Error> = serde_json::from_str(&content).ok();
1250        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1251    }
1252}
1253
1254/// Get trades for a specific account and symbol.
1255pub async fn options_get_user_trades_v1(configuration: &configuration::Configuration, params: OptionsGetUserTradesV1Params) -> Result<Vec<models::OptionsGetUserTradesV1RespItem>, Error<OptionsGetUserTradesV1Error>> {
1256
1257    let uri_str = format!("{}/eapi/v1/userTrades", configuration.base_path);
1258    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
1259
1260    // Create a mutable vector for query parameters
1261    let mut query_params: Vec<(String, String)> = Vec::new();
1262
1263    if let Some(ref param_value) = params.symbol {
1264        query_params.push(("symbol".to_string(), param_value.to_string()));
1265    }
1266    if let Some(ref param_value) = params.from_id {
1267        query_params.push(("fromId".to_string(), param_value.to_string()));
1268    }
1269    if let Some(ref param_value) = params.start_time {
1270        query_params.push(("startTime".to_string(), param_value.to_string()));
1271    }
1272    if let Some(ref param_value) = params.end_time {
1273        query_params.push(("endTime".to_string(), param_value.to_string()));
1274    }
1275    if let Some(ref param_value) = params.limit {
1276        query_params.push(("limit".to_string(), param_value.to_string()));
1277    }
1278    if let Some(ref param_value) = params.recv_window {
1279        query_params.push(("recvWindow".to_string(), param_value.to_string()));
1280    }
1281    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
1282
1283    // Create header parameters collection
1284    let mut header_params = std::collections::HashMap::new();
1285
1286    // Handle Binance Auth first if configured
1287    if let Some(ref binance_auth) = configuration.binance_auth {
1288        // Add API key to headers
1289        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
1290        
1291        // Generate request body for signing (if any)
1292        let body_string: Option<Vec<u8>> = None;
1293        
1294        // Sign the request
1295        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
1296            Ok(sig) => sig,
1297            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
1298        };
1299        
1300        // Add signature to query params
1301        query_params.push(("signature".to_string(), signature));
1302    }
1303
1304    // Apply all query parameters
1305    if !query_params.is_empty() {
1306        req_builder = req_builder.query(&query_params);
1307    }
1308
1309
1310    // Add user agent if configured
1311    if let Some(ref user_agent) = configuration.user_agent {
1312        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
1313    }
1314
1315    // Apply all header parameters
1316    for (header_name, header_value) in header_params {
1317        req_builder = req_builder.header(&header_name, &header_value);
1318    }
1319
1320
1321    let req = req_builder.build()?;
1322    let resp = configuration.client.execute(req).await?;
1323
1324    let status = resp.status();
1325    let content_type = resp
1326        .headers()
1327        .get("content-type")
1328        .and_then(|v| v.to_str().ok())
1329        .unwrap_or("application/octet-stream");
1330    let content_type = super::ContentType::from(content_type);
1331
1332    if !status.is_client_error() && !status.is_server_error() {
1333        let content = resp.text().await?;
1334        match content_type {
1335            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
1336            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsGetUserTradesV1RespItem&gt;`"))),
1337            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::OptionsGetUserTradesV1RespItem&gt;`")))),
1338        }
1339    } else {
1340        let content = resp.text().await?;
1341        let entity: Option<OptionsGetUserTradesV1Error> = serde_json::from_str(&content).ok();
1342        Err(Error::ResponseError(ResponseContent { status, content, entity }))
1343    }
1344}
1345