binance/spot/apis/
futures_data_api.rs

1/*
2 * Binance Spot API
3 *
4 * OpenAPI specification for Binance exchange - Spot API
5 *
6 * The version of the OpenAPI document: 0.3.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::spot::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`get_futures_hist_data_link_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct GetFuturesHistDataLinkV1Params {
20    /// symbol name, e.g. BTCUSDT or BTCUSD_PERP |
21    pub symbol: String,
22    /// `T_DEPTH` for ticklevel orderbook data, `S_DEPTH` for orderbook snapshot data
23    pub data_type: String,
24    pub start_time: i64,
25    pub end_time: i64,
26    pub timestamp: i64,
27    pub recv_window: Option<i64>
28}
29
30
31/// struct for typed errors of method [`get_futures_hist_data_link_v1`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetFuturesHistDataLinkV1Error {
35    Status4XX(models::ApiError),
36    Status5XX(models::ApiError),
37    UnknownValue(serde_json::Value),
38}
39
40
41/// Get Future TickLevel Orderbook Historical Data Download Link
42pub async fn get_futures_hist_data_link_v1(configuration: &configuration::Configuration, params: GetFuturesHistDataLinkV1Params) -> Result<models::GetFuturesHistDataLinkV1Resp, Error<GetFuturesHistDataLinkV1Error>> {
43
44    let uri_str = format!("{}/sapi/v1/futures/histDataLink", configuration.base_path);
45    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
46
47    // Create a mutable vector for query parameters
48    let mut query_params: Vec<(String, String)> = Vec::new();
49
50    query_params.push(("symbol".to_string(), params.symbol.to_string()));
51    query_params.push(("dataType".to_string(), params.data_type.to_string()));
52    query_params.push(("startTime".to_string(), params.start_time.to_string()));
53    query_params.push(("endTime".to_string(), params.end_time.to_string()));
54    if let Some(ref param_value) = params.recv_window {
55        query_params.push(("recvWindow".to_string(), param_value.to_string()));
56    }
57    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
58
59    // Create header parameters collection
60    let mut header_params = std::collections::HashMap::new();
61
62    // Handle Binance Auth first if configured
63    if let Some(ref binance_auth) = configuration.binance_auth {
64        // Add API key to headers
65        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
66        
67        // Generate request body for signing (if any)
68        let body_string: Option<Vec<u8>> = None;
69        
70        // Sign the request
71        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
72            Ok(sig) => sig,
73            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
74        };
75        
76        // Add signature to query params
77        query_params.push(("signature".to_string(), signature));
78    }
79
80    // Apply all query parameters
81    if !query_params.is_empty() {
82        req_builder = req_builder.query(&query_params);
83    }
84
85
86    // Add user agent if configured
87    if let Some(ref user_agent) = configuration.user_agent {
88        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89    }
90
91    // Apply all header parameters
92    for (header_name, header_value) in header_params {
93        req_builder = req_builder.header(&header_name, &header_value);
94    }
95
96
97    let req = req_builder.build()?;
98    let resp = configuration.client.execute(req).await?;
99
100    let status = resp.status();
101    let content_type = resp
102        .headers()
103        .get("content-type")
104        .and_then(|v| v.to_str().ok())
105        .unwrap_or("application/octet-stream");
106    let content_type = super::ContentType::from(content_type);
107
108    if !status.is_client_error() && !status.is_server_error() {
109        let content = resp.text().await?;
110        match content_type {
111            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
112            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetFuturesHistDataLinkV1Resp`"))),
113            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::GetFuturesHistDataLinkV1Resp`")))),
114        }
115    } else {
116        let content = resp.text().await?;
117        let entity: Option<GetFuturesHistDataLinkV1Error> = serde_json::from_str(&content).ok();
118        Err(Error::ResponseError(ResponseContent { status, content, entity }))
119    }
120}
121