binance/wallet/apis/
others_api.rs

1/*
2 * Binance Wallet API
3 *
4 * OpenAPI specification for Binance exchange - Wallet API
5 *
6 * The version of the OpenAPI document: 0.1.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::wallet::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`wallet_get_system_status_v1`]
19#[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
28/// Fetch system status.
29pub 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    // Create a mutable vector for query parameters
35    let mut query_params: Vec<(String, String)> = Vec::new();
36
37
38    // Create header parameters collection
39    let mut header_params = std::collections::HashMap::new();
40
41    // Handle Binance Auth first if configured
42    if let Some(ref binance_auth) = configuration.binance_auth {
43        // Add API key to headers
44        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
45        
46        // Generate request body for signing (if any)
47        let body_string: Option<Vec<u8>> = None;
48        
49        // Sign the request
50        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        // Add signature to query params
56        query_params.push(("signature".to_string(), signature));
57    }
58
59    // Apply all query parameters
60    if !query_params.is_empty() {
61        req_builder = req_builder.query(&query_params);
62    }
63
64
65    // Add user agent if configured
66    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    // Apply all header parameters
71    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