binance/derivatives/options/apis/
account_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::derivatives::options::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct OptionsGetAccountV1Params {
20 pub timestamp: i64,
21 pub recv_window: Option<i64>
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct OptionsGetBillV1Params {
27 pub currency: String,
29 pub timestamp: i64,
30 pub record_id: Option<i64>,
32 pub start_time: Option<i64>,
34 pub end_time: Option<i64>,
36 pub limit: Option<i32>,
38 pub recv_window: Option<i64>
39}
40
41#[derive(Clone, Debug, Default)]
43pub struct OptionsGetIncomeAsynIdV1Params {
44 pub download_id: String,
46 pub timestamp: i64,
47 pub recv_window: Option<i64>
48}
49
50
51#[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#[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#[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#[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
88pub 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 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 let mut header_params = std::collections::HashMap::new();
104
105 if let Some(ref binance_auth) = configuration.binance_auth {
107 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
109
110 let body_string: Option<Vec<u8>> = None;
112
113 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 query_params.push(("signature".to_string(), signature));
121 }
122
123 if !query_params.is_empty() {
125 req_builder = req_builder.query(&query_params);
126 }
127
128
129 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 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
165pub 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 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 let mut header_params = std::collections::HashMap::new();
194
195 if let Some(ref binance_auth) = configuration.binance_auth {
197 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
199
200 let body_string: Option<Vec<u8>> = None;
202
203 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 query_params.push(("signature".to_string(), signature));
211 }
212
213 if !query_params.is_empty() {
215 req_builder = req_builder.query(&query_params);
216 }
217
218
219 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 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<models::OptionsGetBillV1RespItem>`"))),
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<models::OptionsGetBillV1RespItem>`")))),
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
255pub 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 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 let mut header_params = std::collections::HashMap::new();
272
273 if let Some(ref binance_auth) = configuration.binance_auth {
275 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
277
278 let body_string: Option<Vec<u8>> = None;
280
281 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 query_params.push(("signature".to_string(), signature));
289 }
290
291 if !query_params.is_empty() {
293 req_builder = req_builder.query(&query_params);
294 }
295
296
297 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 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
333pub 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 let mut query_params: Vec<(String, String)> = Vec::new();
341
342
343 let mut header_params = std::collections::HashMap::new();
345
346 if let Some(ref binance_auth) = configuration.binance_auth {
348 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
350
351 let body_string: Option<Vec<u8>> = None;
353
354 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 query_params.push(("signature".to_string(), signature));
362 }
363
364 if !query_params.is_empty() {
366 req_builder = req_builder.query(&query_params);
367 }
368
369
370 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 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