binance/spot/apis/
c2c_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_c2c_order_match_list_user_order_history_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct GetC2cOrderMatchListUserOrderHistoryV1Params {
20    pub timestamp: i64,
21    pub start_time: Option<i64>,
22    pub end_time: Option<i64>,
23    /// Default 1
24    pub page: Option<i32>,
25    pub recv_window: Option<i64>
26}
27
28
29/// struct for typed errors of method [`get_c2c_order_match_list_user_order_history_v1`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetC2cOrderMatchListUserOrderHistoryV1Error {
33    Status4XX(models::ApiError),
34    Status5XX(models::ApiError),
35    UnknownValue(serde_json::Value),
36}
37
38
39/// Get C2C Trade History
40pub async fn get_c2c_order_match_list_user_order_history_v1(configuration: &configuration::Configuration, params: GetC2cOrderMatchListUserOrderHistoryV1Params) -> Result<models::GetC2cOrderMatchListUserOrderHistoryV1Resp, Error<GetC2cOrderMatchListUserOrderHistoryV1Error>> {
41
42    let uri_str = format!("{}/sapi/v1/c2c/orderMatch/listUserOrderHistory", configuration.base_path);
43    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45    // Create a mutable vector for query parameters
46    let mut query_params: Vec<(String, String)> = Vec::new();
47
48    if let Some(ref param_value) = params.start_time {
49        query_params.push(("startTime".to_string(), param_value.to_string()));
50    }
51    if let Some(ref param_value) = params.end_time {
52        query_params.push(("endTime".to_string(), param_value.to_string()));
53    }
54    if let Some(ref param_value) = params.page {
55        query_params.push(("page".to_string(), param_value.to_string()));
56    }
57    if let Some(ref param_value) = params.recv_window {
58        query_params.push(("recvWindow".to_string(), param_value.to_string()));
59    }
60    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
61
62    // Create header parameters collection
63    let mut header_params = std::collections::HashMap::new();
64
65    // Handle Binance Auth first if configured
66    if let Some(ref binance_auth) = configuration.binance_auth {
67        // Add API key to headers
68        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
69        
70        // Generate request body for signing (if any)
71        let body_string: Option<Vec<u8>> = None;
72        
73        // Sign the request
74        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
75            Ok(sig) => sig,
76            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
77        };
78        
79        // Add signature to query params
80        query_params.push(("signature".to_string(), signature));
81    }
82
83    // Apply all query parameters
84    if !query_params.is_empty() {
85        req_builder = req_builder.query(&query_params);
86    }
87
88
89    // Add user agent if configured
90    if let Some(ref user_agent) = configuration.user_agent {
91        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92    }
93
94    // Apply all header parameters
95    for (header_name, header_value) in header_params {
96        req_builder = req_builder.header(&header_name, &header_value);
97    }
98
99
100    let req = req_builder.build()?;
101    let resp = configuration.client.execute(req).await?;
102
103    let status = resp.status();
104    let content_type = resp
105        .headers()
106        .get("content-type")
107        .and_then(|v| v.to_str().ok())
108        .unwrap_or("application/octet-stream");
109    let content_type = super::ContentType::from(content_type);
110
111    if !status.is_client_error() && !status.is_server_error() {
112        let content = resp.text().await?;
113        match content_type {
114            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetC2cOrderMatchListUserOrderHistoryV1Resp`"))),
116            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::GetC2cOrderMatchListUserOrderHistoryV1Resp`")))),
117        }
118    } else {
119        let content = resp.text().await?;
120        let entity: Option<GetC2cOrderMatchListUserOrderHistoryV1Error> = serde_json::from_str(&content).ok();
121        Err(Error::ResponseError(ResponseContent { status, content, entity }))
122    }
123}
124