binance_sdk/c2c/rest_api/mod.rs
1/*
2 * C2C REST API
3 *
4 * Query fiat transaction history via the 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 api_client: ApiClient,
32}
33
34impl RestApi {
35 pub fn new(configuration: ConfigurationRestApi) -> Self {
36 let api_client = ApiClient::new(configuration.clone());
37
38 Self {
39 configuration,
40 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 /// Weight(IP): 1
119 ///
120 /// Security Type: `USER_DATA`
121 ///
122 /// Notes:
123 /// - The max interval between `startTimestamp` and `endTimestamp` is 30 days.
124 /// - If `startTimestamp` and `endTimestamp` are not sent, the recent 30 days' data is returned.
125 /// - You can only view data from the past 6 months. For all C2C orders, check `https://c2c.binance.com/en/fiatOrder`.
126 ///
127 /// # Arguments
128 ///
129 /// - `params`: [`GetC2CTradeHistoryParams`]
130 /// The parameters for this operation.
131 ///
132 /// # Returns
133 ///
134 /// [`RestApiResponse<models::GetC2CTradeHistoryResponse>`] on success.
135 ///
136 /// # Errors
137 ///
138 /// This function will return an [`anyhow::Error`] if:
139 /// - the HTTP request fails
140 /// - any parameter is invalid
141 /// - the response cannot be parsed
142 /// - or one of the following occurs:
143 /// - `RequiredError`
144 /// - `ConnectorClientError`
145 /// - `UnauthorizedError`
146 /// - `ForbiddenError`
147 /// - `TooManyRequestsError`
148 /// - `RateLimitBanError`
149 /// - `ServerError`
150 /// - `NotFoundError`
151 /// - `NetworkError`
152 /// - `BadRequestError`
153 ///
154 ///
155 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/investment-and-services-c2-c/api/rest-api/~#get-c2-ctrade-history).
156 ///
157 pub async fn get_c2_c_trade_history(
158 &self,
159 params: GetC2CTradeHistoryParams,
160 ) -> anyhow::Result<RestApiResponse<models::GetC2CTradeHistoryResponse>> {
161 self.api_client.get_c2_c_trade_history(params).await
162 }
163}