binance/spot/apis/
copy_trading_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_copy_trading_futures_lead_symbol_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct GetCopyTradingFuturesLeadSymbolV1Params {
20    pub timestamp: i64,
21    pub recv_window: Option<i64>
22}
23
24/// struct for passing parameters to the method [`get_copy_trading_futures_user_status_v1`]
25#[derive(Clone, Debug, Default)]
26pub struct GetCopyTradingFuturesUserStatusV1Params {
27    pub timestamp: i64,
28    pub recv_window: Option<i64>
29}
30
31
32/// struct for typed errors of method [`get_copy_trading_futures_lead_symbol_v1`]
33#[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/// struct for typed errors of method [`get_copy_trading_futures_user_status_v1`]
42#[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
51/// Get Futures Lead Trading Symbol Whitelist
52pub 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    // Create a mutable vector for query parameters
58    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    // Create header parameters collection
66    let mut header_params = std::collections::HashMap::new();
67
68    // Handle Binance Auth first if configured
69    if let Some(ref binance_auth) = configuration.binance_auth {
70        // Add API key to headers
71        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
72        
73        // Generate request body for signing (if any)
74        let body_string: Option<Vec<u8>> = None;
75        
76        // Sign the request
77        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        // Add signature to query params
83        query_params.push(("signature".to_string(), signature));
84    }
85
86    // Apply all query parameters
87    if !query_params.is_empty() {
88        req_builder = req_builder.query(&query_params);
89    }
90
91
92    // Add user agent if configured
93    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    // Apply all header parameters
98    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
128/// Get Futures Lead Trader Status
129pub 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    // Create a mutable vector for query parameters
135    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    // Create header parameters collection
143    let mut header_params = std::collections::HashMap::new();
144
145    // Handle Binance Auth first if configured
146    if let Some(ref binance_auth) = configuration.binance_auth {
147        // Add API key to headers
148        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
149        
150        // Generate request body for signing (if any)
151        let body_string: Option<Vec<u8>> = None;
152        
153        // Sign the request
154        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        // Add signature to query params
160        query_params.push(("signature".to_string(), signature));
161    }
162
163    // Apply all query parameters
164    if !query_params.is_empty() {
165        req_builder = req_builder.query(&query_params);
166    }
167
168
169    // Add user agent if configured
170    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    // Apply all header parameters
175    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