binance_sdk/alpha/rest_api/mod.rs
1/*
2 * Alpha Trading REST API
3 *
4 * APIs for Binance Alpha Trading.
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 /// # Arguments
119 ///
120 /// - `params`: [`AggregatedTradesParams`]
121 /// The parameters for this operation.
122 ///
123 /// # Returns
124 ///
125 /// [`RestApiResponse<models::AggregatedTradesResponse>`] on success.
126 ///
127 /// # Errors
128 ///
129 /// This function will return an [`anyhow::Error`] if:
130 /// - the HTTP request fails
131 /// - any parameter is invalid
132 /// - the response cannot be parsed
133 /// - or one of the following occurs:
134 /// - `RequiredError`
135 /// - `ConnectorClientError`
136 /// - `UnauthorizedError`
137 /// - `ForbiddenError`
138 /// - `TooManyRequestsError`
139 /// - `RateLimitBanError`
140 /// - `ServerError`
141 /// - `NotFoundError`
142 /// - `NetworkError`
143 /// - `BadRequestError`
144 ///
145 ///
146 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/advanced-trading-alpha-trading/api/rest-api/market-data#aggregated-trades).
147 ///
148 pub async fn aggregated_trades(
149 &self,
150 params: AggregatedTradesParams,
151 ) -> anyhow::Result<RestApiResponse<models::AggregatedTradesResponse>> {
152 self.market_data_api_client.aggregated_trades(params).await
153 }
154
155 /// Full Depth
156 ///
157 /// Fetches the full order book depth (UI & API orders) for a symbol, including bid and ask orders with their prices and quantities.
158 ///
159 /// # Arguments
160 ///
161 /// - `params`: [`FullDepthParams`]
162 /// The parameters for this operation.
163 ///
164 /// # Returns
165 ///
166 /// [`RestApiResponse<models::FullDepthResponse>`] on success.
167 ///
168 /// # Errors
169 ///
170 /// This function will return an [`anyhow::Error`] if:
171 /// - the HTTP request fails
172 /// - any parameter is invalid
173 /// - the response cannot be parsed
174 /// - or one of the following occurs:
175 /// - `RequiredError`
176 /// - `ConnectorClientError`
177 /// - `UnauthorizedError`
178 /// - `ForbiddenError`
179 /// - `TooManyRequestsError`
180 /// - `RateLimitBanError`
181 /// - `ServerError`
182 /// - `NotFoundError`
183 /// - `NetworkError`
184 /// - `BadRequestError`
185 ///
186 ///
187 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/advanced-trading-alpha-trading/api/rest-api/market-data#full-depth).
188 ///
189 pub async fn full_depth(
190 &self,
191 params: FullDepthParams,
192 ) -> anyhow::Result<RestApiResponse<models::FullDepthResponse>> {
193 self.market_data_api_client.full_depth(params).await
194 }
195
196 /// Get Exchange Info
197 ///
198 /// Fetches general exchange information, such as supported symbols, rate limits, and server time.
199 ///
200 /// # Arguments
201 ///
202 /// - `params`: [`GetExchangeInfoParams`]
203 /// The parameters for this operation.
204 ///
205 /// # Returns
206 ///
207 /// [`RestApiResponse<models::GetExchangeInfoResponse>`] on success.
208 ///
209 /// # Errors
210 ///
211 /// This function will return an [`anyhow::Error`] if:
212 /// - the HTTP request fails
213 /// - any parameter is invalid
214 /// - the response cannot be parsed
215 /// - or one of the following occurs:
216 /// - `RequiredError`
217 /// - `ConnectorClientError`
218 /// - `UnauthorizedError`
219 /// - `ForbiddenError`
220 /// - `TooManyRequestsError`
221 /// - `RateLimitBanError`
222 /// - `ServerError`
223 /// - `NotFoundError`
224 /// - `NetworkError`
225 /// - `BadRequestError`
226 ///
227 ///
228 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/advanced-trading-alpha-trading/api/rest-api/market-data#get-exchange-info).
229 ///
230 pub async fn get_exchange_info(
231 &self,
232 ) -> anyhow::Result<RestApiResponse<models::GetExchangeInfoResponse>> {
233 self.market_data_api_client.get_exchange_info().await
234 }
235
236 /// Klines
237 ///
238 /// Fetches Kline/candlestick bars for a symbol, which include open/high/low/close prices and volume over intervals. Useful for charting and analysis.
239 ///
240 /// # Arguments
241 ///
242 /// - `params`: [`KlinesParams`]
243 /// The parameters for this operation.
244 ///
245 /// # Returns
246 ///
247 /// [`RestApiResponse<models::KlinesResponse>`] on success.
248 ///
249 /// # Errors
250 ///
251 /// This function will return an [`anyhow::Error`] if:
252 /// - the HTTP request fails
253 /// - any parameter is invalid
254 /// - the response cannot be parsed
255 /// - or one of the following occurs:
256 /// - `RequiredError`
257 /// - `ConnectorClientError`
258 /// - `UnauthorizedError`
259 /// - `ForbiddenError`
260 /// - `TooManyRequestsError`
261 /// - `RateLimitBanError`
262 /// - `ServerError`
263 /// - `NotFoundError`
264 /// - `NetworkError`
265 /// - `BadRequestError`
266 ///
267 ///
268 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/advanced-trading-alpha-trading/api/rest-api/market-data#klines).
269 ///
270 pub async fn klines(
271 &self,
272 params: KlinesParams,
273 ) -> anyhow::Result<RestApiResponse<models::KlinesResponse>> {
274 self.market_data_api_client.klines(params).await
275 }
276
277 /// Ticker
278 ///
279 /// Gets the 24-hour rolling window price change statistics for a symbol, including volume and price changes.
280 ///
281 /// # Arguments
282 ///
283 /// - `params`: [`TickerParams`]
284 /// The parameters for this operation.
285 ///
286 /// # Returns
287 ///
288 /// [`RestApiResponse<models::TickerResponse>`] on success.
289 ///
290 /// # Errors
291 ///
292 /// This function will return an [`anyhow::Error`] if:
293 /// - the HTTP request fails
294 /// - any parameter is invalid
295 /// - the response cannot be parsed
296 /// - or one of the following occurs:
297 /// - `RequiredError`
298 /// - `ConnectorClientError`
299 /// - `UnauthorizedError`
300 /// - `ForbiddenError`
301 /// - `TooManyRequestsError`
302 /// - `RateLimitBanError`
303 /// - `ServerError`
304 /// - `NotFoundError`
305 /// - `NetworkError`
306 /// - `BadRequestError`
307 ///
308 ///
309 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/advanced-trading-alpha-trading/api/rest-api/market-data#ticker).
310 ///
311 pub async fn ticker(
312 &self,
313 params: TickerParams,
314 ) -> anyhow::Result<RestApiResponse<models::TickerResponse>> {
315 self.market_data_api_client.ticker(params).await
316 }
317
318 /// Token List
319 ///
320 /// 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.
321 ///
322 /// # Arguments
323 ///
324 /// - `params`: [`TokenListParams`]
325 /// The parameters for this operation.
326 ///
327 /// # Returns
328 ///
329 /// [`RestApiResponse<models::TokenListResponse>`] on success.
330 ///
331 /// # Errors
332 ///
333 /// This function will return an [`anyhow::Error`] if:
334 /// - the HTTP request fails
335 /// - any parameter is invalid
336 /// - the response cannot be parsed
337 /// - or one of the following occurs:
338 /// - `RequiredError`
339 /// - `ConnectorClientError`
340 /// - `UnauthorizedError`
341 /// - `ForbiddenError`
342 /// - `TooManyRequestsError`
343 /// - `RateLimitBanError`
344 /// - `ServerError`
345 /// - `NotFoundError`
346 /// - `NetworkError`
347 /// - `BadRequestError`
348 ///
349 ///
350 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/en/docs/catalog/advanced-trading-alpha-trading/api/rest-api/market-data#token-list).
351 ///
352 pub async fn token_list(&self) -> anyhow::Result<RestApiResponse<models::TokenListResponse>> {
353 self.market_data_api_client.token_list().await
354 }
355}