1use 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 SpotGetExchangeInfoV3Params {
20 pub symbol: Option<String>,
22 pub symbols: Option<Vec<String>>,
24 pub permissions: Option<String>,
26 pub show_permission_sets: Option<bool>,
28 pub symbol_status: Option<String>
30}
31
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum SpotGetExchangeInfoV3Error {
37 Status4XX(models::ApiError),
38 Status5XX(models::ApiError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum SpotGetPingV3Error {
46 Status4XX(models::ApiError),
47 Status5XX(models::ApiError),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum SpotGetTimeV3Error {
55 Status4XX(models::ApiError),
56 Status5XX(models::ApiError),
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn spot_get_exchange_info_v3(configuration: &configuration::Configuration, params: SpotGetExchangeInfoV3Params) -> Result<models::SpotGetExchangeInfoV3Resp, Error<SpotGetExchangeInfoV3Error>> {
63
64 let uri_str = format!("{}/api/v3/exchangeInfo", configuration.base_path);
65 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
66
67 let mut query_params: Vec<(String, String)> = Vec::new();
69
70 if let Some(ref param_value) = params.symbol {
71 query_params.push(("symbol".to_string(), param_value.to_string()));
72 }
73 if let Some(ref param_value) = params.symbols {
74 match "multi" {
75 "multi" => {
76 for p in param_value {
77 query_params.push(("symbols".to_string(), p.to_string()));
78 }
79 },
80 _ => {
81 let joined = param_value.iter()
82 .map(|p| p.to_string())
83 .collect::<Vec<String>>()
84 .join(",");
85 query_params.push(("symbols".to_string(), joined));
86 }
87 };
88 }
89 if let Some(ref param_value) = params.permissions {
90 query_params.push(("permissions".to_string(), param_value.to_string()));
91 }
92 if let Some(ref param_value) = params.show_permission_sets {
93 query_params.push(("showPermissionSets".to_string(), param_value.to_string()));
94 }
95 if let Some(ref param_value) = params.symbol_status {
96 query_params.push(("symbolStatus".to_string(), param_value.to_string()));
97 }
98
99 let mut header_params = std::collections::HashMap::new();
101
102 if let Some(ref binance_auth) = configuration.binance_auth {
104 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
106
107 let body_string: Option<Vec<u8>> = None;
109
110 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
112 Ok(sig) => sig,
113 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
114 };
115
116 query_params.push(("signature".to_string(), signature));
118 }
119
120 if !query_params.is_empty() {
122 req_builder = req_builder.query(&query_params);
123 }
124
125
126 if let Some(ref user_agent) = configuration.user_agent {
128 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129 }
130
131 for (header_name, header_value) in header_params {
133 req_builder = req_builder.header(&header_name, &header_value);
134 }
135
136
137 let req = req_builder.build()?;
138 let resp = configuration.client.execute(req).await?;
139
140 let status = resp.status();
141 let content_type = resp
142 .headers()
143 .get("content-type")
144 .and_then(|v| v.to_str().ok())
145 .unwrap_or("application/octet-stream");
146 let content_type = super::ContentType::from(content_type);
147
148 if !status.is_client_error() && !status.is_server_error() {
149 let content = resp.text().await?;
150 match content_type {
151 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
152 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SpotGetExchangeInfoV3Resp`"))),
153 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::SpotGetExchangeInfoV3Resp`")))),
154 }
155 } else {
156 let content = resp.text().await?;
157 let entity: Option<SpotGetExchangeInfoV3Error> = serde_json::from_str(&content).ok();
158 Err(Error::ResponseError(ResponseContent { status, content, entity }))
159 }
160}
161
162pub async fn spot_get_ping_v3(configuration: &configuration::Configuration) -> Result<serde_json::Value, Error<SpotGetPingV3Error>> {
164
165 let uri_str = format!("{}/api/v3/ping", configuration.base_path);
166 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
167
168 let mut query_params: Vec<(String, String)> = Vec::new();
170
171
172 let mut header_params = std::collections::HashMap::new();
174
175 if let Some(ref binance_auth) = configuration.binance_auth {
177 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
179
180 let body_string: Option<Vec<u8>> = None;
182
183 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
185 Ok(sig) => sig,
186 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
187 };
188
189 query_params.push(("signature".to_string(), signature));
191 }
192
193 if !query_params.is_empty() {
195 req_builder = req_builder.query(&query_params);
196 }
197
198
199 if let Some(ref user_agent) = configuration.user_agent {
201 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
202 }
203
204 for (header_name, header_value) in header_params {
206 req_builder = req_builder.header(&header_name, &header_value);
207 }
208
209
210 let req = req_builder.build()?;
211 let resp = configuration.client.execute(req).await?;
212
213 let status = resp.status();
214 let content_type = resp
215 .headers()
216 .get("content-type")
217 .and_then(|v| v.to_str().ok())
218 .unwrap_or("application/octet-stream");
219 let content_type = super::ContentType::from(content_type);
220
221 if !status.is_client_error() && !status.is_server_error() {
222 let content = resp.text().await?;
223 match content_type {
224 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
226 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`")))),
227 }
228 } else {
229 let content = resp.text().await?;
230 let entity: Option<SpotGetPingV3Error> = serde_json::from_str(&content).ok();
231 Err(Error::ResponseError(ResponseContent { status, content, entity }))
232 }
233}
234
235pub async fn spot_get_time_v3(configuration: &configuration::Configuration) -> Result<models::SpotGetTimeV3Resp, Error<SpotGetTimeV3Error>> {
237
238 let uri_str = format!("{}/api/v3/time", configuration.base_path);
239 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
240
241 let mut query_params: Vec<(String, String)> = Vec::new();
243
244
245 let mut header_params = std::collections::HashMap::new();
247
248 if let Some(ref binance_auth) = configuration.binance_auth {
250 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
252
253 let body_string: Option<Vec<u8>> = None;
255
256 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
258 Ok(sig) => sig,
259 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
260 };
261
262 query_params.push(("signature".to_string(), signature));
264 }
265
266 if !query_params.is_empty() {
268 req_builder = req_builder.query(&query_params);
269 }
270
271
272 if let Some(ref user_agent) = configuration.user_agent {
274 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275 }
276
277 for (header_name, header_value) in header_params {
279 req_builder = req_builder.header(&header_name, &header_value);
280 }
281
282
283 let req = req_builder.build()?;
284 let resp = configuration.client.execute(req).await?;
285
286 let status = resp.status();
287 let content_type = resp
288 .headers()
289 .get("content-type")
290 .and_then(|v| v.to_str().ok())
291 .unwrap_or("application/octet-stream");
292 let content_type = super::ContentType::from(content_type);
293
294 if !status.is_client_error() && !status.is_server_error() {
295 let content = resp.text().await?;
296 match content_type {
297 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
298 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SpotGetTimeV3Resp`"))),
299 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::SpotGetTimeV3Resp`")))),
300 }
301 } else {
302 let content = resp.text().await?;
303 let entity: Option<SpotGetTimeV3Error> = serde_json::from_str(&content).ok();
304 Err(Error::ResponseError(ResponseContent { status, content, entity }))
305 }
306}
307