Skip to main content

binance_sdk/pay/rest_api/
mod.rs

1/*
2 * Binance Pay REST API
3 *
4 * OpenAPI Specification for the Binance Pay 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    pay_api_client: PayApiClient,
32}
33
34impl RestApi {
35    pub fn new(configuration: ConfigurationRestApi) -> Self {
36        let pay_api_client = PayApiClient::new(configuration.clone());
37
38        Self {
39            configuration,
40            pay_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 Pay Trade History
115    ///
116    /// Get Pay Trade History
117    ///
118    /// * If startTime and endTime are not sent, the recent 90 days' data will be returned.
119    /// * The max interval between startTime and endTime is 90 days.
120    /// * Support for querying orders within the last 18 months.
121    /// * For payerInfo and receiverInfo,there are different return values in different orderTypes.
122    /// * Sender's perspective when orderType is C2C
123    /// * payerInfo : binanceId
124    /// * receiverInfo : name, binanceId/accountId/email/countryCode/phoneNumber/mobileCode (based on user input)
125    /// * Receiver's perspective when orderType is C2C
126    /// * payerInfo : name
127    /// * receiverInfo : binanceId
128    /// * Sender's perspective when orderType is `CRYPTO_BOX`
129    /// * payerInfo : binanceId
130    /// * receiverInfo : name(the value is always "Crypto Box")
131    /// * Receiver's perspective when orderType is `CRYPTO_BOX`
132    /// * payerInfo : name
133    /// * receiverInfo : binanceId
134    /// * Sender's perspective when orderType is PAY
135    /// * payerInfo : binanceId
136    /// * receiverInfo : name
137    /// * Receiver's perspective when orderType is PAY
138    /// * payerInfo : name
139    /// * receiverInfo : binanceId, name
140    /// * Sender's perspective when orderType is `PAY_REFUND`
141    /// * payerInfo : binanceId, name
142    /// * receiverInfo : name, accountId
143    /// * Receiver's perspective when orderType is `PAY_REFUND`
144    /// * payerInfo : name
145    /// * receiverInfo :  binanceId
146    /// * Sender's perspective when orderType is PAYOUT
147    /// * payerInfo : binanceId, name
148    /// * receiverInfo : name, accountId
149    /// * Receiver's perspective when orderType is PAYOUT
150    /// * payerInfo : name
151    /// * receiverInfo :  binanceId
152    /// * Receiver's perspective when orderType is `CRYPTO_BOX_RF`
153    /// * payerInfo : name(the value is always "Crypto Box")
154    /// * receiverInfo : binanceId
155    /// * Sender's perspective when orderType is REMITTANCE
156    /// * payerInfo : binanceId
157    /// * receiverInfo : name, institutionName, cardNumber, digitalWalletId
158    ///
159    /// Weight: 3000
160    ///
161    /// # Arguments
162    ///
163    /// - `params`: [`GetPayTradeHistoryParams`]
164    ///   The parameters for this operation.
165    ///
166    /// # Returns
167    ///
168    /// [`RestApiResponse<models::GetPayTradeHistoryResponse>`] on success.
169    ///
170    /// # Errors
171    ///
172    /// This function will return an [`anyhow::Error`] if:
173    /// - the HTTP request fails
174    /// - any parameter is invalid
175    /// - the response cannot be parsed
176    /// - or one of the following occurs:
177    ///   - `RequiredError`
178    ///   - `ConnectorClientError`
179    ///   - `UnauthorizedError`
180    ///   - `ForbiddenError`
181    ///   - `TooManyRequestsError`
182    ///   - `RateLimitBanError`
183    ///   - `ServerError`
184    ///   - `NotFoundError`
185    ///   - `NetworkError`
186    ///   - `BadRequestError`
187    ///
188    ///
189    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/pay/rest-api/Get-Pay-Trade-History).
190    ///
191    pub async fn get_pay_trade_history(
192        &self,
193        params: GetPayTradeHistoryParams,
194    ) -> anyhow::Result<RestApiResponse<models::GetPayTradeHistoryResponse>> {
195        self.pay_api_client.get_pay_trade_history(params).await
196    }
197}