binance_sdk/convert/rest_api/mod.rs
1/*
2 * Convert REST API
3 *
4 * Request quotes and execute cryptocurrency conversions via the 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
120 /// upper/lower limits
121 ///
122 /// Weight(IP): 3000
123 ///
124 /// Notes:
125 /// - User needs to supply either or both input parameters.
126 /// - If only one of `fromAsset` and `toAsset` is provided, only partial token pairs are returned.
127 ///
128 /// # Arguments
129 ///
130 /// - `params`: [`ListAllConvertPairsParams`]
131 /// The parameters for this operation.
132 ///
133 /// # Returns
134 ///
135 /// [`RestApiResponse<Vec<models::ListAllConvertPairsResponseInner>>`] on success.
136 ///
137 /// # Errors
138 ///
139 /// This function will return an [`anyhow::Error`] if:
140 /// - the HTTP request fails
141 /// - any parameter is invalid
142 /// - the response cannot be parsed
143 /// - or one of the following occurs:
144 /// - `RequiredError`
145 /// - `ConnectorClientError`
146 /// - `UnauthorizedError`
147 /// - `ForbiddenError`
148 /// - `TooManyRequestsError`
149 /// - `RateLimitBanError`
150 /// - `ServerError`
151 /// - `NotFoundError`
152 /// - `NetworkError`
153 /// - `BadRequestError`
154 ///
155 ///
156 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/market-data#list-all-convert-pairs).
157 ///
158 pub async fn list_all_convert_pairs(
159 &self,
160 params: ListAllConvertPairsParams,
161 ) -> anyhow::Result<RestApiResponse<Vec<models::ListAllConvertPairsResponseInner>>> {
162 self.market_data_api_client
163 .list_all_convert_pairs(params)
164 .await
165 }
166
167 /// Query order quantity precision per asset (`USER_DATA`)
168 ///
169 /// Query for supported asset’s precision information
170 ///
171 /// Weight(IP): 100
172 ///
173 /// Security Type: `USER_DATA`
174 ///
175 /// # Arguments
176 ///
177 /// - `params`: [`QueryOrderQuantityPrecisionPerAssetParams`]
178 /// The parameters for this operation.
179 ///
180 /// # Returns
181 ///
182 /// [`RestApiResponse<Vec<models::QueryOrderQuantityPrecisionPerAssetResponseInner>>`] on success.
183 ///
184 /// # Errors
185 ///
186 /// This function will return an [`anyhow::Error`] if:
187 /// - the HTTP request fails
188 /// - any parameter is invalid
189 /// - the response cannot be parsed
190 /// - or one of the following occurs:
191 /// - `RequiredError`
192 /// - `ConnectorClientError`
193 /// - `UnauthorizedError`
194 /// - `ForbiddenError`
195 /// - `TooManyRequestsError`
196 /// - `RateLimitBanError`
197 /// - `ServerError`
198 /// - `NotFoundError`
199 /// - `NetworkError`
200 /// - `BadRequestError`
201 ///
202 ///
203 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/market-data#query-order-quantity-precision-per-asset).
204 ///
205 pub async fn query_order_quantity_precision_per_asset(
206 &self,
207 params: QueryOrderQuantityPrecisionPerAssetParams,
208 ) -> anyhow::Result<
209 RestApiResponse<Vec<models::QueryOrderQuantityPrecisionPerAssetResponseInner>>,
210 > {
211 self.market_data_api_client
212 .query_order_quantity_precision_per_asset(params)
213 .await
214 }
215
216 /// Accept Quote (TRADE)
217 ///
218 /// Accept the offered quote by quote ID.
219 ///
220 /// Weight(UID): 500
221 ///
222 /// Security Type: TRADE
223 ///
224 /// # Arguments
225 ///
226 /// - `params`: [`AcceptQuoteParams`]
227 /// The parameters for this operation.
228 ///
229 /// # Returns
230 ///
231 /// [`RestApiResponse<models::AcceptQuoteResponse>`] on success.
232 ///
233 /// # Errors
234 ///
235 /// This function will return an [`anyhow::Error`] if:
236 /// - the HTTP request fails
237 /// - any parameter is invalid
238 /// - the response cannot be parsed
239 /// - or one of the following occurs:
240 /// - `RequiredError`
241 /// - `ConnectorClientError`
242 /// - `UnauthorizedError`
243 /// - `ForbiddenError`
244 /// - `TooManyRequestsError`
245 /// - `RateLimitBanError`
246 /// - `ServerError`
247 /// - `NotFoundError`
248 /// - `NetworkError`
249 /// - `BadRequestError`
250 ///
251 ///
252 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#accept-quote).
253 ///
254 pub async fn accept_quote(
255 &self,
256 params: AcceptQuoteParams,
257 ) -> anyhow::Result<RestApiResponse<models::AcceptQuoteResponse>> {
258 self.trade_api_client.accept_quote(params).await
259 }
260
261 /// Cancel limit order (TRADE)
262 ///
263 /// Enable users to cancel a limit order
264 ///
265 /// Weight(UID): 200
266 ///
267 /// Security Type: TRADE
268 ///
269 /// # Arguments
270 ///
271 /// - `params`: [`CancelLimitOrderParams`]
272 /// The parameters for this operation.
273 ///
274 /// # Returns
275 ///
276 /// [`RestApiResponse<models::CancelLimitOrderResponse>`] on success.
277 ///
278 /// # Errors
279 ///
280 /// This function will return an [`anyhow::Error`] if:
281 /// - the HTTP request fails
282 /// - any parameter is invalid
283 /// - the response cannot be parsed
284 /// - or one of the following occurs:
285 /// - `RequiredError`
286 /// - `ConnectorClientError`
287 /// - `UnauthorizedError`
288 /// - `ForbiddenError`
289 /// - `TooManyRequestsError`
290 /// - `RateLimitBanError`
291 /// - `ServerError`
292 /// - `NotFoundError`
293 /// - `NetworkError`
294 /// - `BadRequestError`
295 ///
296 ///
297 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#cancel-limit-order).
298 ///
299 pub async fn cancel_limit_order(
300 &self,
301 params: CancelLimitOrderParams,
302 ) -> anyhow::Result<RestApiResponse<models::CancelLimitOrderResponse>> {
303 self.trade_api_client.cancel_limit_order(params).await
304 }
305
306 /// Get Convert Trade History (`USER_DATA`)
307 ///
308 /// Get Convert Trade History
309 ///
310 /// Weight(UID): 3000
311 ///
312 /// Security Type: `USER_DATA`
313 ///
314 /// Notes:
315 /// - The max interval between `startTime` and `endTime` is 30 days.
316 ///
317 /// # Arguments
318 ///
319 /// - `params`: [`GetConvertTradeHistoryParams`]
320 /// The parameters for this operation.
321 ///
322 /// # Returns
323 ///
324 /// [`RestApiResponse<models::GetConvertTradeHistoryResponse>`] on success.
325 ///
326 /// # Errors
327 ///
328 /// This function will return an [`anyhow::Error`] if:
329 /// - the HTTP request fails
330 /// - any parameter is invalid
331 /// - the response cannot be parsed
332 /// - or one of the following occurs:
333 /// - `RequiredError`
334 /// - `ConnectorClientError`
335 /// - `UnauthorizedError`
336 /// - `ForbiddenError`
337 /// - `TooManyRequestsError`
338 /// - `RateLimitBanError`
339 /// - `ServerError`
340 /// - `NotFoundError`
341 /// - `NetworkError`
342 /// - `BadRequestError`
343 ///
344 ///
345 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#get-convert-trade-history).
346 ///
347 pub async fn get_convert_trade_history(
348 &self,
349 params: GetConvertTradeHistoryParams,
350 ) -> anyhow::Result<RestApiResponse<models::GetConvertTradeHistoryResponse>> {
351 self.trade_api_client
352 .get_convert_trade_history(params)
353 .await
354 }
355
356 /// Order status (`USER_DATA`)
357 ///
358 /// Query order status by order ID.
359 ///
360 /// Weight(UID): 100
361 ///
362 /// Security Type: `USER_DATA`
363 ///
364 /// # Arguments
365 ///
366 /// - `params`: [`OrderStatusParams`]
367 /// The parameters for this operation.
368 ///
369 /// # Returns
370 ///
371 /// [`RestApiResponse<models::OrderStatusResponse>`] on success.
372 ///
373 /// # Errors
374 ///
375 /// This function will return an [`anyhow::Error`] if:
376 /// - the HTTP request fails
377 /// - any parameter is invalid
378 /// - the response cannot be parsed
379 /// - or one of the following occurs:
380 /// - `RequiredError`
381 /// - `ConnectorClientError`
382 /// - `UnauthorizedError`
383 /// - `ForbiddenError`
384 /// - `TooManyRequestsError`
385 /// - `RateLimitBanError`
386 /// - `ServerError`
387 /// - `NotFoundError`
388 /// - `NetworkError`
389 /// - `BadRequestError`
390 ///
391 ///
392 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#order-status).
393 ///
394 pub async fn order_status(
395 &self,
396 params: OrderStatusParams,
397 ) -> anyhow::Result<RestApiResponse<models::OrderStatusResponse>> {
398 self.trade_api_client.order_status(params).await
399 }
400
401 /// Place limit order (TRADE)
402 ///
403 /// Enable users to place a limit order
404 ///
405 /// Weight(UID): 500
406 ///
407 /// Security Type: TRADE
408 ///
409 /// Notes:
410 /// - `baseAsset` and `quoteAsset` can be determined via the `exchangeInfo` endpoint.
411 /// - Limit price is defined from `baseAsset` to `quoteAsset`.
412 /// - Exactly one of `baseAmount` or `quoteAmount` should be sent.
413 ///
414 /// # Arguments
415 ///
416 /// - `params`: [`PlaceLimitOrderParams`]
417 /// The parameters for this operation.
418 ///
419 /// # Returns
420 ///
421 /// [`RestApiResponse<models::PlaceLimitOrderResponse>`] on success.
422 ///
423 /// # Errors
424 ///
425 /// This function will return an [`anyhow::Error`] if:
426 /// - the HTTP request fails
427 /// - any parameter is invalid
428 /// - the response cannot be parsed
429 /// - or one of the following occurs:
430 /// - `RequiredError`
431 /// - `ConnectorClientError`
432 /// - `UnauthorizedError`
433 /// - `ForbiddenError`
434 /// - `TooManyRequestsError`
435 /// - `RateLimitBanError`
436 /// - `ServerError`
437 /// - `NotFoundError`
438 /// - `NetworkError`
439 /// - `BadRequestError`
440 ///
441 ///
442 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#place-limit-order).
443 ///
444 pub async fn place_limit_order(
445 &self,
446 params: PlaceLimitOrderParams,
447 ) -> anyhow::Result<RestApiResponse<models::PlaceLimitOrderResponse>> {
448 self.trade_api_client.place_limit_order(params).await
449 }
450
451 /// Query limit open orders (`USER_DATA`)
452 ///
453 /// Query current open limit orders
454 ///
455 /// Weight(UID): 3000
456 ///
457 /// Security Type: `USER_DATA`
458 ///
459 /// # Arguments
460 ///
461 /// - `params`: [`QueryLimitOpenOrdersParams`]
462 /// The parameters for this operation.
463 ///
464 /// # Returns
465 ///
466 /// [`RestApiResponse<models::QueryLimitOpenOrdersResponse>`] on success.
467 ///
468 /// # Errors
469 ///
470 /// This function will return an [`anyhow::Error`] if:
471 /// - the HTTP request fails
472 /// - any parameter is invalid
473 /// - the response cannot be parsed
474 /// - or one of the following occurs:
475 /// - `RequiredError`
476 /// - `ConnectorClientError`
477 /// - `UnauthorizedError`
478 /// - `ForbiddenError`
479 /// - `TooManyRequestsError`
480 /// - `RateLimitBanError`
481 /// - `ServerError`
482 /// - `NotFoundError`
483 /// - `NetworkError`
484 /// - `BadRequestError`
485 ///
486 ///
487 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#query-limit-open-orders).
488 ///
489 pub async fn query_limit_open_orders(
490 &self,
491 params: QueryLimitOpenOrdersParams,
492 ) -> anyhow::Result<RestApiResponse<models::QueryLimitOpenOrdersResponse>> {
493 self.trade_api_client.query_limit_open_orders(params).await
494 }
495
496 /// Send Quote Request (TRADE)
497 ///
498 /// Request a quote for the requested token pairs
499 ///
500 /// Weight(UID): 200
501 ///
502 /// Security Type: TRADE
503 ///
504 /// Notes:
505 /// - Either `fromAmount` or `toAmount` should be sent.
506 /// - `quoteId` is returned only if you have enough funds to convert.
507 ///
508 /// # Arguments
509 ///
510 /// - `params`: [`SendQuoteRequestParams`]
511 /// The parameters for this operation.
512 ///
513 /// # Returns
514 ///
515 /// [`RestApiResponse<models::SendQuoteRequestResponse>`] on success.
516 ///
517 /// # Errors
518 ///
519 /// This function will return an [`anyhow::Error`] if:
520 /// - the HTTP request fails
521 /// - any parameter is invalid
522 /// - the response cannot be parsed
523 /// - or one of the following occurs:
524 /// - `RequiredError`
525 /// - `ConnectorClientError`
526 /// - `UnauthorizedError`
527 /// - `ForbiddenError`
528 /// - `TooManyRequestsError`
529 /// - `RateLimitBanError`
530 /// - `ServerError`
531 /// - `NotFoundError`
532 /// - `NetworkError`
533 /// - `BadRequestError`
534 ///
535 ///
536 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/core-trading-convert/api/rest-api/trade#send-quote-request).
537 ///
538 pub async fn send_quote_request(
539 &self,
540 params: SendQuoteRequestParams,
541 ) -> anyhow::Result<RestApiResponse<models::SendQuoteRequestResponse>> {
542 self.trade_api_client.send_quote_request(params).await
543 }
544}