1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::margin::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct MarginCreateUserDataStreamIsolatedV1Params {
20 pub symbol: String
21}
22
23#[derive(Clone, Debug, Default)]
25pub struct MarginDeleteUserDataStreamIsolatedV1Params {
26 pub symbol: String,
27 pub listenkey: String
28}
29
30#[derive(Clone, Debug, Default)]
32pub struct MarginDeleteUserDataStreamV1Params {
33 pub listenkey: String
34}
35
36#[derive(Clone, Debug, Default)]
38pub struct MarginUpdateUserDataStreamIsolatedV1Params {
39 pub listen_key: String,
40 pub symbol: String
41}
42
43#[derive(Clone, Debug, Default)]
45pub struct MarginUpdateUserDataStreamV1Params {
46 pub listen_key: String
47}
48
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum MarginCreateUserDataStreamIsolatedV1Error {
54 Status4XX(models::ApiError),
55 Status5XX(models::ApiError),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum MarginCreateUserDataStreamV1Error {
63 Status4XX(models::ApiError),
64 Status5XX(models::ApiError),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum MarginDeleteUserDataStreamIsolatedV1Error {
72 Status4XX(models::ApiError),
73 Status5XX(models::ApiError),
74 UnknownValue(serde_json::Value),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum MarginDeleteUserDataStreamV1Error {
81 Status4XX(models::ApiError),
82 Status5XX(models::ApiError),
83 UnknownValue(serde_json::Value),
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum MarginUpdateUserDataStreamIsolatedV1Error {
90 Status4XX(models::ApiError),
91 Status5XX(models::ApiError),
92 UnknownValue(serde_json::Value),
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum MarginUpdateUserDataStreamV1Error {
99 Status4XX(models::ApiError),
100 Status5XX(models::ApiError),
101 UnknownValue(serde_json::Value),
102}
103
104
105pub async fn margin_create_user_data_stream_isolated_v1(configuration: &configuration::Configuration, params: MarginCreateUserDataStreamIsolatedV1Params) -> Result<models::MarginCreateUserDataStreamIsolatedV1Resp, Error<MarginCreateUserDataStreamIsolatedV1Error>> {
107
108 let uri_str = format!("{}/sapi/v1/userDataStream/isolated", configuration.base_path);
109 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
110
111 let mut query_params: Vec<(String, String)> = Vec::new();
113
114
115 let mut header_params = std::collections::HashMap::new();
117
118 if let Some(ref binance_auth) = configuration.binance_auth {
120 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
122
123 let body_string: Option<Vec<u8>> = None;
125
126 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
128 Ok(sig) => sig,
129 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
130 };
131
132 query_params.push(("signature".to_string(), signature));
134 }
135
136 if !query_params.is_empty() {
138 req_builder = req_builder.query(&query_params);
139 }
140
141
142 if let Some(ref user_agent) = configuration.user_agent {
144 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
145 }
146
147 for (header_name, header_value) in header_params {
149 req_builder = req_builder.header(&header_name, &header_value);
150 }
151
152 let mut multipart_form_params = std::collections::HashMap::new();
153 multipart_form_params.insert("symbol", params.symbol.to_string());
154 req_builder = req_builder.form(&multipart_form_params);
155
156 let req = req_builder.build()?;
157 let resp = configuration.client.execute(req).await?;
158
159 let status = resp.status();
160 let content_type = resp
161 .headers()
162 .get("content-type")
163 .and_then(|v| v.to_str().ok())
164 .unwrap_or("application/octet-stream");
165 let content_type = super::ContentType::from(content_type);
166
167 if !status.is_client_error() && !status.is_server_error() {
168 let content = resp.text().await?;
169 match content_type {
170 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
171 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginCreateUserDataStreamIsolatedV1Resp`"))),
172 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::MarginCreateUserDataStreamIsolatedV1Resp`")))),
173 }
174 } else {
175 let content = resp.text().await?;
176 let entity: Option<MarginCreateUserDataStreamIsolatedV1Error> = serde_json::from_str(&content).ok();
177 Err(Error::ResponseError(ResponseContent { status, content, entity }))
178 }
179}
180
181pub async fn margin_create_user_data_stream_v1(configuration: &configuration::Configuration) -> Result<models::MarginCreateUserDataStreamV1Resp, Error<MarginCreateUserDataStreamV1Error>> {
183
184 let uri_str = format!("{}/sapi/v1/userDataStream", configuration.base_path);
185 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
186
187 let mut query_params: Vec<(String, String)> = Vec::new();
189
190
191 let mut header_params = std::collections::HashMap::new();
193
194 if let Some(ref binance_auth) = configuration.binance_auth {
196 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
198
199 let body_string: Option<Vec<u8>> = None;
201
202 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
204 Ok(sig) => sig,
205 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
206 };
207
208 query_params.push(("signature".to_string(), signature));
210 }
211
212 if !query_params.is_empty() {
214 req_builder = req_builder.query(&query_params);
215 }
216
217
218 if let Some(ref user_agent) = configuration.user_agent {
220 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221 }
222
223 for (header_name, header_value) in header_params {
225 req_builder = req_builder.header(&header_name, &header_value);
226 }
227
228
229 let req = req_builder.build()?;
230 let resp = configuration.client.execute(req).await?;
231
232 let status = resp.status();
233 let content_type = resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let content_type = super::ContentType::from(content_type);
239
240 if !status.is_client_error() && !status.is_server_error() {
241 let content = resp.text().await?;
242 match content_type {
243 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginCreateUserDataStreamV1Resp`"))),
245 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::MarginCreateUserDataStreamV1Resp`")))),
246 }
247 } else {
248 let content = resp.text().await?;
249 let entity: Option<MarginCreateUserDataStreamV1Error> = serde_json::from_str(&content).ok();
250 Err(Error::ResponseError(ResponseContent { status, content, entity }))
251 }
252}
253
254pub async fn margin_delete_user_data_stream_isolated_v1(configuration: &configuration::Configuration, params: MarginDeleteUserDataStreamIsolatedV1Params) -> Result<serde_json::Value, Error<MarginDeleteUserDataStreamIsolatedV1Error>> {
256
257 let uri_str = format!("{}/sapi/v1/userDataStream/isolated", configuration.base_path);
258 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
259
260 let mut query_params: Vec<(String, String)> = Vec::new();
262
263 query_params.push(("symbol".to_string(), params.symbol.to_string()));
264 query_params.push(("listenkey".to_string(), params.listenkey.to_string()));
265
266 let mut header_params = std::collections::HashMap::new();
268
269 if let Some(ref binance_auth) = configuration.binance_auth {
271 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
273
274 let body_string: Option<Vec<u8>> = None;
276
277 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
279 Ok(sig) => sig,
280 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
281 };
282
283 query_params.push(("signature".to_string(), signature));
285 }
286
287 if !query_params.is_empty() {
289 req_builder = req_builder.query(&query_params);
290 }
291
292
293 if let Some(ref user_agent) = configuration.user_agent {
295 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
296 }
297
298 for (header_name, header_value) in header_params {
300 req_builder = req_builder.header(&header_name, &header_value);
301 }
302
303
304 let req = req_builder.build()?;
305 let resp = configuration.client.execute(req).await?;
306
307 let status = resp.status();
308 let content_type = resp
309 .headers()
310 .get("content-type")
311 .and_then(|v| v.to_str().ok())
312 .unwrap_or("application/octet-stream");
313 let content_type = super::ContentType::from(content_type);
314
315 if !status.is_client_error() && !status.is_server_error() {
316 let content = resp.text().await?;
317 match content_type {
318 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
319 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
320 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
321 }
322 } else {
323 let content = resp.text().await?;
324 let entity: Option<MarginDeleteUserDataStreamIsolatedV1Error> = serde_json::from_str(&content).ok();
325 Err(Error::ResponseError(ResponseContent { status, content, entity }))
326 }
327}
328
329pub async fn margin_delete_user_data_stream_v1(configuration: &configuration::Configuration, params: MarginDeleteUserDataStreamV1Params) -> Result<serde_json::Value, Error<MarginDeleteUserDataStreamV1Error>> {
331
332 let uri_str = format!("{}/sapi/v1/userDataStream", configuration.base_path);
333 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
334
335 let mut query_params: Vec<(String, String)> = Vec::new();
337
338 query_params.push(("listenkey".to_string(), params.listenkey.to_string()));
339
340 let mut header_params = std::collections::HashMap::new();
342
343 if let Some(ref binance_auth) = configuration.binance_auth {
345 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
347
348 let body_string: Option<Vec<u8>> = None;
350
351 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
353 Ok(sig) => sig,
354 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
355 };
356
357 query_params.push(("signature".to_string(), signature));
359 }
360
361 if !query_params.is_empty() {
363 req_builder = req_builder.query(&query_params);
364 }
365
366
367 if let Some(ref user_agent) = configuration.user_agent {
369 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
370 }
371
372 for (header_name, header_value) in header_params {
374 req_builder = req_builder.header(&header_name, &header_value);
375 }
376
377
378 let req = req_builder.build()?;
379 let resp = configuration.client.execute(req).await?;
380
381 let status = resp.status();
382 let content_type = resp
383 .headers()
384 .get("content-type")
385 .and_then(|v| v.to_str().ok())
386 .unwrap_or("application/octet-stream");
387 let content_type = super::ContentType::from(content_type);
388
389 if !status.is_client_error() && !status.is_server_error() {
390 let content = resp.text().await?;
391 match content_type {
392 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
393 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
394 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
395 }
396 } else {
397 let content = resp.text().await?;
398 let entity: Option<MarginDeleteUserDataStreamV1Error> = serde_json::from_str(&content).ok();
399 Err(Error::ResponseError(ResponseContent { status, content, entity }))
400 }
401}
402
403pub async fn margin_update_user_data_stream_isolated_v1(configuration: &configuration::Configuration, params: MarginUpdateUserDataStreamIsolatedV1Params) -> Result<serde_json::Value, Error<MarginUpdateUserDataStreamIsolatedV1Error>> {
405
406 let uri_str = format!("{}/sapi/v1/userDataStream/isolated", configuration.base_path);
407 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
408
409 let mut query_params: Vec<(String, String)> = Vec::new();
411
412
413 let mut header_params = std::collections::HashMap::new();
415
416 if let Some(ref binance_auth) = configuration.binance_auth {
418 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
420
421 let body_string: Option<Vec<u8>> = None;
423
424 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
426 Ok(sig) => sig,
427 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
428 };
429
430 query_params.push(("signature".to_string(), signature));
432 }
433
434 if !query_params.is_empty() {
436 req_builder = req_builder.query(&query_params);
437 }
438
439
440 if let Some(ref user_agent) = configuration.user_agent {
442 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
443 }
444
445 for (header_name, header_value) in header_params {
447 req_builder = req_builder.header(&header_name, &header_value);
448 }
449
450 let mut multipart_form_params = std::collections::HashMap::new();
451 multipart_form_params.insert("listenKey", params.listen_key.to_string());
452 multipart_form_params.insert("symbol", params.symbol.to_string());
453 req_builder = req_builder.form(&multipart_form_params);
454
455 let req = req_builder.build()?;
456 let resp = configuration.client.execute(req).await?;
457
458 let status = resp.status();
459 let content_type = resp
460 .headers()
461 .get("content-type")
462 .and_then(|v| v.to_str().ok())
463 .unwrap_or("application/octet-stream");
464 let content_type = super::ContentType::from(content_type);
465
466 if !status.is_client_error() && !status.is_server_error() {
467 let content = resp.text().await?;
468 match content_type {
469 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
470 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
471 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
472 }
473 } else {
474 let content = resp.text().await?;
475 let entity: Option<MarginUpdateUserDataStreamIsolatedV1Error> = serde_json::from_str(&content).ok();
476 Err(Error::ResponseError(ResponseContent { status, content, entity }))
477 }
478}
479
480pub async fn margin_update_user_data_stream_v1(configuration: &configuration::Configuration, params: MarginUpdateUserDataStreamV1Params) -> Result<serde_json::Value, Error<MarginUpdateUserDataStreamV1Error>> {
482
483 let uri_str = format!("{}/sapi/v1/userDataStream", configuration.base_path);
484 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
485
486 let mut query_params: Vec<(String, String)> = Vec::new();
488
489
490 let mut header_params = std::collections::HashMap::new();
492
493 if let Some(ref binance_auth) = configuration.binance_auth {
495 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
497
498 let body_string: Option<Vec<u8>> = None;
500
501 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
503 Ok(sig) => sig,
504 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
505 };
506
507 query_params.push(("signature".to_string(), signature));
509 }
510
511 if !query_params.is_empty() {
513 req_builder = req_builder.query(&query_params);
514 }
515
516
517 if let Some(ref user_agent) = configuration.user_agent {
519 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
520 }
521
522 for (header_name, header_value) in header_params {
524 req_builder = req_builder.header(&header_name, &header_value);
525 }
526
527 let mut multipart_form_params = std::collections::HashMap::new();
528 multipart_form_params.insert("listenKey", params.listen_key.to_string());
529 req_builder = req_builder.form(&multipart_form_params);
530
531 let req = req_builder.build()?;
532 let resp = configuration.client.execute(req).await?;
533
534 let status = resp.status();
535 let content_type = resp
536 .headers()
537 .get("content-type")
538 .and_then(|v| v.to_str().ok())
539 .unwrap_or("application/octet-stream");
540 let content_type = super::ContentType::from(content_type);
541
542 if !status.is_client_error() && !status.is_server_error() {
543 let content = resp.text().await?;
544 match content_type {
545 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
546 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
547 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
548 }
549 } else {
550 let content = resp.text().await?;
551 let entity: Option<MarginUpdateUserDataStreamV1Error> = serde_json::from_str(&content).ok();
552 Err(Error::ResponseError(ResponseContent { status, content, entity }))
553 }
554}
555