binance/derivatives/options/apis/
account_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_get_account_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct OptionsGetAccountV1Params {
20    pub timestamp: i64,
21    pub recv_window: Option<i64>
22}
23
24/// struct for passing parameters to the method [`options_get_bill_v1`]
25#[derive(Clone, Debug, Default)]
26pub struct OptionsGetBillV1Params {
27    /// Asset type, only support USDT  as of now
28    pub currency: String,
29    pub timestamp: i64,
30    /// Return the recordId and subsequent data, the latest data is returned by default, e.g 100000
31    pub record_id: Option<i64>,
32    /// Start Time, e.g 1593511200000
33    pub start_time: Option<i64>,
34    /// End Time, e.g 1593512200000
35    pub end_time: Option<i64>,
36    /// Number of result sets returned Default:100 Max:1000
37    pub limit: Option<i32>,
38    pub recv_window: Option<i64>
39}
40
41/// struct for passing parameters to the method [`options_get_income_asyn_id_v1`]
42#[derive(Clone, Debug, Default)]
43pub struct OptionsGetIncomeAsynIdV1Params {
44    /// get by download id api
45    pub download_id: String,
46    pub timestamp: i64,
47    pub recv_window: Option<i64>
48}
49
50
51/// struct for typed errors of method [`options_get_account_v1`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum OptionsGetAccountV1Error {
55    Status4XX(models::ApiError),
56    Status5XX(models::ApiError),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`options_get_bill_v1`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum OptionsGetBillV1Error {
64    Status4XX(models::ApiError),
65    Status5XX(models::ApiError),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`options_get_income_asyn_id_v1`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum OptionsGetIncomeAsynIdV1Error {
73    Status4XX(models::ApiError),
74    Status5XX(models::ApiError),
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`options_get_income_asyn_v1`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum OptionsGetIncomeAsynV1Error {
82    Status4XX(models::ApiError),
83    Status5XX(models::ApiError),
84    UnknownValue(serde_json::Value),
85}
86
87
88/// Get current account information.
89pub async fn options_get_account_v1(configuration: &configuration::Configuration, params: OptionsGetAccountV1Params) -> Result<models::OptionsGetAccountV1Resp, Error<OptionsGetAccountV1Error>> {
90
91    let uri_str = format!("{}/eapi/v1/account", configuration.base_path);
92    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
93
94    // Create a mutable vector for query parameters
95    let mut query_params: Vec<(String, String)> = Vec::new();
96
97    if let Some(ref param_value) = params.recv_window {
98        query_params.push(("recvWindow".to_string(), param_value.to_string()));
99    }
100    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
101
102    // Create header parameters collection
103    let mut header_params = std::collections::HashMap::new();
104
105    // Handle Binance Auth first if configured
106    if let Some(ref binance_auth) = configuration.binance_auth {
107        // Add API key to headers
108        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
109        
110        // Generate request body for signing (if any)
111        let body_string: Option<Vec<u8>> = None;
112        
113        // Sign the request
114        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
115            Ok(sig) => sig,
116            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
117        };
118        
119        // Add signature to query params
120        query_params.push(("signature".to_string(), signature));
121    }
122
123    // Apply all query parameters
124    if !query_params.is_empty() {
125        req_builder = req_builder.query(&query_params);
126    }
127
128
129    // Add user agent if configured
130    if let Some(ref user_agent) = configuration.user_agent {
131        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
132    }
133
134    // Apply all header parameters
135    for (header_name, header_value) in header_params {
136        req_builder = req_builder.header(&header_name, &header_value);
137    }
138
139
140    let req = req_builder.build()?;
141    let resp = configuration.client.execute(req).await?;
142
143    let status = resp.status();
144    let content_type = resp
145        .headers()
146        .get("content-type")
147        .and_then(|v| v.to_str().ok())
148        .unwrap_or("application/octet-stream");
149    let content_type = super::ContentType::from(content_type);
150
151    if !status.is_client_error() && !status.is_server_error() {
152        let content = resp.text().await?;
153        match content_type {
154            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsGetAccountV1Resp`"))),
156            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::OptionsGetAccountV1Resp`")))),
157        }
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<OptionsGetAccountV1Error> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent { status, content, entity }))
162    }
163}
164
165/// Query account funding flows.
166pub async fn options_get_bill_v1(configuration: &configuration::Configuration, params: OptionsGetBillV1Params) -> Result<Vec<models::OptionsGetBillV1RespItem>, Error<OptionsGetBillV1Error>> {
167
168    let uri_str = format!("{}/eapi/v1/bill", configuration.base_path);
169    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
170
171    // Create a mutable vector for query parameters
172    let mut query_params: Vec<(String, String)> = Vec::new();
173
174    query_params.push(("currency".to_string(), params.currency.to_string()));
175    if let Some(ref param_value) = params.record_id {
176        query_params.push(("recordId".to_string(), param_value.to_string()));
177    }
178    if let Some(ref param_value) = params.start_time {
179        query_params.push(("startTime".to_string(), param_value.to_string()));
180    }
181    if let Some(ref param_value) = params.end_time {
182        query_params.push(("endTime".to_string(), param_value.to_string()));
183    }
184    if let Some(ref param_value) = params.limit {
185        query_params.push(("limit".to_string(), param_value.to_string()));
186    }
187    if let Some(ref param_value) = params.recv_window {
188        query_params.push(("recvWindow".to_string(), param_value.to_string()));
189    }
190    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
191
192    // Create header parameters collection
193    let mut header_params = std::collections::HashMap::new();
194
195    // Handle Binance Auth first if configured
196    if let Some(ref binance_auth) = configuration.binance_auth {
197        // Add API key to headers
198        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
199        
200        // Generate request body for signing (if any)
201        let body_string: Option<Vec<u8>> = None;
202        
203        // Sign the request
204        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
205            Ok(sig) => sig,
206            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
207        };
208        
209        // Add signature to query params
210        query_params.push(("signature".to_string(), signature));
211    }
212
213    // Apply all query parameters
214    if !query_params.is_empty() {
215        req_builder = req_builder.query(&query_params);
216    }
217
218
219    // Add user agent if configured
220    if let Some(ref user_agent) = configuration.user_agent {
221        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
222    }
223
224    // Apply all header parameters
225    for (header_name, header_value) in header_params {
226        req_builder = req_builder.header(&header_name, &header_value);
227    }
228
229
230    let req = req_builder.build()?;
231    let resp = configuration.client.execute(req).await?;
232
233    let status = resp.status();
234    let content_type = resp
235        .headers()
236        .get("content-type")
237        .and_then(|v| v.to_str().ok())
238        .unwrap_or("application/octet-stream");
239    let content_type = super::ContentType::from(content_type);
240
241    if !status.is_client_error() && !status.is_server_error() {
242        let content = resp.text().await?;
243        match content_type {
244            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OptionsGetBillV1RespItem&gt;`"))),
246            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::OptionsGetBillV1RespItem&gt;`")))),
247        }
248    } else {
249        let content = resp.text().await?;
250        let entity: Option<OptionsGetBillV1Error> = serde_json::from_str(&content).ok();
251        Err(Error::ResponseError(ResponseContent { status, content, entity }))
252    }
253}
254
255/// Get option transaction history download Link by Id
256pub async fn options_get_income_asyn_id_v1(configuration: &configuration::Configuration, params: OptionsGetIncomeAsynIdV1Params) -> Result<models::OptionsGetIncomeAsynIdV1Resp, Error<OptionsGetIncomeAsynIdV1Error>> {
257
258    let uri_str = format!("{}/eapi/v1/income/asyn/id", configuration.base_path);
259    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
260
261    // Create a mutable vector for query parameters
262    let mut query_params: Vec<(String, String)> = Vec::new();
263
264    query_params.push(("downloadId".to_string(), params.download_id.to_string()));
265    if let Some(ref param_value) = params.recv_window {
266        query_params.push(("recvWindow".to_string(), param_value.to_string()));
267    }
268    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
269
270    // Create header parameters collection
271    let mut header_params = std::collections::HashMap::new();
272
273    // Handle Binance Auth first if configured
274    if let Some(ref binance_auth) = configuration.binance_auth {
275        // Add API key to headers
276        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
277        
278        // Generate request body for signing (if any)
279        let body_string: Option<Vec<u8>> = None;
280        
281        // Sign the request
282        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
283            Ok(sig) => sig,
284            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
285        };
286        
287        // Add signature to query params
288        query_params.push(("signature".to_string(), signature));
289    }
290
291    // Apply all query parameters
292    if !query_params.is_empty() {
293        req_builder = req_builder.query(&query_params);
294    }
295
296
297    // Add user agent if configured
298    if let Some(ref user_agent) = configuration.user_agent {
299        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
300    }
301
302    // Apply all header parameters
303    for (header_name, header_value) in header_params {
304        req_builder = req_builder.header(&header_name, &header_value);
305    }
306
307
308    let req = req_builder.build()?;
309    let resp = configuration.client.execute(req).await?;
310
311    let status = resp.status();
312    let content_type = resp
313        .headers()
314        .get("content-type")
315        .and_then(|v| v.to_str().ok())
316        .unwrap_or("application/octet-stream");
317    let content_type = super::ContentType::from(content_type);
318
319    if !status.is_client_error() && !status.is_server_error() {
320        let content = resp.text().await?;
321        match content_type {
322            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
323            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsGetIncomeAsynIdV1Resp`"))),
324            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::OptionsGetIncomeAsynIdV1Resp`")))),
325        }
326    } else {
327        let content = resp.text().await?;
328        let entity: Option<OptionsGetIncomeAsynIdV1Error> = serde_json::from_str(&content).ok();
329        Err(Error::ResponseError(ResponseContent { status, content, entity }))
330    }
331}
332
333/// Get download id for option transaction history
334pub async fn options_get_income_asyn_v1(configuration: &configuration::Configuration) -> Result<models::OptionsGetIncomeAsynV1Resp, Error<OptionsGetIncomeAsynV1Error>> {
335
336    let uri_str = format!("{}/eapi/v1/income/asyn", configuration.base_path);
337    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
338
339    // Create a mutable vector for query parameters
340    let mut query_params: Vec<(String, String)> = Vec::new();
341
342
343    // Create header parameters collection
344    let mut header_params = std::collections::HashMap::new();
345
346    // Handle Binance Auth first if configured
347    if let Some(ref binance_auth) = configuration.binance_auth {
348        // Add API key to headers
349        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
350        
351        // Generate request body for signing (if any)
352        let body_string: Option<Vec<u8>> = None;
353        
354        // Sign the request
355        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
356            Ok(sig) => sig,
357            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
358        };
359        
360        // Add signature to query params
361        query_params.push(("signature".to_string(), signature));
362    }
363
364    // Apply all query parameters
365    if !query_params.is_empty() {
366        req_builder = req_builder.query(&query_params);
367    }
368
369
370    // Add user agent if configured
371    if let Some(ref user_agent) = configuration.user_agent {
372        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
373    }
374
375    // Apply all header parameters
376    for (header_name, header_value) in header_params {
377        req_builder = req_builder.header(&header_name, &header_value);
378    }
379
380
381    let req = req_builder.build()?;
382    let resp = configuration.client.execute(req).await?;
383
384    let status = resp.status();
385    let content_type = resp
386        .headers()
387        .get("content-type")
388        .and_then(|v| v.to_str().ok())
389        .unwrap_or("application/octet-stream");
390    let content_type = super::ContentType::from(content_type);
391
392    if !status.is_client_error() && !status.is_server_error() {
393        let content = resp.text().await?;
394        match content_type {
395            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
396            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OptionsGetIncomeAsynV1Resp`"))),
397            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::OptionsGetIncomeAsynV1Resp`")))),
398        }
399    } else {
400        let content = resp.text().await?;
401        let entity: Option<OptionsGetIncomeAsynV1Error> = serde_json::from_str(&content).ok();
402        Err(Error::ResponseError(ResponseContent { status, content, entity }))
403    }
404}
405