Skip to main content

binance_sdk/c2c/rest_api/
mod.rs

1/*
2 * Binance C2C REST API
3 *
4 * OpenAPI Specification for the Binance C2C REST API
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 *
9 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
10 * https://openapi-generator.tech
11 * Do not edit the class manually.
12 */
13
14#![allow(unused_imports)]
15use http::Method;
16use serde::de::DeserializeOwned;
17use serde_json::Value;
18use std::collections::BTreeMap;
19
20use crate::common::{config::ConfigurationRestApi, models::RestApiResponse, utils::send_request};
21
22mod apis;
23mod models;
24
25pub use apis::*;
26pub use models::*;
27
28#[derive(Debug, Clone)]
29pub struct RestApi {
30    configuration: ConfigurationRestApi,
31    c2_c_api_client: C2CApiClient,
32}
33
34impl RestApi {
35    pub fn new(configuration: ConfigurationRestApi) -> Self {
36        let c2_c_api_client = C2CApiClient::new(configuration.clone());
37
38        Self {
39            configuration,
40            c2_c_api_client,
41        }
42    }
43
44    /// Send an unsigned request to the API
45    ///
46    /// # Arguments
47    ///
48    /// * `endpoint` - The API endpoint to send the request to
49    /// * `method` - The HTTP method to use for the request
50    /// * `query_params` - A map of query parameters to send with the request
51    /// * `body_params` - A map of body parameters to send with the request
52    ///
53    /// # Returns
54    ///
55    /// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
56    ///
57    /// # Errors
58    ///
59    /// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
60    pub async fn send_request<R: DeserializeOwned + Send + 'static>(
61        &self,
62        endpoint: &str,
63        method: Method,
64        query_params: BTreeMap<String, Value>,
65        body_params: BTreeMap<String, Value>,
66    ) -> anyhow::Result<RestApiResponse<R>> {
67        send_request::<R>(
68            &self.configuration,
69            endpoint,
70            method,
71            query_params,
72            body_params,
73            None,
74            false,
75        )
76        .await
77    }
78
79    /// Send a signed request to the API
80    ///
81    /// # Arguments
82    ///
83    /// * `endpoint` - The API endpoint to send the request to
84    /// * `method` - The HTTP method to use for the request
85    /// * `query_params` - A map of query parameters to send with the request
86    /// * `body_params` - A map of body parameters to send with the request
87    ///
88    /// # Returns
89    ///
90    /// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
91    ///
92    /// # Errors
93    ///
94    /// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
95    pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
96        &self,
97        endpoint: &str,
98        method: Method,
99        query_params: BTreeMap<String, Value>,
100        body_params: BTreeMap<String, Value>,
101    ) -> anyhow::Result<RestApiResponse<R>> {
102        send_request::<R>(
103            &self.configuration,
104            endpoint,
105            method,
106            query_params,
107            body_params,
108            None,
109            true,
110        )
111        .await
112    }
113
114    /// Get C2C Trade History (`USER_DATA`)
115    ///
116    /// Get C2C Trade History
117    ///
118    /// * The max interval between startTimestamp and endTimestamp is 30 days.
119    /// * If startTimestamp and endTimestamp are not sent, the recent 30 days' data will be returned.
120    /// * You can only view data from the past 6 months. To see all C2C orders, please check <https://c2c.binance.com/en/fiatOrder>
121    ///
122    /// Weight: 1
123    ///
124    /// # Arguments
125    ///
126    /// - `params`: [`GetC2CTradeHistoryParams`]
127    ///   The parameters for this operation.
128    ///
129    /// # Returns
130    ///
131    /// [`RestApiResponse<models::GetC2CTradeHistoryResponse>`] on success.
132    ///
133    /// # Errors
134    ///
135    /// This function will return an [`anyhow::Error`] if:
136    /// - the HTTP request fails
137    /// - any parameter is invalid
138    /// - the response cannot be parsed
139    /// - or one of the following occurs:
140    ///   - `RequiredError`
141    ///   - `ConnectorClientError`
142    ///   - `UnauthorizedError`
143    ///   - `ForbiddenError`
144    ///   - `TooManyRequestsError`
145    ///   - `RateLimitBanError`
146    ///   - `ServerError`
147    ///   - `NotFoundError`
148    ///   - `NetworkError`
149    ///   - `BadRequestError`
150    ///
151    ///
152    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/c2c/rest-api/Get-C2C-Trade-History).
153    ///
154    pub async fn get_c2_c_trade_history(
155        &self,
156        params: GetC2CTradeHistoryParams,
157    ) -> anyhow::Result<RestApiResponse<models::GetC2CTradeHistoryResponse>> {
158        self.c2_c_api_client.get_c2_c_trade_history(params).await
159    }
160}