binance/spot/apis/
copy_trading_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 GetCopyTradingFuturesLeadSymbolV1Params {
20 pub timestamp: i64,
21 pub recv_window: Option<i64>
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct GetCopyTradingFuturesUserStatusV1Params {
27 pub timestamp: i64,
28 pub recv_window: Option<i64>
29}
30
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetCopyTradingFuturesLeadSymbolV1Error {
36 Status4XX(models::ApiError),
37 Status5XX(models::ApiError),
38 UnknownValue(serde_json::Value),
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetCopyTradingFuturesUserStatusV1Error {
45 Status4XX(models::ApiError),
46 Status5XX(models::ApiError),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn get_copy_trading_futures_lead_symbol_v1(configuration: &configuration::Configuration, params: GetCopyTradingFuturesLeadSymbolV1Params) -> Result<models::GetCopyTradingFuturesLeadSymbolV1Resp, Error<GetCopyTradingFuturesLeadSymbolV1Error>> {
53
54 let uri_str = format!("{}/sapi/v1/copyTrading/futures/leadSymbol", configuration.base_path);
55 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
56
57 let mut query_params: Vec<(String, String)> = Vec::new();
59
60 if let Some(ref param_value) = params.recv_window {
61 query_params.push(("recvWindow".to_string(), param_value.to_string()));
62 }
63 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
64
65 let mut header_params = std::collections::HashMap::new();
67
68 if let Some(ref binance_auth) = configuration.binance_auth {
70 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
72
73 let body_string: Option<Vec<u8>> = None;
75
76 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
78 Ok(sig) => sig,
79 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
80 };
81
82 query_params.push(("signature".to_string(), signature));
84 }
85
86 if !query_params.is_empty() {
88 req_builder = req_builder.query(&query_params);
89 }
90
91
92 if let Some(ref user_agent) = configuration.user_agent {
94 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95 }
96
97 for (header_name, header_value) in header_params {
99 req_builder = req_builder.header(&header_name, &header_value);
100 }
101
102
103 let req = req_builder.build()?;
104 let resp = configuration.client.execute(req).await?;
105
106 let status = resp.status();
107 let content_type = resp
108 .headers()
109 .get("content-type")
110 .and_then(|v| v.to_str().ok())
111 .unwrap_or("application/octet-stream");
112 let content_type = super::ContentType::from(content_type);
113
114 if !status.is_client_error() && !status.is_server_error() {
115 let content = resp.text().await?;
116 match content_type {
117 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
118 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetCopyTradingFuturesLeadSymbolV1Resp`"))),
119 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::GetCopyTradingFuturesLeadSymbolV1Resp`")))),
120 }
121 } else {
122 let content = resp.text().await?;
123 let entity: Option<GetCopyTradingFuturesLeadSymbolV1Error> = serde_json::from_str(&content).ok();
124 Err(Error::ResponseError(ResponseContent { status, content, entity }))
125 }
126}
127
128pub async fn get_copy_trading_futures_user_status_v1(configuration: &configuration::Configuration, params: GetCopyTradingFuturesUserStatusV1Params) -> Result<models::GetCopyTradingFuturesUserStatusV1Resp, Error<GetCopyTradingFuturesUserStatusV1Error>> {
130
131 let uri_str = format!("{}/sapi/v1/copyTrading/futures/userStatus", configuration.base_path);
132 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
133
134 let mut query_params: Vec<(String, String)> = Vec::new();
136
137 if let Some(ref param_value) = params.recv_window {
138 query_params.push(("recvWindow".to_string(), param_value.to_string()));
139 }
140 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
141
142 let mut header_params = std::collections::HashMap::new();
144
145 if let Some(ref binance_auth) = configuration.binance_auth {
147 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
149
150 let body_string: Option<Vec<u8>> = None;
152
153 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
155 Ok(sig) => sig,
156 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
157 };
158
159 query_params.push(("signature".to_string(), signature));
161 }
162
163 if !query_params.is_empty() {
165 req_builder = req_builder.query(&query_params);
166 }
167
168
169 if let Some(ref user_agent) = configuration.user_agent {
171 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172 }
173
174 for (header_name, header_value) in header_params {
176 req_builder = req_builder.header(&header_name, &header_value);
177 }
178
179
180 let req = req_builder.build()?;
181 let resp = configuration.client.execute(req).await?;
182
183 let status = resp.status();
184 let content_type = resp
185 .headers()
186 .get("content-type")
187 .and_then(|v| v.to_str().ok())
188 .unwrap_or("application/octet-stream");
189 let content_type = super::ContentType::from(content_type);
190
191 if !status.is_client_error() && !status.is_server_error() {
192 let content = resp.text().await?;
193 match content_type {
194 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
195 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetCopyTradingFuturesUserStatusV1Resp`"))),
196 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::GetCopyTradingFuturesUserStatusV1Resp`")))),
197 }
198 } else {
199 let content = resp.text().await?;
200 let entity: Option<GetCopyTradingFuturesUserStatusV1Error> = serde_json::from_str(&content).ok();
201 Err(Error::ResponseError(ResponseContent { status, content, entity }))
202 }
203}
204