Skip to main content

binance_sdk/convert/rest_api/
mod.rs

1/*
2 * Binance Convert REST API
3 *
4 * OpenAPI Specification for the Binance Convert 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    market_data_api_client: MarketDataApiClient,
32    trade_api_client: TradeApiClient,
33}
34
35impl RestApi {
36    pub fn new(configuration: ConfigurationRestApi) -> Self {
37        let market_data_api_client = MarketDataApiClient::new(configuration.clone());
38        let trade_api_client = TradeApiClient::new(configuration.clone());
39
40        Self {
41            configuration,
42            market_data_api_client,
43            trade_api_client,
44        }
45    }
46
47    /// Send an unsigned request to the API
48    ///
49    /// # Arguments
50    ///
51    /// * `endpoint` - The API endpoint to send the request to
52    /// * `method` - The HTTP method to use for the request
53    /// * `query_params` - A map of query parameters to send with the request
54    /// * `body_params` - A map of body parameters to send with the request
55    ///
56    /// # Returns
57    ///
58    /// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
59    ///
60    /// # Errors
61    ///
62    /// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
63    pub async fn send_request<R: DeserializeOwned + Send + 'static>(
64        &self,
65        endpoint: &str,
66        method: Method,
67        query_params: BTreeMap<String, Value>,
68        body_params: BTreeMap<String, Value>,
69    ) -> anyhow::Result<RestApiResponse<R>> {
70        send_request::<R>(
71            &self.configuration,
72            endpoint,
73            method,
74            query_params,
75            body_params,
76            None,
77            false,
78        )
79        .await
80    }
81
82    /// Send a signed request to the API
83    ///
84    /// # Arguments
85    ///
86    /// * `endpoint` - The API endpoint to send the request to
87    /// * `method` - The HTTP method to use for the request
88    /// * `query_params` - A map of query parameters to send with the request
89    /// * `body_params` - A map of body parameters to send with the request
90    ///
91    /// # Returns
92    ///
93    /// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
94    ///
95    /// # Errors
96    ///
97    /// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
98    pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
99        &self,
100        endpoint: &str,
101        method: Method,
102        query_params: BTreeMap<String, Value>,
103        body_params: BTreeMap<String, Value>,
104    ) -> anyhow::Result<RestApiResponse<R>> {
105        send_request::<R>(
106            &self.configuration,
107            endpoint,
108            method,
109            query_params,
110            body_params,
111            None,
112            true,
113        )
114        .await
115    }
116
117    /// List All Convert Pairs
118    ///
119    /// Query for all convertible token pairs and the tokens’ respective upper/lower limits
120    ///
121    /// * User needs to supply either or both of the input parameter
122    /// * If not defined for both fromAsset and toAsset, only partial token pairs will be returned
123    ///
124    /// Weight: 3000(IP)
125    ///
126    /// # Arguments
127    ///
128    /// - `params`: [`ListAllConvertPairsParams`]
129    ///   The parameters for this operation.
130    ///
131    /// # Returns
132    ///
133    /// [`RestApiResponse<Vec<models::ListAllConvertPairsResponseInner>>`] on success.
134    ///
135    /// # Errors
136    ///
137    /// This function will return an [`anyhow::Error`] if:
138    /// - the HTTP request fails
139    /// - any parameter is invalid
140    /// - the response cannot be parsed
141    /// - or one of the following occurs:
142    ///   - `RequiredError`
143    ///   - `ConnectorClientError`
144    ///   - `UnauthorizedError`
145    ///   - `ForbiddenError`
146    ///   - `TooManyRequestsError`
147    ///   - `RateLimitBanError`
148    ///   - `ServerError`
149    ///   - `NotFoundError`
150    ///   - `NetworkError`
151    ///   - `BadRequestError`
152    ///
153    ///
154    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/market-data/).
155    ///
156    pub async fn list_all_convert_pairs(
157        &self,
158        params: ListAllConvertPairsParams,
159    ) -> anyhow::Result<RestApiResponse<Vec<models::ListAllConvertPairsResponseInner>>> {
160        self.market_data_api_client
161            .list_all_convert_pairs(params)
162            .await
163    }
164
165    /// Query order quantity precision per `asset(USER_DATA)`
166    ///
167    /// Query for supported asset’s precision information
168    ///
169    /// Weight: 100(IP)
170    ///
171    /// # Arguments
172    ///
173    /// - `params`: [`QueryOrderQuantityPrecisionPerAssetParams`]
174    ///   The parameters for this operation.
175    ///
176    /// # Returns
177    ///
178    /// [`RestApiResponse<Vec<models::QueryOrderQuantityPrecisionPerAssetResponseInner>>`] on success.
179    ///
180    /// # Errors
181    ///
182    /// This function will return an [`anyhow::Error`] if:
183    /// - the HTTP request fails
184    /// - any parameter is invalid
185    /// - the response cannot be parsed
186    /// - or one of the following occurs:
187    ///   - `RequiredError`
188    ///   - `ConnectorClientError`
189    ///   - `UnauthorizedError`
190    ///   - `ForbiddenError`
191    ///   - `TooManyRequestsError`
192    ///   - `RateLimitBanError`
193    ///   - `ServerError`
194    ///   - `NotFoundError`
195    ///   - `NetworkError`
196    ///   - `BadRequestError`
197    ///
198    ///
199    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset).
200    ///
201    pub async fn query_order_quantity_precision_per_asset(
202        &self,
203        params: QueryOrderQuantityPrecisionPerAssetParams,
204    ) -> anyhow::Result<
205        RestApiResponse<Vec<models::QueryOrderQuantityPrecisionPerAssetResponseInner>>,
206    > {
207        self.market_data_api_client
208            .query_order_quantity_precision_per_asset(params)
209            .await
210    }
211
212    /// Accept Quote (TRADE)
213    ///
214    /// Accept the offered quote by quote ID.
215    ///
216    /// Weight: 500(UID)
217    ///
218    /// # Arguments
219    ///
220    /// - `params`: [`AcceptQuoteParams`]
221    ///   The parameters for this operation.
222    ///
223    /// # Returns
224    ///
225    /// [`RestApiResponse<models::AcceptQuoteResponse>`] on success.
226    ///
227    /// # Errors
228    ///
229    /// This function will return an [`anyhow::Error`] if:
230    /// - the HTTP request fails
231    /// - any parameter is invalid
232    /// - the response cannot be parsed
233    /// - or one of the following occurs:
234    ///   - `RequiredError`
235    ///   - `ConnectorClientError`
236    ///   - `UnauthorizedError`
237    ///   - `ForbiddenError`
238    ///   - `TooManyRequestsError`
239    ///   - `RateLimitBanError`
240    ///   - `ServerError`
241    ///   - `NotFoundError`
242    ///   - `NetworkError`
243    ///   - `BadRequestError`
244    ///
245    ///
246    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Accept-Quote).
247    ///
248    pub async fn accept_quote(
249        &self,
250        params: AcceptQuoteParams,
251    ) -> anyhow::Result<RestApiResponse<models::AcceptQuoteResponse>> {
252        self.trade_api_client.accept_quote(params).await
253    }
254
255    /// Cancel limit order (`USER_DATA`)
256    ///
257    /// Enable users to cancel a limit order
258    ///
259    /// Weight: 200(UID)
260    ///
261    /// # Arguments
262    ///
263    /// - `params`: [`CancelLimitOrderParams`]
264    ///   The parameters for this operation.
265    ///
266    /// # Returns
267    ///
268    /// [`RestApiResponse<models::CancelLimitOrderResponse>`] on success.
269    ///
270    /// # Errors
271    ///
272    /// This function will return an [`anyhow::Error`] if:
273    /// - the HTTP request fails
274    /// - any parameter is invalid
275    /// - the response cannot be parsed
276    /// - or one of the following occurs:
277    ///   - `RequiredError`
278    ///   - `ConnectorClientError`
279    ///   - `UnauthorizedError`
280    ///   - `ForbiddenError`
281    ///   - `TooManyRequestsError`
282    ///   - `RateLimitBanError`
283    ///   - `ServerError`
284    ///   - `NotFoundError`
285    ///   - `NetworkError`
286    ///   - `BadRequestError`
287    ///
288    ///
289    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Cancel-Order).
290    ///
291    pub async fn cancel_limit_order(
292        &self,
293        params: CancelLimitOrderParams,
294    ) -> anyhow::Result<RestApiResponse<models::CancelLimitOrderResponse>> {
295        self.trade_api_client.cancel_limit_order(params).await
296    }
297
298    /// Get Convert Trade `History(USER_DATA)`
299    ///
300    /// Get Convert Trade History
301    ///
302    /// * The max interval between startTime and endTime is 30 days.
303    ///
304    /// Weight: 3000
305    ///
306    /// # Arguments
307    ///
308    /// - `params`: [`GetConvertTradeHistoryParams`]
309    ///   The parameters for this operation.
310    ///
311    /// # Returns
312    ///
313    /// [`RestApiResponse<models::GetConvertTradeHistoryResponse>`] on success.
314    ///
315    /// # Errors
316    ///
317    /// This function will return an [`anyhow::Error`] if:
318    /// - the HTTP request fails
319    /// - any parameter is invalid
320    /// - the response cannot be parsed
321    /// - or one of the following occurs:
322    ///   - `RequiredError`
323    ///   - `ConnectorClientError`
324    ///   - `UnauthorizedError`
325    ///   - `ForbiddenError`
326    ///   - `TooManyRequestsError`
327    ///   - `RateLimitBanError`
328    ///   - `ServerError`
329    ///   - `NotFoundError`
330    ///   - `NetworkError`
331    ///   - `BadRequestError`
332    ///
333    ///
334    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History).
335    ///
336    pub async fn get_convert_trade_history(
337        &self,
338        params: GetConvertTradeHistoryParams,
339    ) -> anyhow::Result<RestApiResponse<models::GetConvertTradeHistoryResponse>> {
340        self.trade_api_client
341            .get_convert_trade_history(params)
342            .await
343    }
344
345    /// Order `status(USER_DATA)`
346    ///
347    /// Query order status by order ID.
348    ///
349    /// Weight: 100(UID)
350    ///
351    /// # Arguments
352    ///
353    /// - `params`: [`OrderStatusParams`]
354    ///   The parameters for this operation.
355    ///
356    /// # Returns
357    ///
358    /// [`RestApiResponse<models::OrderStatusResponse>`] on success.
359    ///
360    /// # Errors
361    ///
362    /// This function will return an [`anyhow::Error`] if:
363    /// - the HTTP request fails
364    /// - any parameter is invalid
365    /// - the response cannot be parsed
366    /// - or one of the following occurs:
367    ///   - `RequiredError`
368    ///   - `ConnectorClientError`
369    ///   - `UnauthorizedError`
370    ///   - `ForbiddenError`
371    ///   - `TooManyRequestsError`
372    ///   - `RateLimitBanError`
373    ///   - `ServerError`
374    ///   - `NotFoundError`
375    ///   - `NetworkError`
376    ///   - `BadRequestError`
377    ///
378    ///
379    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Order-Status).
380    ///
381    pub async fn order_status(
382        &self,
383        params: OrderStatusParams,
384    ) -> anyhow::Result<RestApiResponse<models::OrderStatusResponse>> {
385        self.trade_api_client.order_status(params).await
386    }
387
388    /// Place limit order (`USER_DATA`)
389    ///
390    /// Enable users to place a limit order
391    ///
392    /// * `baseAsset` or `quoteAsset` can be determined via `exchangeInfo` endpoint.
393    /// * Limit price is defined from `baseAsset` to `quoteAsset`.
394    /// * Either `baseAmount` or `quoteAmount` is used.
395    ///
396    /// Weight: 500(UID)
397    ///
398    /// # Arguments
399    ///
400    /// - `params`: [`PlaceLimitOrderParams`]
401    ///   The parameters for this operation.
402    ///
403    /// # Returns
404    ///
405    /// [`RestApiResponse<models::PlaceLimitOrderResponse>`] on success.
406    ///
407    /// # Errors
408    ///
409    /// This function will return an [`anyhow::Error`] if:
410    /// - the HTTP request fails
411    /// - any parameter is invalid
412    /// - the response cannot be parsed
413    /// - or one of the following occurs:
414    ///   - `RequiredError`
415    ///   - `ConnectorClientError`
416    ///   - `UnauthorizedError`
417    ///   - `ForbiddenError`
418    ///   - `TooManyRequestsError`
419    ///   - `RateLimitBanError`
420    ///   - `ServerError`
421    ///   - `NotFoundError`
422    ///   - `NetworkError`
423    ///   - `BadRequestError`
424    ///
425    ///
426    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Place-Order).
427    ///
428    pub async fn place_limit_order(
429        &self,
430        params: PlaceLimitOrderParams,
431    ) -> anyhow::Result<RestApiResponse<models::PlaceLimitOrderResponse>> {
432        self.trade_api_client.place_limit_order(params).await
433    }
434
435    /// Query limit open orders (`USER_DATA`)
436    ///
437    /// Request a quote for the requested token pairs
438    ///
439    /// Weight: 3000(UID)
440    ///
441    /// # Arguments
442    ///
443    /// - `params`: [`QueryLimitOpenOrdersParams`]
444    ///   The parameters for this operation.
445    ///
446    /// # Returns
447    ///
448    /// [`RestApiResponse<models::QueryLimitOpenOrdersResponse>`] on success.
449    ///
450    /// # Errors
451    ///
452    /// This function will return an [`anyhow::Error`] if:
453    /// - the HTTP request fails
454    /// - any parameter is invalid
455    /// - the response cannot be parsed
456    /// - or one of the following occurs:
457    ///   - `RequiredError`
458    ///   - `ConnectorClientError`
459    ///   - `UnauthorizedError`
460    ///   - `ForbiddenError`
461    ///   - `TooManyRequestsError`
462    ///   - `RateLimitBanError`
463    ///   - `ServerError`
464    ///   - `NotFoundError`
465    ///   - `NetworkError`
466    ///   - `BadRequestError`
467    ///
468    ///
469    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Query-Order).
470    ///
471    pub async fn query_limit_open_orders(
472        &self,
473        params: QueryLimitOpenOrdersParams,
474    ) -> anyhow::Result<RestApiResponse<models::QueryLimitOpenOrdersResponse>> {
475        self.trade_api_client.query_limit_open_orders(params).await
476    }
477
478    /// Send Quote `Request(USER_DATA)`
479    ///
480    /// Request a quote for the requested token pairs
481    ///
482    /// * Either fromAmount or toAmount should be sent
483    /// * `quoteId` will be returned only if you have enough funds to convert
484    ///
485    /// Weight: 200(UID)
486    ///
487    /// # Arguments
488    ///
489    /// - `params`: [`SendQuoteRequestParams`]
490    ///   The parameters for this operation.
491    ///
492    /// # Returns
493    ///
494    /// [`RestApiResponse<models::SendQuoteRequestResponse>`] on success.
495    ///
496    /// # Errors
497    ///
498    /// This function will return an [`anyhow::Error`] if:
499    /// - the HTTP request fails
500    /// - any parameter is invalid
501    /// - the response cannot be parsed
502    /// - or one of the following occurs:
503    ///   - `RequiredError`
504    ///   - `ConnectorClientError`
505    ///   - `UnauthorizedError`
506    ///   - `ForbiddenError`
507    ///   - `TooManyRequestsError`
508    ///   - `RateLimitBanError`
509    ///   - `ServerError`
510    ///   - `NotFoundError`
511    ///   - `NetworkError`
512    ///   - `BadRequestError`
513    ///
514    ///
515    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/convert/trade/Send-quote-request).
516    ///
517    pub async fn send_quote_request(
518        &self,
519        params: SendQuoteRequestParams,
520    ) -> anyhow::Result<RestApiResponse<models::SendQuoteRequestResponse>> {
521        self.trade_api_client.send_quote_request(params).await
522    }
523}