binance/wallet/apis/
others_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::wallet::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum WalletGetSystemStatusV1Error {
22 Status4XX(models::ApiError),
23 Status5XX(models::ApiError),
24 UnknownValue(serde_json::Value),
25}
26
27
28pub async fn wallet_get_system_status_v1(configuration: &configuration::Configuration) -> Result<models::WalletGetSystemStatusV1Resp, Error<WalletGetSystemStatusV1Error>> {
30
31 let uri_str = format!("{}/sapi/v1/system/status", configuration.base_path);
32 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
33
34 let mut query_params: Vec<(String, String)> = Vec::new();
36
37
38 let mut header_params = std::collections::HashMap::new();
40
41 if let Some(ref binance_auth) = configuration.binance_auth {
43 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
45
46 let body_string: Option<Vec<u8>> = None;
48
49 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
51 Ok(sig) => sig,
52 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
53 };
54
55 query_params.push(("signature".to_string(), signature));
57 }
58
59 if !query_params.is_empty() {
61 req_builder = req_builder.query(&query_params);
62 }
63
64
65 if let Some(ref user_agent) = configuration.user_agent {
67 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68 }
69
70 for (header_name, header_value) in header_params {
72 req_builder = req_builder.header(&header_name, &header_value);
73 }
74
75
76 let req = req_builder.build()?;
77 let resp = configuration.client.execute(req).await?;
78
79 let status = resp.status();
80 let content_type = resp
81 .headers()
82 .get("content-type")
83 .and_then(|v| v.to_str().ok())
84 .unwrap_or("application/octet-stream");
85 let content_type = super::ContentType::from(content_type);
86
87 if !status.is_client_error() && !status.is_server_error() {
88 let content = resp.text().await?;
89 match content_type {
90 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WalletGetSystemStatusV1Resp`"))),
92 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::WalletGetSystemStatusV1Resp`")))),
93 }
94 } else {
95 let content = resp.text().await?;
96 let entity: Option<WalletGetSystemStatusV1Error> = serde_json::from_str(&content).ok();
97 Err(Error::ResponseError(ResponseContent { status, content, entity }))
98 }
99}
100