Skip to main content

binance_sdk/alpha/rest_api/
mod.rs

1/*
2 * Binance Alpha REST API
3 *
4 * OpenAPI Specification for the Binance Alpha 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}
33
34impl RestApi {
35    pub fn new(configuration: ConfigurationRestApi) -> Self {
36        let market_data_api_client = MarketDataApiClient::new(configuration.clone());
37
38        Self {
39            configuration,
40            market_data_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    /// Aggregated Trades
115    ///
116    /// Retrieves compressed, aggregated historical trades for a specific symbol. Useful for recent trade history.
117    ///
118    /// Weight: 0
119    ///
120    /// # Arguments
121    ///
122    /// - `params`: [`AggregatedTradesParams`]
123    ///   The parameters for this operation.
124    ///
125    /// # Returns
126    ///
127    /// [`RestApiResponse<models::AggregatedTradesResponse>`] on success.
128    ///
129    /// # Errors
130    ///
131    /// This function will return an [`anyhow::Error`] if:
132    /// - the HTTP request fails
133    /// - any parameter is invalid
134    /// - the response cannot be parsed
135    /// - or one of the following occurs:
136    ///   - `RequiredError`
137    ///   - `ConnectorClientError`
138    ///   - `UnauthorizedError`
139    ///   - `ForbiddenError`
140    ///   - `TooManyRequestsError`
141    ///   - `RateLimitBanError`
142    ///   - `ServerError`
143    ///   - `NotFoundError`
144    ///   - `NetworkError`
145    ///   - `BadRequestError`
146    ///
147    ///
148    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/alpha/market-data/rest-api/Aggregated-Trades).
149    ///
150    pub async fn aggregated_trades(
151        &self,
152        params: AggregatedTradesParams,
153    ) -> anyhow::Result<RestApiResponse<models::AggregatedTradesResponse>> {
154        self.market_data_api_client.aggregated_trades(params).await
155    }
156
157    /// Get Exchange Info
158    ///
159    /// Fetches general exchange information, such as supported symbols, rate limits, and server time.
160    ///
161    /// Weight: 0
162    ///
163    /// # Arguments
164    ///
165    /// - `params`: [`GetExchangeInfoParams`]
166    ///   The parameters for this operation.
167    ///
168    /// # Returns
169    ///
170    /// [`RestApiResponse<models::GetExchangeInfoResponse>`] on success.
171    ///
172    /// # Errors
173    ///
174    /// This function will return an [`anyhow::Error`] if:
175    /// - the HTTP request fails
176    /// - any parameter is invalid
177    /// - the response cannot be parsed
178    /// - or one of the following occurs:
179    ///   - `RequiredError`
180    ///   - `ConnectorClientError`
181    ///   - `UnauthorizedError`
182    ///   - `ForbiddenError`
183    ///   - `TooManyRequestsError`
184    ///   - `RateLimitBanError`
185    ///   - `ServerError`
186    ///   - `NotFoundError`
187    ///   - `NetworkError`
188    ///   - `BadRequestError`
189    ///
190    ///
191    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/alpha/market-data/rest-api/Get-Exchange-Info).
192    ///
193    pub async fn get_exchange_info(
194        &self,
195    ) -> anyhow::Result<RestApiResponse<models::GetExchangeInfoResponse>> {
196        self.market_data_api_client.get_exchange_info().await
197    }
198
199    /// Klines (Candlestick Data)
200    ///
201    /// Fetches Kline/candlestick bars for a symbol, which include open/high/low/close prices and volume over intervals. Useful for charting and analysis.
202    ///
203    /// Weight: 0
204    ///
205    /// # Arguments
206    ///
207    /// - `params`: [`KlinesParams`]
208    ///   The parameters for this operation.
209    ///
210    /// # Returns
211    ///
212    /// [`RestApiResponse<models::KlinesResponse>`] on success.
213    ///
214    /// # Errors
215    ///
216    /// This function will return an [`anyhow::Error`] if:
217    /// - the HTTP request fails
218    /// - any parameter is invalid
219    /// - the response cannot be parsed
220    /// - or one of the following occurs:
221    ///   - `RequiredError`
222    ///   - `ConnectorClientError`
223    ///   - `UnauthorizedError`
224    ///   - `ForbiddenError`
225    ///   - `TooManyRequestsError`
226    ///   - `RateLimitBanError`
227    ///   - `ServerError`
228    ///   - `NotFoundError`
229    ///   - `NetworkError`
230    ///   - `BadRequestError`
231    ///
232    ///
233    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/alpha/market-data/rest-api/Klines).
234    ///
235    pub async fn klines(
236        &self,
237        params: KlinesParams,
238    ) -> anyhow::Result<RestApiResponse<models::KlinesResponse>> {
239        self.market_data_api_client.klines(params).await
240    }
241
242    /// Ticker (24hr Price Statistics)
243    ///
244    /// Gets the 24-hour rolling window price change statistics for a symbol, including volume and price changes.
245    ///
246    /// Weight: 0
247    ///
248    /// # Arguments
249    ///
250    /// - `params`: [`TickerParams`]
251    ///   The parameters for this operation.
252    ///
253    /// # Returns
254    ///
255    /// [`RestApiResponse<models::TickerResponse>`] on success.
256    ///
257    /// # Errors
258    ///
259    /// This function will return an [`anyhow::Error`] if:
260    /// - the HTTP request fails
261    /// - any parameter is invalid
262    /// - the response cannot be parsed
263    /// - or one of the following occurs:
264    ///   - `RequiredError`
265    ///   - `ConnectorClientError`
266    ///   - `UnauthorizedError`
267    ///   - `ForbiddenError`
268    ///   - `TooManyRequestsError`
269    ///   - `RateLimitBanError`
270    ///   - `ServerError`
271    ///   - `NotFoundError`
272    ///   - `NetworkError`
273    ///   - `BadRequestError`
274    ///
275    ///
276    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/alpha/market-data/rest-api/24hr-ticker-price-change).
277    ///
278    pub async fn ticker(
279        &self,
280        params: TickerParams,
281    ) -> anyhow::Result<RestApiResponse<models::TickerResponse>> {
282        self.market_data_api_client.ticker(params).await
283    }
284
285    /// Token List
286    ///
287    /// Retrieves a list of all available ALPHA tokens, including their IDs and symbols. Use this to find the token ID for constructing symbols in other endpoints.
288    ///
289    /// Weight: 0
290    ///
291    /// # Arguments
292    ///
293    /// - `params`: [`TokenListParams`]
294    ///   The parameters for this operation.
295    ///
296    /// # Returns
297    ///
298    /// [`RestApiResponse<models::TokenListResponse>`] on success.
299    ///
300    /// # Errors
301    ///
302    /// This function will return an [`anyhow::Error`] if:
303    /// - the HTTP request fails
304    /// - any parameter is invalid
305    /// - the response cannot be parsed
306    /// - or one of the following occurs:
307    ///   - `RequiredError`
308    ///   - `ConnectorClientError`
309    ///   - `UnauthorizedError`
310    ///   - `ForbiddenError`
311    ///   - `TooManyRequestsError`
312    ///   - `RateLimitBanError`
313    ///   - `ServerError`
314    ///   - `NotFoundError`
315    ///   - `NetworkError`
316    ///   - `BadRequestError`
317    ///
318    ///
319    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/alpha/market-data/rest-api/Token-List).
320    ///
321    pub async fn token_list(&self) -> anyhow::Result<RestApiResponse<models::TokenListResponse>> {
322        self.market_data_api_client.token_list().await
323    }
324}