binance_sdk/spot/websocket_api/mod.rs
1/*
2 * Binance Spot WebSocket API
3 *
4 * OpenAPI Specifications for the Binance Spot WebSocket API
5 *
6 * API documents:
7 * - [Github web-socket-api documentation file](https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-api.md)
8 * - [General API information for web-socket-api on website](https://developers.binance.com/docs/binance-spot-api-docs/web-socket-api/general-api-information)
9 *
10 *
11 * The version of the OpenAPI document: 1.0.0
12 *
13 *
14 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
15 * https://openapi-generator.tech
16 * Do not edit the class manually.
17 */
18
19#![allow(unused_imports)]
20use serde::de::DeserializeOwned;
21use serde_json::Value;
22use std::{collections::BTreeMap, sync::Arc};
23
24use crate::common::config::ConfigurationWebsocketApi;
25use crate::common::models::WebsocketApiResponse;
26use crate::common::utils::random_string;
27use crate::common::websocket::{
28 Subscription, WebsocketApi as WebsocketApiBase, WebsocketBase, WebsocketMessageSendOptions,
29 WebsocketStream, create_stream_handler,
30};
31use crate::errors::WebsocketError;
32use crate::models::{WebsocketEvent, WebsocketMode};
33
34mod apis;
35mod handle;
36mod models;
37
38pub use apis::*;
39pub use handle::*;
40pub use models::*;
41
42const HAS_TIME_UNIT: bool = true;
43
44#[derive(Clone)]
45pub struct WebsocketApi {
46 websocket_api_base: Arc<WebsocketApiBase>,
47
48 account_api_client: AccountApiClient,
49 auth_api_client: AuthApiClient,
50 general_api_client: GeneralApiClient,
51 market_api_client: MarketApiClient,
52 trade_api_client: TradeApiClient,
53 user_data_stream_api_client: UserDataStreamApiClient,
54}
55
56impl WebsocketApi {
57 pub(crate) async fn connect(
58 config: ConfigurationWebsocketApi,
59 mode: Option<WebsocketMode>,
60 ) -> anyhow::Result<Self> {
61 let mut cfg = config;
62 if let Some(m) = mode {
63 cfg.mode = m;
64 }
65 if !HAS_TIME_UNIT {
66 cfg.time_unit = None;
67 }
68
69 let websocket_api_base = WebsocketApiBase::new(cfg, vec![]);
70 websocket_api_base.clone().connect().await?;
71
72 Ok(Self {
73 websocket_api_base: websocket_api_base.clone(),
74 account_api_client: AccountApiClient::new(websocket_api_base.clone()),
75 auth_api_client: AuthApiClient::new(websocket_api_base.clone()),
76 general_api_client: GeneralApiClient::new(websocket_api_base.clone()),
77 market_api_client: MarketApiClient::new(websocket_api_base.clone()),
78 trade_api_client: TradeApiClient::new(websocket_api_base.clone()),
79 user_data_stream_api_client: UserDataStreamApiClient::new(websocket_api_base.clone()),
80 })
81 }
82
83 /// Subscribes to WebSocket events with a provided callback function.
84 ///
85 /// # Arguments
86 ///
87 /// * `callback` - A mutable function that will be called when a WebSocket event is received.
88 /// The callback takes a `WebsocketEvent` as its parameter.
89 ///
90 /// # Returns
91 ///
92 /// A `Subscription` that can be used to manage the event subscription.
93 ///
94 /// # Examples
95 ///
96 ///
97 /// let subscription = `websocket_api.subscribe_on_ws_events(|event`| {
98 /// // Handle WebSocket event
99 /// });
100 ///
101 pub fn subscribe_on_ws_events<F>(&self, callback: F) -> Subscription
102 where
103 F: FnMut(WebsocketEvent) + Send + 'static,
104 {
105 let base = Arc::clone(&self.websocket_api_base);
106 base.common.events.subscribe(callback)
107 }
108
109 /// Unsubscribes from WebSocket events using the provided `Subscription`.
110 ///
111 /// # Arguments
112 ///
113 /// * `subscription` - The `Subscription` to unsubscribe from WebSocket events.
114 ///
115 /// # Examples
116 ///
117 ///
118 /// let subscription = `websocket_api.subscribe_on_ws_events(|event`| {
119 /// // Handle WebSocket event
120 /// });
121 /// `websocket_api.unsubscribe_from_ws_events(subscription)`;
122 ///
123 pub fn unsubscribe_from_ws_events(&self, subscription: Subscription) {
124 subscription.unsubscribe();
125 }
126
127 /// Disconnects the WebSocket connection.
128 ///
129 /// # Returns
130 ///
131 /// A `Result` indicating whether the disconnection was successful.
132 /// Returns an error if the disconnection fails.
133 ///
134 /// # Errors
135 ///
136 /// Returns an [`anyhow::Error`] if the connection fails.
137 ///
138 /// # Examples
139 ///
140 ///
141 /// let result = `websocket_api.disconnect().await`;
142 ///
143 pub async fn disconnect(&self) -> anyhow::Result<()> {
144 self.websocket_api_base
145 .disconnect()
146 .await
147 .map_err(anyhow::Error::msg)
148 }
149
150 /// Sends a ping message to the WebSocket server to check the connection status.
151 ///
152 /// # Examples
153 ///
154 ///
155 /// `websocket_api.ping_server().await`;
156 ///
157 ///
158 /// This method sends a lightweight ping request to verify the WebSocket connection is still active.
159 pub async fn ping_server(&self) {
160 self.websocket_api_base.ping_server().await;
161 }
162
163 /// Checks if the WebSocket connection is currently active.
164 ///
165 /// # Returns
166 ///
167 /// A `bool` indicating whether the WebSocket connection is established and active.
168 ///
169 /// # Examples
170 ///
171 ///
172 /// let `is_active` = `websocket_api.is_connected().await`;
173 /// if `is_active` {
174 /// // WebSocket connection is active
175 /// }
176 ///
177 ///
178 /// This method provides a way to check the current status of the WebSocket connection.
179 pub async fn is_connected(&self) -> bool {
180 self.websocket_api_base.is_connected().await
181 }
182
183 /// Sends an unsigned WebSocket message with the specified method and payload.
184 ///
185 /// # Type Parameters
186 ///
187 /// * `R` - The response type to deserialize the message into.
188 ///
189 /// # Arguments
190 ///
191 /// * `method` - The WebSocket method to invoke.
192 /// * `payload` - A map of key-value pairs representing the message payload.
193 ///
194 /// # Returns
195 ///
196 /// A `Result` containing the deserialized response or a `WebsocketError`.
197 ///
198 /// # Errors
199 ///
200 /// Returns a `WebsocketError` if the WebSocket connection fails or the response cannot be deserialized.
201 ///
202 /// # Examples
203 ///
204 ///
205 /// let response = `websocket_api.send_message::`<ResponseType>("`method_name`", payload).await;
206 ///
207 pub async fn send_message<R: DeserializeOwned + Send + Sync + 'static>(
208 &self,
209 method: &str,
210 payload: BTreeMap<String, Value>,
211 ) -> Result<WebsocketApiResponse<R>, WebsocketError> {
212 self.websocket_api_base
213 .send_message::<R>(method, payload, WebsocketMessageSendOptions::new())
214 .await?
215 .into_iter()
216 .next()
217 .ok_or(WebsocketError::NoResponse)
218 }
219
220 /// Sends a signed WebSocket message with the specified method and payload.
221 ///
222 /// # Type Parameters
223 ///
224 /// * `R` - The response type to deserialize the message into.
225 ///
226 /// # Arguments
227 ///
228 /// * `method` - The WebSocket method to invoke.
229 /// * `payload` - A map of key-value pairs representing the message payload.
230 ///
231 /// # Returns
232 ///
233 /// A `Result` containing the deserialized response or a `WebsocketError`.
234 ///
235 /// # Errors
236 ///
237 /// Returns a `WebsocketError` if the WebSocket connection fails or the response cannot be deserialized.
238 ///
239 /// # Examples
240 ///
241 ///
242 /// let response = `websocket_api.send_signed_message::`<ResponseType>("`method_name`", payload).await;
243 ///
244 pub async fn send_signed_message<R: DeserializeOwned + Send + Sync + 'static>(
245 &self,
246 method: &str,
247 payload: BTreeMap<String, Value>,
248 ) -> Result<WebsocketApiResponse<R>, WebsocketError> {
249 self.websocket_api_base
250 .send_message::<R>(method, payload, WebsocketMessageSendOptions::new().signed())
251 .await?
252 .into_iter()
253 .next()
254 .ok_or(WebsocketError::NoResponse)
255 }
256
257 /// WebSocket Account Commission Rates
258 ///
259 /// Get current account commission rates.
260 /// Weight: 20
261 ///
262 /// # Arguments
263 ///
264 /// - `params`: [`AccountCommissionParams`]
265 /// The parameters for this operation.
266 ///
267 /// # Returns
268 ///
269 /// [`WebsocketApiResponse<Box<models::AccountCommissionResponseResult>>`] on success.
270 ///
271 /// # Errors
272 ///
273 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
274 ///
275 ///
276 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-commission-rates-user_data).
277 ///
278 pub async fn account_commission(
279 &self,
280 params: AccountCommissionParams,
281 ) -> anyhow::Result<WebsocketApiResponse<Box<models::AccountCommissionResponseResult>>> {
282 self.account_api_client.account_commission(params).await
283 }
284
285 /// WebSocket Unfilled Order Count
286 ///
287 /// Query your current unfilled order count for all intervals.
288 /// Weight: 40
289 ///
290 /// # Arguments
291 ///
292 /// - `params`: [`AccountRateLimitsOrdersParams`]
293 /// The parameters for this operation.
294 ///
295 /// # Returns
296 ///
297 /// [`WebsocketApiResponse<Vec<models::AccountRateLimitsOrdersResponseResultInner>>`] on success.
298 ///
299 /// # Errors
300 ///
301 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
302 ///
303 ///
304 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#unfilled-order-count-user_data).
305 ///
306 pub async fn account_rate_limits_orders(
307 &self,
308 params: AccountRateLimitsOrdersParams,
309 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::AccountRateLimitsOrdersResponseResultInner>>>
310 {
311 self.account_api_client
312 .account_rate_limits_orders(params)
313 .await
314 }
315
316 /// WebSocket Account information
317 ///
318 /// Query information about your account.
319 /// Weight: 20
320 ///
321 /// # Arguments
322 ///
323 /// - `params`: [`AccountStatusParams`]
324 /// The parameters for this operation.
325 ///
326 /// # Returns
327 ///
328 /// [`WebsocketApiResponse<Box<models::AccountStatusResponseResult>>`] on success.
329 ///
330 /// # Errors
331 ///
332 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
333 ///
334 ///
335 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-information-user_data).
336 ///
337 pub async fn account_status(
338 &self,
339 params: AccountStatusParams,
340 ) -> anyhow::Result<WebsocketApiResponse<Box<models::AccountStatusResponseResult>>> {
341 self.account_api_client.account_status(params).await
342 }
343
344 /// WebSocket Account order list history
345 ///
346 /// Query information about all your order lists, filtered by time range.
347 /// Weight: 20
348 ///
349 /// # Arguments
350 ///
351 /// - `params`: [`AllOrderListsParams`]
352 /// The parameters for this operation.
353 ///
354 /// # Returns
355 ///
356 /// [`WebsocketApiResponse<Vec<models::AllOrderListsResponseResultInner>>`] on success.
357 ///
358 /// # Errors
359 ///
360 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
361 ///
362 ///
363 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-order-list-history-user_data).
364 ///
365 pub async fn all_order_lists(
366 &self,
367 params: AllOrderListsParams,
368 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::AllOrderListsResponseResultInner>>> {
369 self.account_api_client.all_order_lists(params).await
370 }
371
372 /// WebSocket Account order history
373 ///
374 /// Query information about all your orders – active, canceled, filled – filtered by time range.
375 /// Weight: 20
376 ///
377 /// # Arguments
378 ///
379 /// - `params`: [`AllOrdersParams`]
380 /// The parameters for this operation.
381 ///
382 /// # Returns
383 ///
384 /// [`WebsocketApiResponse<Vec<models::AllOrdersResponseResultInner>>`] on success.
385 ///
386 /// # Errors
387 ///
388 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
389 ///
390 ///
391 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-order-history-user_data).
392 ///
393 pub async fn all_orders(
394 &self,
395 params: AllOrdersParams,
396 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::AllOrdersResponseResultInner>>> {
397 self.account_api_client.all_orders(params).await
398 }
399
400 /// WebSocket Account allocations
401 ///
402 /// Retrieves allocations resulting from SOR order placement.
403 /// Weight: 20
404 ///
405 /// # Arguments
406 ///
407 /// - `params`: [`MyAllocationsParams`]
408 /// The parameters for this operation.
409 ///
410 /// # Returns
411 ///
412 /// [`WebsocketApiResponse<Vec<models::MyAllocationsResponseResultInner>>`] on success.
413 ///
414 /// # Errors
415 ///
416 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
417 ///
418 ///
419 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-allocations-user_data).
420 ///
421 pub async fn my_allocations(
422 &self,
423 params: MyAllocationsParams,
424 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::MyAllocationsResponseResultInner>>> {
425 self.account_api_client.my_allocations(params).await
426 }
427
428 /// WebSocket Query Relevant Filters
429 ///
430 /// Retrieves the list of [filters](filters.md) relevant to an account on a given symbol. This is the only method that shows if an account has `MAX_ASSET` filters applied to it.
431 /// Weight: 40
432 ///
433 /// # Arguments
434 ///
435 /// - `params`: [`MyFiltersParams`]
436 /// The parameters for this operation.
437 ///
438 /// # Returns
439 ///
440 /// [`WebsocketApiResponse<Box<models::MyFiltersResponseResult>>`] on success.
441 ///
442 /// # Errors
443 ///
444 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
445 ///
446 ///
447 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#query-relevant-filters-user_data).
448 ///
449 pub async fn my_filters(
450 &self,
451 params: MyFiltersParams,
452 ) -> anyhow::Result<WebsocketApiResponse<Box<models::MyFiltersResponseResult>>> {
453 self.account_api_client.my_filters(params).await
454 }
455
456 /// WebSocket Account prevented matches
457 ///
458 /// Displays the list of orders that were expired due to STP.
459 ///
460 /// These are the combinations supported:
461 ///
462 /// * `symbol` + `preventedMatchId`
463 /// * `symbol` + `orderId`
464 /// * `symbol` + `orderId` + `fromPreventedMatchId` (`limit` will default to 500)
465 /// * `symbol` + `orderId` + `fromPreventedMatchId` + `limit`
466 /// Weight: Case | Weight
467 /// ---- | -----
468 /// If `symbol` is invalid | 2
469 /// Querying by `preventedMatchId` | 2
470 /// Querying by `orderId` | 20
471 ///
472 /// # Arguments
473 ///
474 /// - `params`: [`MyPreventedMatchesParams`]
475 /// The parameters for this operation.
476 ///
477 /// # Returns
478 ///
479 /// [`WebsocketApiResponse<Vec<models::MyPreventedMatchesResponseResultInner>>`] on success.
480 ///
481 /// # Errors
482 ///
483 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
484 ///
485 ///
486 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-prevented-matches-user_data).
487 ///
488 pub async fn my_prevented_matches(
489 &self,
490 params: MyPreventedMatchesParams,
491 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::MyPreventedMatchesResponseResultInner>>>
492 {
493 self.account_api_client.my_prevented_matches(params).await
494 }
495
496 /// WebSocket Account trade history
497 ///
498 /// Query information about all your trades, filtered by time range.
499 /// Weight: Condition| Weight|
500 /// ---| ---
501 /// |Without orderId|20|
502 /// |With orderId|5|
503 ///
504 /// # Arguments
505 ///
506 /// - `params`: [`MyTradesParams`]
507 /// The parameters for this operation.
508 ///
509 /// # Returns
510 ///
511 /// [`WebsocketApiResponse<Vec<models::MyTradesResponseResultInner>>`] on success.
512 ///
513 /// # Errors
514 ///
515 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
516 ///
517 ///
518 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#account-trade-history-user_data).
519 ///
520 pub async fn my_trades(
521 &self,
522 params: MyTradesParams,
523 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::MyTradesResponseResultInner>>> {
524 self.account_api_client.my_trades(params).await
525 }
526
527 /// WebSocket Current open Order lists
528 ///
529 /// Query execution status of all open order lists.
530 ///
531 /// If you need to continuously monitor order status updates, please consider using WebSocket Streams:
532 ///
533 /// * `userDataStream.start` request
534 /// * `executionReport` user data stream event
535 /// Weight: 6
536 ///
537 /// # Arguments
538 ///
539 /// - `params`: [`OpenOrderListsStatusParams`]
540 /// The parameters for this operation.
541 ///
542 /// # Returns
543 ///
544 /// [`WebsocketApiResponse<Vec<models::OpenOrderListsStatusResponseResultInner>>`] on success.
545 ///
546 /// # Errors
547 ///
548 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
549 ///
550 ///
551 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#current-open-order-lists-user_data).
552 ///
553 pub async fn open_order_lists_status(
554 &self,
555 params: OpenOrderListsStatusParams,
556 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::OpenOrderListsStatusResponseResultInner>>>
557 {
558 self.account_api_client
559 .open_order_lists_status(params)
560 .await
561 }
562
563 /// WebSocket Current open orders
564 ///
565 /// Query execution status of all open orders.
566 ///
567 /// If you need to continuously monitor order status updates, please consider using WebSocket Streams:
568 ///
569 /// * `userDataStream.start` request
570 /// * `executionReport` user data stream event
571 /// Weight: Adjusted based on the number of requested symbols:
572 ///
573 /// | Parameter | Weight |
574 /// | --------- | ------ |
575 /// | `symbol` | 6 |
576 /// | none | 80 |
577 ///
578 /// # Arguments
579 ///
580 /// - `params`: [`OpenOrdersStatusParams`]
581 /// The parameters for this operation.
582 ///
583 /// # Returns
584 ///
585 /// [`WebsocketApiResponse<Vec<models::OpenOrdersStatusResponseResultInner>>`] on success.
586 ///
587 /// # Errors
588 ///
589 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
590 ///
591 ///
592 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#current-open-orders-user_data).
593 ///
594 pub async fn open_orders_status(
595 &self,
596 params: OpenOrdersStatusParams,
597 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::OpenOrdersStatusResponseResultInner>>>
598 {
599 self.account_api_client.open_orders_status(params).await
600 }
601
602 /// WebSocket Query Order Amendments
603 ///
604 /// Queries all amendments of a single order.
605 /// Weight: 4
606 ///
607 /// # Arguments
608 ///
609 /// - `params`: [`OrderAmendmentsParams`]
610 /// The parameters for this operation.
611 ///
612 /// # Returns
613 ///
614 /// [`WebsocketApiResponse<Vec<models::OrderAmendmentsResponseResultInner>>`] on success.
615 ///
616 /// # Errors
617 ///
618 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
619 ///
620 ///
621 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#query-order-amendments-user_data).
622 ///
623 pub async fn order_amendments(
624 &self,
625 params: OrderAmendmentsParams,
626 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::OrderAmendmentsResponseResultInner>>> {
627 self.account_api_client.order_amendments(params).await
628 }
629
630 /// WebSocket Query Order list
631 ///
632 /// Check execution status of an Order list.
633 ///
634 /// For execution status of individual orders, use `order.status`.
635 /// Weight: 4
636 ///
637 /// # Arguments
638 ///
639 /// - `params`: [`OrderListStatusParams`]
640 /// The parameters for this operation.
641 ///
642 /// # Returns
643 ///
644 /// [`WebsocketApiResponse<Box<models::AllOrderListsResponseResultInner>>`] on success.
645 ///
646 /// # Errors
647 ///
648 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
649 ///
650 ///
651 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#query-order-list-user_data).
652 ///
653 pub async fn order_list_status(
654 &self,
655 params: OrderListStatusParams,
656 ) -> anyhow::Result<WebsocketApiResponse<Box<models::AllOrderListsResponseResultInner>>> {
657 self.account_api_client.order_list_status(params).await
658 }
659
660 /// WebSocket Query order
661 ///
662 /// Check execution status of an order.
663 /// Weight: 4
664 ///
665 /// # Arguments
666 ///
667 /// - `params`: [`OrderStatusParams`]
668 /// The parameters for this operation.
669 ///
670 /// # Returns
671 ///
672 /// [`WebsocketApiResponse<Box<models::OrderStatusResponseResult>>`] on success.
673 ///
674 /// # Errors
675 ///
676 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
677 ///
678 ///
679 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/account-requests#query-order-user_data).
680 ///
681 pub async fn order_status(
682 &self,
683 params: OrderStatusParams,
684 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderStatusResponseResult>>> {
685 self.account_api_client.order_status(params).await
686 }
687
688 /// WebSocket Log in with API key
689 ///
690 /// Authenticate WebSocket connection using the provided API key.
691 ///
692 /// After calling `session.logon`, you can omit `apiKey` and `signature` parameters for future requests that require them.
693 ///
694 /// Note that only one API key can be authenticated.
695 /// Calling `session.logon` multiple times changes the current authenticated API key.
696 /// Weight: 2
697 ///
698 /// # Arguments
699 ///
700 /// - `params`: [`SessionLogonParams`]
701 /// The parameters for this operation.
702 ///
703 /// # Returns
704 ///
705 /// [`WebsocketApiResponse<Box<models::SessionLogonResponseResult>>`] on success.
706 ///
707 /// # Errors
708 ///
709 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
710 ///
711 ///
712 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/authentication-requests#log-in-with-api-key-signed).
713 ///
714 pub async fn session_logon(
715 &self,
716 params: SessionLogonParams,
717 ) -> anyhow::Result<Vec<WebsocketApiResponse<Box<models::SessionLogonResponseResult>>>> {
718 self.auth_api_client.session_logon(params).await
719 }
720
721 /// WebSocket Log out of the session
722 ///
723 /// Forget the API key previously authenticated.
724 /// If the connection is not authenticated, this request does nothing.
725 ///
726 /// Note that the WebSocket connection stays open after `session.logout` request.
727 /// You can continue using the connection,
728 /// but now you will have to explicitly provide the `apiKey` and `signature` parameters where needed.
729 /// Weight: 2
730 ///
731 /// # Arguments
732 ///
733 /// - `params`: [`SessionLogoutParams`]
734 /// The parameters for this operation.
735 ///
736 /// # Returns
737 ///
738 /// [`WebsocketApiResponse<Box<models::SessionLogoutResponseResult>>`] on success.
739 ///
740 /// # Errors
741 ///
742 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
743 ///
744 ///
745 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/authentication-requests#log-out-of-the-session).
746 ///
747 pub async fn session_logout(
748 &self,
749 params: SessionLogoutParams,
750 ) -> anyhow::Result<Vec<WebsocketApiResponse<Box<models::SessionLogoutResponseResult>>>> {
751 self.auth_api_client.session_logout(params).await
752 }
753
754 /// WebSocket Query session status
755 ///
756 /// Query the status of the WebSocket connection,
757 /// inspecting which API key (if any) is used to authorize requests.
758 /// Weight: 2
759 ///
760 /// # Arguments
761 ///
762 /// - `params`: [`SessionStatusParams`]
763 /// The parameters for this operation.
764 ///
765 /// # Returns
766 ///
767 /// [`WebsocketApiResponse<Box<models::SessionStatusResponseResult>>`] on success.
768 ///
769 /// # Errors
770 ///
771 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
772 ///
773 ///
774 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/authentication-requests#query-session-status).
775 ///
776 pub async fn session_status(
777 &self,
778 params: SessionStatusParams,
779 ) -> anyhow::Result<WebsocketApiResponse<Box<models::SessionStatusResponseResult>>> {
780 self.auth_api_client.session_status(params).await
781 }
782
783 /// WebSocket Exchange information
784 ///
785 /// Query current exchange trading rules, rate limits, and symbol information.
786 /// Weight: 20
787 ///
788 /// # Arguments
789 ///
790 /// - `params`: [`ExchangeInfoParams`]
791 /// The parameters for this operation.
792 ///
793 /// # Returns
794 ///
795 /// [`WebsocketApiResponse<Box<models::ExchangeInfoResponseResult>>`] on success.
796 ///
797 /// # Errors
798 ///
799 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
800 ///
801 ///
802 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#exchange-information).
803 ///
804 pub async fn exchange_info(
805 &self,
806 params: ExchangeInfoParams,
807 ) -> anyhow::Result<WebsocketApiResponse<Box<models::ExchangeInfoResponseResult>>> {
808 self.general_api_client.exchange_info(params).await
809 }
810
811 /// WebSocket Query Execution Rules
812 ///
813 ///
814 /// Weight: Parameter | Weight|
815 /// --- | ---
816 /// `symbol` | 2
817 /// `symbols` | 2 for each `symbol`, capped at a max of 40|
818 /// `symbolStatus` |40|
819 /// None |40|
820 ///
821 /// # Arguments
822 ///
823 /// - `params`: [`ExecutionRulesParams`]
824 /// The parameters for this operation.
825 ///
826 /// # Returns
827 ///
828 /// [`WebsocketApiResponse<Box<models::ExecutionRulesResponseResult>>`] on success.
829 ///
830 /// # Errors
831 ///
832 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
833 ///
834 ///
835 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#query-execution-rules).
836 ///
837 pub async fn execution_rules(
838 &self,
839 params: ExecutionRulesParams,
840 ) -> anyhow::Result<WebsocketApiResponse<Box<models::ExecutionRulesResponseResult>>> {
841 self.general_api_client.execution_rules(params).await
842 }
843
844 /// WebSocket Test connectivity
845 ///
846 /// Test connectivity to the WebSocket API.
847 /// Weight: 1
848 ///
849 /// # Arguments
850 ///
851 /// - `params`: [`PingParams`]
852 /// The parameters for this operation.
853 ///
854 /// # Returns
855 ///
856 /// [`WebsocketApiResponse<serde_json::Value>`] on success.
857 ///
858 /// # Errors
859 ///
860 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
861 ///
862 ///
863 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#test-connectivity).
864 ///
865 pub async fn ping(
866 &self,
867 params: PingParams,
868 ) -> anyhow::Result<WebsocketApiResponse<serde_json::Value>> {
869 self.general_api_client.ping(params).await
870 }
871
872 /// WebSocket Check server time
873 ///
874 /// Test connectivity to the WebSocket API and get the current server time.
875 /// Weight: 1
876 ///
877 /// # Arguments
878 ///
879 /// - `params`: [`TimeParams`]
880 /// The parameters for this operation.
881 ///
882 /// # Returns
883 ///
884 /// [`WebsocketApiResponse<Box<models::TimeResponseResult>>`] on success.
885 ///
886 /// # Errors
887 ///
888 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
889 ///
890 ///
891 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/general-requests#check-server-time).
892 ///
893 pub async fn time(
894 &self,
895 params: TimeParams,
896 ) -> anyhow::Result<WebsocketApiResponse<Box<models::TimeResponseResult>>> {
897 self.general_api_client.time(params).await
898 }
899
900 /// WebSocket Current average price
901 ///
902 /// Get current average price for a symbol.
903 /// Weight: 2
904 ///
905 /// # Arguments
906 ///
907 /// - `params`: [`AvgPriceParams`]
908 /// The parameters for this operation.
909 ///
910 /// # Returns
911 ///
912 /// [`WebsocketApiResponse<Box<models::AvgPriceResponseResult>>`] on success.
913 ///
914 /// # Errors
915 ///
916 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
917 ///
918 ///
919 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#current-average-price).
920 ///
921 pub async fn avg_price(
922 &self,
923 params: AvgPriceParams,
924 ) -> anyhow::Result<WebsocketApiResponse<Box<models::AvgPriceResponseResult>>> {
925 self.market_api_client.avg_price(params).await
926 }
927
928 /// WebSocket Historical Block Trades
929 ///
930 /// Get block trades.
931 /// Weight: 25
932 ///
933 /// # Arguments
934 ///
935 /// - `params`: [`BlockTradesHistoricalParams`]
936 /// The parameters for this operation.
937 ///
938 /// # Returns
939 ///
940 /// [`WebsocketApiResponse<Vec<models::BlockTradesHistoricalResponseResultInner>>`] on success.
941 ///
942 /// # Errors
943 ///
944 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
945 ///
946 ///
947 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#historical-block-trades).
948 ///
949 pub async fn block_trades_historical(
950 &self,
951 params: BlockTradesHistoricalParams,
952 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::BlockTradesHistoricalResponseResultInner>>>
953 {
954 self.market_api_client.block_trades_historical(params).await
955 }
956
957 /// WebSocket Order book
958 ///
959 /// Get current order book.
960 ///
961 /// Note that this request returns limited market depth.
962 ///
963 /// If you need to continuously monitor order book updates, please consider using WebSocket Streams:
964 ///
965 /// * `<symbol>@depth<levels>`
966 /// * `<symbol>@depth`
967 ///
968 /// You can use `depth` request together with `<symbol>@depth` streams to [maintain a local order book](web-socket-streams.md#how-to-manage-a-local-order-book-correctly).
969 /// Weight: Adjusted based on the limit:
970 ///
971 /// | Limit | Weight |
972 /// |:---------:|:------:|
973 /// | 1–100 | 5 |
974 /// | 101–500 | 25|
975 /// | 501–1000 | 50 |
976 /// | 1001–5000 | 250 |
977 ///
978 /// # Arguments
979 ///
980 /// - `params`: [`DepthParams`]
981 /// The parameters for this operation.
982 ///
983 /// # Returns
984 ///
985 /// [`WebsocketApiResponse<Box<models::DepthResponseResult>>`] on success.
986 ///
987 /// # Errors
988 ///
989 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
990 ///
991 ///
992 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#order-book).
993 ///
994 pub async fn depth(
995 &self,
996 params: DepthParams,
997 ) -> anyhow::Result<WebsocketApiResponse<Box<models::DepthResponseResult>>> {
998 self.market_api_client.depth(params).await
999 }
1000
1001 /// WebSocket Klines
1002 ///
1003 /// Get klines (candlestick bars).
1004 ///
1005 /// Klines are uniquely identified by their open & close time.
1006 ///
1007 /// If you need access to real-time kline updates, please consider using WebSocket Streams:
1008 ///
1009 /// * `<symbol>@kline_<interval>`
1010 ///
1011 /// If you need historical kline data,
1012 /// please consider using [data.binance.vision](https://github.com/binance/binance-public-data/#klines).
1013 /// Weight: 2
1014 ///
1015 /// # Arguments
1016 ///
1017 /// - `params`: [`KlinesParams`]
1018 /// The parameters for this operation.
1019 ///
1020 /// # Returns
1021 ///
1022 /// [`WebsocketApiResponse<Vec<Vec<models::KlinesItemInner>>>`] on success.
1023 ///
1024 /// # Errors
1025 ///
1026 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1027 ///
1028 ///
1029 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#klines).
1030 ///
1031 pub async fn klines(
1032 &self,
1033 params: KlinesParams,
1034 ) -> anyhow::Result<WebsocketApiResponse<Vec<Vec<models::KlinesItemInner>>>> {
1035 self.market_api_client.klines(params).await
1036 }
1037
1038 /// WebSocket Query Reference Price
1039 ///
1040 ///
1041 /// Weight: 2
1042 ///
1043 /// # Arguments
1044 ///
1045 /// - `params`: [`ReferencePriceParams`]
1046 /// The parameters for this operation.
1047 ///
1048 /// # Returns
1049 ///
1050 /// [`WebsocketApiResponse<Box<models::ReferencePriceResponseResult>>`] on success.
1051 ///
1052 /// # Errors
1053 ///
1054 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1055 ///
1056 ///
1057 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#query-reference-price).
1058 ///
1059 pub async fn reference_price(
1060 &self,
1061 params: ReferencePriceParams,
1062 ) -> anyhow::Result<WebsocketApiResponse<Box<models::ReferencePriceResponseResult>>> {
1063 self.market_api_client.reference_price(params).await
1064 }
1065
1066 /// WebSocket Query Reference Price Calculation
1067 ///
1068 /// Describes how reference price is calculated for a given symbol.
1069 /// Weight: 2
1070 ///
1071 /// # Arguments
1072 ///
1073 /// - `params`: [`ReferencePriceCalculationParams`]
1074 /// The parameters for this operation.
1075 ///
1076 /// # Returns
1077 ///
1078 /// [`WebsocketApiResponse<Box<models::ReferencePriceCalculationResponseResult>>`] on success.
1079 ///
1080 /// # Errors
1081 ///
1082 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1083 ///
1084 ///
1085 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#query-reference-price-calculation).
1086 ///
1087 pub async fn reference_price_calculation(
1088 &self,
1089 params: ReferencePriceCalculationParams,
1090 ) -> anyhow::Result<WebsocketApiResponse<Box<models::ReferencePriceCalculationResponseResult>>>
1091 {
1092 self.market_api_client
1093 .reference_price_calculation(params)
1094 .await
1095 }
1096
1097 /// WebSocket Rolling window price change statistics
1098 ///
1099 /// Get rolling window price change statistics with a custom window.
1100 ///
1101 /// This request is similar to `ticker.24hr`,
1102 /// but statistics are computed on demand using the arbitrary window you specify.
1103 /// Weight: Adjusted based on the number of requested symbols:
1104 ///
1105 /// | Symbols | Weight |
1106 /// |:-------:|:------:|
1107 /// | 1–50 | 4 per symbol |
1108 /// | 51–100 | 200 |
1109 ///
1110 /// # Arguments
1111 ///
1112 /// - `params`: [`TickerParams`]
1113 /// The parameters for this operation.
1114 ///
1115 /// # Returns
1116 ///
1117 /// [`WebsocketApiResponse<models::TickerResponse>`] on success.
1118 ///
1119 /// # Errors
1120 ///
1121 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1122 ///
1123 ///
1124 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#rolling-window-price-change-statistics).
1125 ///
1126 pub async fn ticker(
1127 &self,
1128 params: TickerParams,
1129 ) -> anyhow::Result<WebsocketApiResponse<models::TickerResponse>> {
1130 self.market_api_client.ticker(params).await
1131 }
1132
1133 /// WebSocket 24hr ticker price change statistics
1134 ///
1135 /// Get 24-hour rolling window price change statistics.
1136 ///
1137 /// If you need to continuously monitor trading statistics, please consider using WebSocket Streams:
1138 ///
1139 /// * `<symbol>@ticker` or `!ticker@arr`
1140 /// * `<symbol>@miniTicker` or `!miniTicker@arr`
1141 ///
1142 /// If you need different window sizes,
1143 /// use the `ticker` request.
1144 /// Weight: Adjusted based on the number of requested symbols:
1145 ///
1146 /// | Symbols | Weight |
1147 /// |:-----------:|:------:|
1148 /// | 1–20 | 2 |
1149 /// | 21–100 | 40 |
1150 /// | 101 or more | 80 |
1151 /// | all symbols | 80 |
1152 ///
1153 /// # Arguments
1154 ///
1155 /// - `params`: [`Ticker24hrParams`]
1156 /// The parameters for this operation.
1157 ///
1158 /// # Returns
1159 ///
1160 /// [`WebsocketApiResponse<models::Ticker24hrResponse>`] on success.
1161 ///
1162 /// # Errors
1163 ///
1164 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1165 ///
1166 ///
1167 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#24hr-ticker-price-change-statistics).
1168 ///
1169 pub async fn ticker24hr(
1170 &self,
1171 params: Ticker24hrParams,
1172 ) -> anyhow::Result<WebsocketApiResponse<models::Ticker24hrResponse>> {
1173 self.market_api_client.ticker24hr(params).await
1174 }
1175
1176 /// WebSocket Symbol order book ticker
1177 ///
1178 /// Get the current best price and quantity on the order book.
1179 ///
1180 /// If you need access to real-time order book ticker updates, please consider using WebSocket Streams:
1181 ///
1182 /// * `<symbol>@bookTicker`
1183 /// Weight: Adjusted based on the number of requested symbols:
1184 ///
1185 /// | Parameter | Weight |
1186 /// | --------- |:------:|
1187 /// | `symbol` | 2 |
1188 /// | `symbols` | 4 |
1189 /// | none | 4 |
1190 ///
1191 /// # Arguments
1192 ///
1193 /// - `params`: [`TickerBookParams`]
1194 /// The parameters for this operation.
1195 ///
1196 /// # Returns
1197 ///
1198 /// [`WebsocketApiResponse<models::TickerBookResponse>`] on success.
1199 ///
1200 /// # Errors
1201 ///
1202 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1203 ///
1204 ///
1205 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#symbol-order-book-ticker).
1206 ///
1207 pub async fn ticker_book(
1208 &self,
1209 params: TickerBookParams,
1210 ) -> anyhow::Result<WebsocketApiResponse<models::TickerBookResponse>> {
1211 self.market_api_client.ticker_book(params).await
1212 }
1213
1214 /// WebSocket Symbol price ticker
1215 ///
1216 /// Get the latest market price for a symbol.
1217 ///
1218 /// If you need access to real-time price updates, please consider using WebSocket Streams:
1219 ///
1220 /// * `<symbol>@aggTrade`
1221 /// * `<symbol>@trade`
1222 /// Weight: Adjusted based on the number of requested symbols:
1223 ///
1224 /// | Parameter | Weight |
1225 /// | --------- |:------:|
1226 /// | `symbol` | 2 |
1227 /// | `symbols` | 4 |
1228 /// | none | 4 |
1229 ///
1230 /// # Arguments
1231 ///
1232 /// - `params`: [`TickerPriceParams`]
1233 /// The parameters for this operation.
1234 ///
1235 /// # Returns
1236 ///
1237 /// [`WebsocketApiResponse<models::TickerPriceResponse>`] on success.
1238 ///
1239 /// # Errors
1240 ///
1241 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1242 ///
1243 ///
1244 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#symbol-price-ticker).
1245 ///
1246 pub async fn ticker_price(
1247 &self,
1248 params: TickerPriceParams,
1249 ) -> anyhow::Result<WebsocketApiResponse<models::TickerPriceResponse>> {
1250 self.market_api_client.ticker_price(params).await
1251 }
1252
1253 /// WebSocket Trading Day Ticker
1254 ///
1255 /// Price change statistics for a trading day.
1256 /// Weight: 4 for each requested <tt>symbol</tt>. <br/><br/> The weight for this request will cap at 200 once the number of `symbols` in the request is more than 50.
1257 ///
1258 /// # Arguments
1259 ///
1260 /// - `params`: [`TickerTradingDayParams`]
1261 /// The parameters for this operation.
1262 ///
1263 /// # Returns
1264 ///
1265 /// [`WebsocketApiResponse<Vec<models::TickerTradingDayResponseResultInner>>`] on success.
1266 ///
1267 /// # Errors
1268 ///
1269 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1270 ///
1271 ///
1272 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#trading-day-ticker).
1273 ///
1274 pub async fn ticker_trading_day(
1275 &self,
1276 params: TickerTradingDayParams,
1277 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::TickerTradingDayResponseResultInner>>>
1278 {
1279 self.market_api_client.ticker_trading_day(params).await
1280 }
1281
1282 /// WebSocket Aggregate trades
1283 ///
1284 /// Get aggregate trades.
1285 ///
1286 /// An *aggregate trade* (aggtrade) represents one or more individual trades.
1287 /// Trades that fill at the same time, from the same taker order, with the same price –
1288 /// those trades are collected into an aggregate trade with total quantity of the individual trades.
1289 ///
1290 /// If you need access to real-time trading activity, please consider using WebSocket Streams:
1291 ///
1292 /// * `<symbol>@aggTrade`
1293 ///
1294 /// If you need historical aggregate trade data,
1295 /// please consider using [data.binance.vision](https://github.com/binance/binance-public-data/#aggtrades).
1296 /// Weight: 4
1297 ///
1298 /// # Arguments
1299 ///
1300 /// - `params`: [`TradesAggregateParams`]
1301 /// The parameters for this operation.
1302 ///
1303 /// # Returns
1304 ///
1305 /// [`WebsocketApiResponse<Vec<models::TradesAggregateResponseResultInner>>`] on success.
1306 ///
1307 /// # Errors
1308 ///
1309 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1310 ///
1311 ///
1312 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#aggregate-trades).
1313 ///
1314 pub async fn trades_aggregate(
1315 &self,
1316 params: TradesAggregateParams,
1317 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::TradesAggregateResponseResultInner>>> {
1318 self.market_api_client.trades_aggregate(params).await
1319 }
1320
1321 /// WebSocket Historical trades
1322 ///
1323 /// Get historical trades.
1324 /// Weight: 25
1325 ///
1326 /// # Arguments
1327 ///
1328 /// - `params`: [`TradesHistoricalParams`]
1329 /// The parameters for this operation.
1330 ///
1331 /// # Returns
1332 ///
1333 /// [`WebsocketApiResponse<Vec<models::TradesHistoricalResponseResultInner>>`] on success.
1334 ///
1335 /// # Errors
1336 ///
1337 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1338 ///
1339 ///
1340 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#historical-trades).
1341 ///
1342 pub async fn trades_historical(
1343 &self,
1344 params: TradesHistoricalParams,
1345 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::TradesHistoricalResponseResultInner>>>
1346 {
1347 self.market_api_client.trades_historical(params).await
1348 }
1349
1350 /// WebSocket Recent trades
1351 ///
1352 /// Get recent trades.
1353 ///
1354 /// If you need access to real-time trading activity, please consider using WebSocket Streams:
1355 ///
1356 /// * `<symbol>@trade`
1357 /// Weight: 25
1358 ///
1359 /// # Arguments
1360 ///
1361 /// - `params`: [`TradesRecentParams`]
1362 /// The parameters for this operation.
1363 ///
1364 /// # Returns
1365 ///
1366 /// [`WebsocketApiResponse<Vec<models::TradesRecentResponseResultInner>>`] on success.
1367 ///
1368 /// # Errors
1369 ///
1370 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1371 ///
1372 ///
1373 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#recent-trades).
1374 ///
1375 pub async fn trades_recent(
1376 &self,
1377 params: TradesRecentParams,
1378 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::TradesRecentResponseResultInner>>> {
1379 self.market_api_client.trades_recent(params).await
1380 }
1381
1382 /// WebSocket UI Klines
1383 ///
1384 /// Get klines (candlestick bars) optimized for presentation.
1385 ///
1386 /// This request is similar to `klines`, having the same parameters and response.
1387 /// `uiKlines` return modified kline data, optimized for presentation of candlestick charts.
1388 /// Weight: 2
1389 ///
1390 /// # Arguments
1391 ///
1392 /// - `params`: [`UiKlinesParams`]
1393 /// The parameters for this operation.
1394 ///
1395 /// # Returns
1396 ///
1397 /// [`WebsocketApiResponse<Vec<Vec<models::KlinesItemInner>>>`] on success.
1398 ///
1399 /// # Errors
1400 ///
1401 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1402 ///
1403 ///
1404 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/market-data-requests#ui-klines).
1405 ///
1406 pub async fn ui_klines(
1407 &self,
1408 params: UiKlinesParams,
1409 ) -> anyhow::Result<WebsocketApiResponse<Vec<Vec<models::KlinesItemInner>>>> {
1410 self.market_api_client.ui_klines(params).await
1411 }
1412
1413 /// WebSocket Cancel open orders
1414 ///
1415 /// Cancel all open orders on a symbol.
1416 /// This includes orders that are part of an order list.
1417 /// Weight: 1
1418 ///
1419 /// # Arguments
1420 ///
1421 /// - `params`: [`OpenOrdersCancelAllParams`]
1422 /// The parameters for this operation.
1423 ///
1424 /// # Returns
1425 ///
1426 /// [`WebsocketApiResponse<Vec<models::OpenOrdersCancelAllResponseResultInner>>`] on success.
1427 ///
1428 /// # Errors
1429 ///
1430 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1431 ///
1432 ///
1433 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#cancel-open-orders-trade).
1434 ///
1435 pub async fn open_orders_cancel_all(
1436 &self,
1437 params: OpenOrdersCancelAllParams,
1438 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::OpenOrdersCancelAllResponseResultInner>>>
1439 {
1440 self.trade_api_client.open_orders_cancel_all(params).await
1441 }
1442
1443 /// WebSocket Order Amend Keep Priority
1444 ///
1445 /// Reduce the quantity of an existing open order.
1446 ///
1447 /// This adds 0 orders to the `EXCHANGE_MAX_ORDERS` filter and the `MAX_NUM_ORDERS` filter.
1448 ///
1449 /// Read [Order Amend Keep Priority FAQ](faqs/order_amend_keep_priority.md) to learn more.
1450 /// Weight: 4
1451 ///
1452 /// # Arguments
1453 ///
1454 /// - `params`: [`OrderAmendKeepPriorityParams`]
1455 /// The parameters for this operation.
1456 ///
1457 /// # Returns
1458 ///
1459 /// [`WebsocketApiResponse<Box<models::OrderAmendKeepPriorityResponseResult>>`] on success.
1460 ///
1461 /// # Errors
1462 ///
1463 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1464 ///
1465 ///
1466 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#order-amend-keep-priority-trade).
1467 ///
1468 pub async fn order_amend_keep_priority(
1469 &self,
1470 params: OrderAmendKeepPriorityParams,
1471 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderAmendKeepPriorityResponseResult>>>
1472 {
1473 self.trade_api_client
1474 .order_amend_keep_priority(params)
1475 .await
1476 }
1477
1478 /// WebSocket Cancel order
1479 ///
1480 /// Cancel an active order.
1481 /// Weight: 1
1482 ///
1483 /// # Arguments
1484 ///
1485 /// - `params`: [`OrderCancelParams`]
1486 /// The parameters for this operation.
1487 ///
1488 /// # Returns
1489 ///
1490 /// [`WebsocketApiResponse<Box<models::OrderCancelResponseResult>>`] on success.
1491 ///
1492 /// # Errors
1493 ///
1494 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1495 ///
1496 ///
1497 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#cancel-order-trade).
1498 ///
1499 pub async fn order_cancel(
1500 &self,
1501 params: OrderCancelParams,
1502 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderCancelResponseResult>>> {
1503 self.trade_api_client.order_cancel(params).await
1504 }
1505
1506 /// WebSocket Cancel and replace order
1507 ///
1508 /// * Cancel an existing order and immediately place a new order instead of the canceled one.
1509 /// * A new order that was not attempted (i.e. when `newOrderResult: NOT_ATTEMPTED`), will still increase the unfilled order count by 1.
1510 /// * You can only cancel an individual order from an orderList using this method, but the result is the same as canceling the entire orderList.
1511 /// Weight: 1
1512 ///
1513 /// # Arguments
1514 ///
1515 /// - `params`: [`OrderCancelReplaceParams`]
1516 /// The parameters for this operation.
1517 ///
1518 /// # Returns
1519 ///
1520 /// [`WebsocketApiResponse<Box<models::OrderCancelReplaceResponseResult>>`] on success.
1521 ///
1522 /// # Errors
1523 ///
1524 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1525 ///
1526 ///
1527 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#cancel-and-replace-order-trade).
1528 ///
1529 pub async fn order_cancel_replace(
1530 &self,
1531 params: OrderCancelReplaceParams,
1532 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderCancelReplaceResponseResult>>> {
1533 self.trade_api_client.order_cancel_replace(params).await
1534 }
1535
1536 /// WebSocket Cancel Order list
1537 ///
1538 /// Cancel an active order list.
1539 /// Weight: 1
1540 ///
1541 /// # Arguments
1542 ///
1543 /// - `params`: [`OrderListCancelParams`]
1544 /// The parameters for this operation.
1545 ///
1546 /// # Returns
1547 ///
1548 /// [`WebsocketApiResponse<Box<models::OrderListCancelResponseResult>>`] on success.
1549 ///
1550 /// # Errors
1551 ///
1552 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1553 ///
1554 ///
1555 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#cancel-order-list-trade).
1556 ///
1557 pub async fn order_list_cancel(
1558 &self,
1559 params: OrderListCancelParams,
1560 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListCancelResponseResult>>> {
1561 self.trade_api_client.order_list_cancel(params).await
1562 }
1563
1564 /// WebSocket Place new OCO - Deprecated
1565 ///
1566 /// Send in a new one-cancels-the-other (OCO) pair:
1567 /// `LIMIT_MAKER` + `STOP_LOSS`/`STOP_LOSS_LIMIT` orders (called *legs*),
1568 /// where activation of one order immediately cancels the other.
1569 ///
1570 /// This adds 1 order to `EXCHANGE_MAX_ORDERS` filter and the `MAX_NUM_ORDERS` filter
1571 /// Weight: 1
1572 ///
1573 /// Unfilled Order Count: 1
1574 ///
1575 /// # Arguments
1576 ///
1577 /// - `params`: [`OrderListPlaceParams`]
1578 /// The parameters for this operation.
1579 ///
1580 /// # Returns
1581 ///
1582 /// [`WebsocketApiResponse<Box<models::OrderListPlaceResponseResult>>`] on success.
1583 ///
1584 /// # Errors
1585 ///
1586 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1587 ///
1588 ///
1589 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-oco---deprecated-trade).
1590 ///
1591 /// # Deprecation
1592 ///
1593 /// **Deprecated:** This method may be removed in a future version.
1594 #[deprecated]
1595 pub async fn order_list_place(
1596 &self,
1597 params: OrderListPlaceParams,
1598 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListPlaceResponseResult>>> {
1599 self.trade_api_client.order_list_place(params).await
1600 }
1601
1602 /// WebSocket Place new Order list - OCO
1603 ///
1604 /// Send in an one-cancels-the-other (OCO) pair, where activation of one order immediately cancels the other.
1605 ///
1606 /// * An OCO has 2 orders called the **above order** and **below order**.
1607 /// * One of the orders must be a `LIMIT_MAKER/TAKE_PROFIT/TAKE_PROFIT_LIMIT` order and the other must be `STOP_LOSS` or `STOP_LOSS_LIMIT` order.
1608 /// * Price restrictions:
1609 /// * If the OCO is on the `SELL` side:
1610 /// * `LIMIT_MAKER/TAKE_PROFIT_LIMIT` `price` > Last Traded Price > `STOP_LOSS/STOP_LOSS_LIMIT` `stopPrice`
1611 /// * `TAKE_PROFIT stopPrice` > Last Traded Price > `STOP_LOSS/STOP_LOSS_LIMIT stopPrice`
1612 /// * If the OCO is on the `BUY` side:
1613 /// * `LIMIT_MAKER` `price` < Last Traded Price < `STOP_LOSS/STOP_LOSS_LIMIT` `stopPrice`
1614 /// * `TAKE_PROFIT stopPrice` > Last Traded Price > `STOP_LOSS/STOP_LOSS_LIMIT stopPrice`
1615 /// * OCOs add **2 orders** to the `EXCHANGE_MAX_ORDERS` filter and `MAX_NUM_ORDERS` filter.
1616 /// Weight: 1
1617 ///
1618 /// Unfilled Order Count: 2
1619 ///
1620 /// # Arguments
1621 ///
1622 /// - `params`: [`OrderListPlaceOcoParams`]
1623 /// The parameters for this operation.
1624 ///
1625 /// # Returns
1626 ///
1627 /// [`WebsocketApiResponse<Box<models::OrderListPlaceOcoResponseResult>>`] on success.
1628 ///
1629 /// # Errors
1630 ///
1631 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1632 ///
1633 ///
1634 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-order-list---oco-trade).
1635 ///
1636 pub async fn order_list_place_oco(
1637 &self,
1638 params: OrderListPlaceOcoParams,
1639 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListPlaceOcoResponseResult>>> {
1640 self.trade_api_client.order_list_place_oco(params).await
1641 }
1642
1643 /// WebSocket OPO
1644 ///
1645 /// Place an [OPO](./faqs/opo.md).
1646 ///
1647 /// * OPOs add 2 orders to the `EXCHANGE_MAX_NUM_ORDERS` filter and `MAX_NUM_ORDERS` filter.
1648 /// Weight: 1
1649 ///
1650 /// Unfilled Order Count: 2
1651 ///
1652 /// # Arguments
1653 ///
1654 /// - `params`: [`OrderListPlaceOpoParams`]
1655 /// The parameters for this operation.
1656 ///
1657 /// # Returns
1658 ///
1659 /// [`WebsocketApiResponse<Box<models::OrderListPlaceOpoResponseResult>>`] on success.
1660 ///
1661 /// # Errors
1662 ///
1663 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1664 ///
1665 ///
1666 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#opo-trade).
1667 ///
1668 pub async fn order_list_place_opo(
1669 &self,
1670 params: OrderListPlaceOpoParams,
1671 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListPlaceOpoResponseResult>>> {
1672 self.trade_api_client.order_list_place_opo(params).await
1673 }
1674
1675 /// WebSocket OPOCO
1676 ///
1677 /// Place an [OPOCO](./faqs/opo.md).
1678 /// Weight: 1
1679 ///
1680 /// Unfilled Order Count: 3
1681 ///
1682 /// # Arguments
1683 ///
1684 /// - `params`: [`OrderListPlaceOpocoParams`]
1685 /// The parameters for this operation.
1686 ///
1687 /// # Returns
1688 ///
1689 /// [`WebsocketApiResponse<Box<models::OrderListPlaceOpocoResponseResult>>`] on success.
1690 ///
1691 /// # Errors
1692 ///
1693 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1694 ///
1695 ///
1696 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#opoco-trade).
1697 ///
1698 pub async fn order_list_place_opoco(
1699 &self,
1700 params: OrderListPlaceOpocoParams,
1701 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListPlaceOpocoResponseResult>>> {
1702 self.trade_api_client.order_list_place_opoco(params).await
1703 }
1704
1705 /// WebSocket Place new Order list - OTO
1706 ///
1707 /// Places an OTO.
1708 ///
1709 /// * An OTO (One-Triggers-the-Other) is an order list comprised of 2 orders.
1710 /// * The first order is called the **working order** and must be `LIMIT` or `LIMIT_MAKER`. Initially, only the working order goes on the order book.
1711 /// * The second order is called the **pending order**. It can be any order type except for `MARKET` orders using parameter `quoteOrderQty`. The pending order is only placed on the order book when the working order gets **fully filled**.
1712 /// * If either the working order or the pending order is cancelled individually, the other order in the order list will also be canceled or expired.
1713 /// * When the order list is placed, if the working order gets **immediately fully filled**, the placement response will show the working order as `FILLED` but the pending order will still appear as `PENDING_NEW`. You need to query the status of the pending order again to see its updated status.
1714 /// * OTOs add **2 orders** to the `EXCHANGE_MAX_NUM_ORDERS` filter and `MAX_NUM_ORDERS` filter.
1715 /// Weight: 1
1716 ///
1717 /// Unfilled Order Count: 2
1718 ///
1719 /// # Arguments
1720 ///
1721 /// - `params`: [`OrderListPlaceOtoParams`]
1722 /// The parameters for this operation.
1723 ///
1724 /// # Returns
1725 ///
1726 /// [`WebsocketApiResponse<Box<models::OrderListPlaceOtoResponseResult>>`] on success.
1727 ///
1728 /// # Errors
1729 ///
1730 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1731 ///
1732 ///
1733 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-order-list---oto-trade).
1734 ///
1735 pub async fn order_list_place_oto(
1736 &self,
1737 params: OrderListPlaceOtoParams,
1738 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListPlaceOtoResponseResult>>> {
1739 self.trade_api_client.order_list_place_oto(params).await
1740 }
1741
1742 /// WebSocket Place new Order list - OTOCO
1743 ///
1744 /// Place an OTOCO.
1745 ///
1746 /// * An OTOCO (One-Triggers-One-Cancels-the-Other) is an order list comprised of 3 orders.
1747 /// * The first order is called the **working order** and must be `LIMIT` or `LIMIT_MAKER`. Initially, only the working order goes on the order book.
1748 /// * The behavior of the working order is the same as the [OTO](#place-new-order-list---oto-trade).
1749 /// * OTOCO has 2 pending orders (pending above and pending below), forming an OCO pair. The pending orders are only placed on the order book when the working order gets **fully filled**.
1750 /// * The rules of the pending above and pending below follow the same rules as the [Order list OCO](#new-order-list---oco-trade).
1751 /// * OTOCOs add **3 orders** to the `EXCHANGE_MAX_NUM_ORDERS` filter and `MAX_NUM_ORDERS` filter.
1752 /// Weight: 1
1753 ///
1754 /// Unfilled Order Count: 3
1755 ///
1756 /// # Arguments
1757 ///
1758 /// - `params`: [`OrderListPlaceOtocoParams`]
1759 /// The parameters for this operation.
1760 ///
1761 /// # Returns
1762 ///
1763 /// [`WebsocketApiResponse<Box<models::OrderListPlaceOtocoResponseResult>>`] on success.
1764 ///
1765 /// # Errors
1766 ///
1767 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1768 ///
1769 ///
1770 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-order-list---otoco-trade).
1771 ///
1772 pub async fn order_list_place_otoco(
1773 &self,
1774 params: OrderListPlaceOtocoParams,
1775 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderListPlaceOtocoResponseResult>>> {
1776 self.trade_api_client.order_list_place_otoco(params).await
1777 }
1778
1779 /// WebSocket Place new order
1780 ///
1781 /// Send in a new order.
1782 ///
1783 /// This adds 1 order to the `EXCHANGE_MAX_ORDERS` filter and the `MAX_NUM_ORDERS` filter.
1784 /// Weight: 1
1785 ///
1786 /// # Arguments
1787 ///
1788 /// - `params`: [`OrderPlaceParams`]
1789 /// The parameters for this operation.
1790 ///
1791 /// # Returns
1792 ///
1793 /// [`WebsocketApiResponse<Box<models::OrderPlaceResponseResult>>`] on success.
1794 ///
1795 /// # Errors
1796 ///
1797 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1798 ///
1799 ///
1800 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-order-trade).
1801 ///
1802 pub async fn order_place(
1803 &self,
1804 params: OrderPlaceParams,
1805 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderPlaceResponseResult>>> {
1806 self.trade_api_client.order_place(params).await
1807 }
1808
1809 /// WebSocket Test new order
1810 ///
1811 /// Test order placement.
1812 ///
1813 /// Validates new order parameters and verifies your signature
1814 /// but does not send the order into the matching engine.
1815 /// Weight: |Condition| Request Weight|
1816 /// |------------ | ------------ |
1817 /// |Without `computeCommissionRates`| 1|
1818 /// |With `computeCommissionRates`|20|
1819 ///
1820 /// # Arguments
1821 ///
1822 /// - `params`: [`OrderTestParams`]
1823 /// The parameters for this operation.
1824 ///
1825 /// # Returns
1826 ///
1827 /// [`WebsocketApiResponse<Box<models::OrderTestResponseResult>>`] on success.
1828 ///
1829 /// # Errors
1830 ///
1831 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1832 ///
1833 ///
1834 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#test-new-order-trade).
1835 ///
1836 pub async fn order_test(
1837 &self,
1838 params: OrderTestParams,
1839 ) -> anyhow::Result<WebsocketApiResponse<Box<models::OrderTestResponseResult>>> {
1840 self.trade_api_client.order_test(params).await
1841 }
1842
1843 /// WebSocket Place new order using SOR
1844 ///
1845 /// Places an order using smart order routing (SOR).
1846 ///
1847 /// This adds 1 order to the `EXCHANGE_MAX_ORDERS` filter and the `MAX_NUM_ORDERS` filter.
1848 ///
1849 /// Read [SOR FAQ](faqs/sor_faq.md) to learn more.
1850 /// Weight: 1
1851 ///
1852 /// Unfilled Order Count: 1
1853 ///
1854 /// # Arguments
1855 ///
1856 /// - `params`: [`SorOrderPlaceParams`]
1857 /// The parameters for this operation.
1858 ///
1859 /// # Returns
1860 ///
1861 /// [`WebsocketApiResponse<Vec<models::SorOrderPlaceResponseResultInner>>`] on success.
1862 ///
1863 /// # Errors
1864 ///
1865 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1866 ///
1867 ///
1868 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#place-new-order-using-sor-trade).
1869 ///
1870 pub async fn sor_order_place(
1871 &self,
1872 params: SorOrderPlaceParams,
1873 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::SorOrderPlaceResponseResultInner>>> {
1874 self.trade_api_client.sor_order_place(params).await
1875 }
1876
1877 /// WebSocket Test new order using SOR
1878 ///
1879 /// Test new order creation and signature/recvWindow using smart order routing (SOR).
1880 /// Creates and validates a new order but does not send it into the matching engine.
1881 /// Weight: |Condition | Request Weight|
1882 /// |------------ | ------------ |
1883 /// |Without `computeCommissionRates`| 1 |
1884 /// |With `computeCommissionRates` |20 |
1885 ///
1886 /// # Arguments
1887 ///
1888 /// - `params`: [`SorOrderTestParams`]
1889 /// The parameters for this operation.
1890 ///
1891 /// # Returns
1892 ///
1893 /// [`WebsocketApiResponse<Box<models::SorOrderTestResponseResult>>`] on success.
1894 ///
1895 /// # Errors
1896 ///
1897 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1898 ///
1899 ///
1900 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/trading-requests#test-new-order-using-sor-trade).
1901 ///
1902 pub async fn sor_order_test(
1903 &self,
1904 params: SorOrderTestParams,
1905 ) -> anyhow::Result<WebsocketApiResponse<Box<models::SorOrderTestResponseResult>>> {
1906 self.trade_api_client.sor_order_test(params).await
1907 }
1908
1909 /// WebSocket Listing all subscriptions
1910 ///
1911 ///
1912 /// Weight: 2
1913 ///
1914 /// **Data Source**:
1915 /// Memory
1916 ///
1917 /// # Arguments
1918 ///
1919 /// - `params`: [`SessionSubscriptionsParams`]
1920 /// The parameters for this operation.
1921 ///
1922 /// # Returns
1923 ///
1924 /// [`WebsocketApiResponse<Vec<models::SessionSubscriptionsResponseResultInner>>`] on success.
1925 ///
1926 /// # Errors
1927 ///
1928 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1929 ///
1930 ///
1931 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/user-Data-Stream-requests#listing-all-subscriptions).
1932 ///
1933 pub async fn session_subscriptions(
1934 &self,
1935 params: SessionSubscriptionsParams,
1936 ) -> anyhow::Result<WebsocketApiResponse<Vec<models::SessionSubscriptionsResponseResultInner>>>
1937 {
1938 self.user_data_stream_api_client
1939 .session_subscriptions(params)
1940 .await
1941 }
1942
1943 /// WebSocket Subscribe to User Data Stream
1944 ///
1945 /// Subscribe to the User Data Stream in the current WebSocket connection.
1946 /// Weight: 2
1947 ///
1948 /// # Arguments
1949 ///
1950 /// - `params`: [`UserDataStreamSubscribeParams`]
1951 /// The parameters for this operation.
1952 ///
1953 /// # Returns
1954 ///
1955 /// [`WebsocketApiResponse<Box<models::UserDataStreamSubscribeResponseResult>>`] on success.
1956 ///
1957 /// # Errors
1958 ///
1959 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
1960 ///
1961 ///
1962 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/user-Data-Stream-requests#subscribe-to-user-data-stream-user_stream).
1963 ///
1964 pub async fn user_data_stream_subscribe(
1965 &self,
1966 params: UserDataStreamSubscribeParams,
1967 ) -> anyhow::Result<(
1968 WebsocketApiResponse<Box<models::UserDataStreamSubscribeResponseResult>>,
1969 Arc<WebsocketStream<UserDataStreamEventsResponse>>,
1970 )> {
1971 let response = self
1972 .user_data_stream_api_client
1973 .user_data_stream_subscribe(params)
1974 .await?;
1975 let stream = create_stream_handler::<UserDataStreamEventsResponse>(
1976 WebsocketBase::WebsocketApi(self.websocket_api_base.clone()),
1977 random_string(),
1978 None,
1979 None,
1980 )
1981 .await;
1982
1983 Ok((response, stream))
1984 }
1985
1986 /// WebSocket Subscribe to User Data Stream through signature subscription
1987 ///
1988 ///
1989 /// Weight: 2
1990 ///
1991 /// # Arguments
1992 ///
1993 /// - `params`: [`UserDataStreamSubscribeSignatureParams`]
1994 /// The parameters for this operation.
1995 ///
1996 /// # Returns
1997 ///
1998 /// [`WebsocketApiResponse<Box<models::UserDataStreamSubscribeResponseResult>>`] on success.
1999 ///
2000 /// # Errors
2001 ///
2002 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
2003 ///
2004 ///
2005 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/user-Data-Stream-requests#subscribe-to-user-data-stream-through-signature-subscription-user_stream).
2006 ///
2007 pub async fn user_data_stream_subscribe_signature(
2008 &self,
2009 params: UserDataStreamSubscribeSignatureParams,
2010 ) -> anyhow::Result<(
2011 WebsocketApiResponse<Box<models::UserDataStreamSubscribeResponseResult>>,
2012 Arc<WebsocketStream<UserDataStreamEventsResponse>>,
2013 )> {
2014 let response = self
2015 .user_data_stream_api_client
2016 .user_data_stream_subscribe_signature(params)
2017 .await?;
2018 let stream = create_stream_handler::<UserDataStreamEventsResponse>(
2019 WebsocketBase::WebsocketApi(self.websocket_api_base.clone()),
2020 random_string(),
2021 None,
2022 None,
2023 )
2024 .await;
2025
2026 Ok((response, stream))
2027 }
2028
2029 /// WebSocket Unsubscribe from User Data Stream
2030 ///
2031 /// Stop listening to the User Data Stream in the current WebSocket connection.
2032 ///
2033 /// Note that `session.logout` will only close the subscription created with `userDataStream.subscribe` but not subscriptions opened with `userDataStream.subscribe.signature`.
2034 /// Weight: 2
2035 ///
2036 /// # Arguments
2037 ///
2038 /// - `params`: [`UserDataStreamUnsubscribeParams`]
2039 /// The parameters for this operation.
2040 ///
2041 /// # Returns
2042 ///
2043 /// [`WebsocketApiResponse<serde_json::Value>`] on success.
2044 ///
2045 /// # Errors
2046 ///
2047 /// Returns an [`anyhow::Error`] if the WebSocket request fails, if parameters are invalid, or if parsing the response fails.
2048 ///
2049 ///
2050 /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/binance-spot-api-docs/websocket-api/user-Data-Stream-requests#unsubscribe-from-user-data-stream).
2051 ///
2052 pub async fn user_data_stream_unsubscribe(
2053 &self,
2054 params: UserDataStreamUnsubscribeParams,
2055 ) -> anyhow::Result<WebsocketApiResponse<serde_json::Value>> {
2056 self.user_data_stream_api_client
2057 .user_data_stream_unsubscribe(params)
2058 .await
2059 }
2060}