Skip to main content

binance_sdk/pay/rest_api/
mod.rs

1/*
2 * Binance Pay REST API
3 *
4 * Query Binance Pay transaction history.
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 Pay Trade History
115    ///
116    /// Get Pay Trade History
117    ///
118    /// Weight(UID): 3000
119    ///
120    /// Notes:
121    /// - If `startTime` and `endTime` are not sent, the recent 90 days' data will be returned.
122    /// - The max interval between `startTime` and `endTime` is 90 days.
123    /// - Support for querying orders within the last 18 months.
124    /// - `payerInfo` and `receiverInfo` return different fields in different `orderType` values:
125    /// - C2C sender: `payerInfo=binanceId`; `receiverInfo=name, binanceId/accountId/email/countryCode/phoneNumber/mobileCode` (based on user input).
126    /// - C2C receiver: `payerInfo=name`; `receiverInfo=binanceId`.
127    /// - `CRYPTO_BOX` sender: `payerInfo=binanceId`; `receiverInfo=name` (always `"Crypto Box"`).
128    /// - `CRYPTO_BOX` receiver: `payerInfo=name`; `receiverInfo=binanceId`.
129    /// - PAY sender: `payerInfo=binanceId`; `receiverInfo=name`.
130    /// - PAY receiver: `payerInfo=name`; `receiverInfo=binanceId, name`.
131    /// - `PAY_REFUND` sender: `payerInfo=binanceId, name`; `receiverInfo=name, accountId`.
132    /// - `PAY_REFUND` receiver: `payerInfo=name`; `receiverInfo=binanceId`.
133    /// - PAYOUT sender: `payerInfo=binanceId, name`; `receiverInfo=name, accountId`.
134    /// - PAYOUT receiver: `payerInfo=name`; `receiverInfo=binanceId`.
135    /// - `CRYPTO_BOX_RF` receiver: `payerInfo=name` (always `"Crypto Box"`); `receiverInfo=binanceId`.
136    /// - REMITTANCE sender: `payerInfo=binanceId`; `receiverInfo=name, institutionName, cardNumber, digitalWalletId`.
137    ///
138    /// # Arguments
139    ///
140    /// - `params`: [`GetPayTradeHistoryParams`]
141    ///   The parameters for this operation.
142    ///
143    /// # Returns
144    ///
145    /// [`RestApiResponse<models::GetPayTradeHistoryResponse>`] on success.
146    ///
147    /// # Errors
148    ///
149    /// This function will return an [`anyhow::Error`] if:
150    /// - the HTTP request fails
151    /// - any parameter is invalid
152    /// - the response cannot be parsed
153    /// - or one of the following occurs:
154    ///   - `RequiredError`
155    ///   - `ConnectorClientError`
156    ///   - `UnauthorizedError`
157    ///   - `ForbiddenError`
158    ///   - `TooManyRequestsError`
159    ///   - `RateLimitBanError`
160    ///   - `ServerError`
161    ///   - `NotFoundError`
162    ///   - `NetworkError`
163    ///   - `BadRequestError`
164    ///
165    ///
166    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/investment-and-services-pay/api/rest-api/~#get-pay-trade-history).
167    ///
168    pub async fn get_pay_trade_history(
169        &self,
170        params: GetPayTradeHistoryParams,
171    ) -> anyhow::Result<RestApiResponse<models::GetPayTradeHistoryResponse>> {
172        self.api_client.get_pay_trade_history(params).await
173    }
174}