binance/spot/apis/
c2c_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::spot::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct GetC2cOrderMatchListUserOrderHistoryV1Params {
20 pub timestamp: i64,
21 pub start_time: Option<i64>,
22 pub end_time: Option<i64>,
23 pub page: Option<i32>,
25 pub recv_window: Option<i64>
26}
27
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetC2cOrderMatchListUserOrderHistoryV1Error {
33 Status4XX(models::ApiError),
34 Status5XX(models::ApiError),
35 UnknownValue(serde_json::Value),
36}
37
38
39pub async fn get_c2c_order_match_list_user_order_history_v1(configuration: &configuration::Configuration, params: GetC2cOrderMatchListUserOrderHistoryV1Params) -> Result<models::GetC2cOrderMatchListUserOrderHistoryV1Resp, Error<GetC2cOrderMatchListUserOrderHistoryV1Error>> {
41
42 let uri_str = format!("{}/sapi/v1/c2c/orderMatch/listUserOrderHistory", configuration.base_path);
43 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45 let mut query_params: Vec<(String, String)> = Vec::new();
47
48 if let Some(ref param_value) = params.start_time {
49 query_params.push(("startTime".to_string(), param_value.to_string()));
50 }
51 if let Some(ref param_value) = params.end_time {
52 query_params.push(("endTime".to_string(), param_value.to_string()));
53 }
54 if let Some(ref param_value) = params.page {
55 query_params.push(("page".to_string(), param_value.to_string()));
56 }
57 if let Some(ref param_value) = params.recv_window {
58 query_params.push(("recvWindow".to_string(), param_value.to_string()));
59 }
60 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
61
62 let mut header_params = std::collections::HashMap::new();
64
65 if let Some(ref binance_auth) = configuration.binance_auth {
67 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
69
70 let body_string: Option<Vec<u8>> = None;
72
73 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
75 Ok(sig) => sig,
76 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
77 };
78
79 query_params.push(("signature".to_string(), signature));
81 }
82
83 if !query_params.is_empty() {
85 req_builder = req_builder.query(&query_params);
86 }
87
88
89 if let Some(ref user_agent) = configuration.user_agent {
91 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92 }
93
94 for (header_name, header_value) in header_params {
96 req_builder = req_builder.header(&header_name, &header_value);
97 }
98
99
100 let req = req_builder.build()?;
101 let resp = configuration.client.execute(req).await?;
102
103 let status = resp.status();
104 let content_type = resp
105 .headers()
106 .get("content-type")
107 .and_then(|v| v.to_str().ok())
108 .unwrap_or("application/octet-stream");
109 let content_type = super::ContentType::from(content_type);
110
111 if !status.is_client_error() && !status.is_server_error() {
112 let content = resp.text().await?;
113 match content_type {
114 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetC2cOrderMatchListUserOrderHistoryV1Resp`"))),
116 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::GetC2cOrderMatchListUserOrderHistoryV1Resp`")))),
117 }
118 } else {
119 let content = resp.text().await?;
120 let entity: Option<GetC2cOrderMatchListUserOrderHistoryV1Error> = serde_json::from_str(&content).ok();
121 Err(Error::ResponseError(ResponseContent { status, content, entity }))
122 }
123}
124