1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
/*
* Binance Derivatives Trading COIN Futures WebSocket Market Streams
*
* OpenAPI Specification for the Binance Derivatives Trading COIN Futures WebSocket Market Streams
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#![allow(unused_imports)]
use serde_json::Value;
use std::sync::{Arc, atomic::Ordering};
use tokio::spawn;
use crate::common::config::ConfigurationWebsocketStreams;
use crate::common::websocket::{
Subscription, WebsocketBase, WebsocketStream, WebsocketStreams as WebsocketStreamsBase,
create_stream_handler,
};
use crate::models::{StreamId, WebsocketEvent, WebsocketMode};
mod apis;
mod handle;
mod models;
pub use apis::*;
pub use handle::*;
pub use models::*;
const HAS_TIME_UNIT: bool = false;
pub struct WebsocketStreams {
websocket_streams_base: Arc<WebsocketStreamsBase>,
websocket_market_streams_api_client: WebsocketMarketStreamsApiClient,
}
impl WebsocketStreams {
pub(crate) async fn connect(
config: ConfigurationWebsocketStreams,
streams: Vec<String>,
mode: Option<WebsocketMode>,
) -> anyhow::Result<Self> {
let mut cfg = config;
if let Some(m) = mode {
cfg.mode = m;
}
if !HAS_TIME_UNIT {
cfg.time_unit = None;
}
let websocket_streams_base = WebsocketStreamsBase::new(cfg, vec![], vec![]);
websocket_streams_base.clone().connect(streams).await?;
Ok(Self {
websocket_streams_base: websocket_streams_base.clone(),
websocket_market_streams_api_client: WebsocketMarketStreamsApiClient::new(
websocket_streams_base.clone(),
),
})
}
/// Subscribes to WebSocket events with a provided callback function.
///
/// # Arguments
///
/// * `callback` - A mutable function that takes a `WebsocketEvent` and is `Send` and `'static`.
///
/// # Returns
///
/// A `Subscription` that can be used to manage the event subscription.
///
/// # Examples
///
///
/// let subscription = `websocket_streams.subscribe_on_ws_events(|event`| {
/// // Handle WebSocket event
/// });
///
pub fn subscribe_on_ws_events<F>(&self, callback: F) -> Subscription
where
F: FnMut(WebsocketEvent) + Send + 'static,
{
let base = Arc::clone(&self.websocket_streams_base);
base.common.events.subscribe(callback)
}
/// Unsubscribes from WebSocket events for a given `Subscription`.
///
/// # Arguments
///
/// * `subscription` - The `Subscription` to unsubscribe from WebSocket events.
///
/// # Examples
///
///
/// let subscription = `websocket_streams.subscribe_on_ws_events(|event`| {
/// // Handle WebSocket event
/// });
/// `websocket_streams.unsubscribe_from_ws_events(subscription)`;
///
pub fn unsubscribe_from_ws_events(&self, subscription: Subscription) {
subscription.unsubscribe();
}
/// Disconnects the WebSocket connection.
///
/// # Returns
///
/// A `Result` indicating whether the disconnection was successful.
/// Returns an error if the disconnection fails.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the connection fails.
///
/// # Examples
///
///
/// let `websocket_streams` = `WebSocketStreams::new`(...);
/// `websocket_streams.disconnect().await`?;
///
pub async fn disconnect(&self) -> anyhow::Result<()> {
self.websocket_streams_base
.disconnect()
.await
.map_err(anyhow::Error::msg)
}
/// Checks if the WebSocket connection is currently active.
///
/// # Returns
///
/// A `bool` indicating whether the WebSocket connection is established and connected.
///
/// # Examples
///
///
/// let `is_active` = `websocket_streams.is_connected().await`;
/// if `is_active` {
/// // WebSocket connection is active
/// }
///
pub async fn is_connected(&self) -> bool {
self.websocket_streams_base.is_connected().await
}
/// Sends a ping to the WebSocket server to maintain the connection.
///
/// # Examples
///
///
/// `websocket_streams.ping_server().await`;
///
///
/// This method sends a ping request to the WebSocket server to keep the connection alive
/// and check the server's responsiveness.
pub async fn ping_server(&self) {
self.websocket_streams_base.ping_server().await;
}
/// Subscribes to specified WebSocket streams.
///
/// # Arguments
///
/// * `streams` - A vector of stream names to subscribe to
/// * `id` - An optional identifier for the subscription request
///
/// # Examples
///
///
/// `websocket_streams.subscribe(vec`!["`btcusdt@trade".to_string()`], None).await;
///
///
/// This method initiates an asynchronous subscription to the specified WebSocket streams.
/// The subscription is performed in a separate task using `spawn`.
pub fn subscribe(&self, streams: Vec<String>, id: Option<String>) {
let base = Arc::clone(&self.websocket_streams_base);
spawn(async move { base.subscribe(streams, id.map(StreamId::from), None).await });
}
/// Unsubscribes from specified WebSocket streams.
///
/// # Arguments
///
/// * `streams` - A vector of stream names to unsubscribe from
/// * `id` - An optional identifier for the unsubscription request
///
/// # Examples
///
///
/// `websocket_streams.unsubscribe(vec`!["`btcusdt@trade".to_string()`], None).await;
///
///
/// This method initiates an asynchronous unsubscription from the specified WebSocket streams.
/// The unsubscription is performed in a separate task using `spawn`.
pub fn unsubscribe(&self, streams: Vec<String>, id: Option<String>) {
let base = Arc::clone(&self.websocket_streams_base);
spawn(async move {
base.unsubscribe(streams, id.map(StreamId::from), None)
.await;
});
}
/// Checks if the current WebSocket stream is subscribed to a specific stream.
///
/// # Arguments
///
/// * `stream` - The name of the stream to check for subscription
///
/// # Returns
///
/// A boolean indicating whether the stream is currently subscribed
///
/// # Examples
///
///
/// let `is_subscribed` = `websocket_streams.is_subscribed("btcusdt@trade").await`;
///
///
/// This method checks the subscription status of a specific WebSocket stream.
pub async fn is_subscribed(&self, stream: &str) -> bool {
self.websocket_streams_base.is_subscribed(stream).await
}
/// User Data Stream
///
/// Establishes a WebSocket stream for user-specific data events.
///
/// # Arguments
///
/// - `listen_key`: A unique key for identifying the user's data stream
/// - `id`: An optional identifier for the stream request
///
/// # Returns
///
/// [`Arc<WebsocketStream<UserDataStreamEventsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream creation fails or if parsing the response encounters issues.
///
/// # Examples
///
///
/// let `user_stream` = `websocket_streams.user_data(listen_key`, None).await?;
///
pub async fn user_data(
&self,
listen_key: String,
id: Option<String>,
) -> anyhow::Result<Arc<WebsocketStream<UserDataStreamEventsResponse>>> {
Ok(create_stream_handler::<UserDataStreamEventsResponse>(
WebsocketBase::WebsocketStreams(self.websocket_streams_base.clone()),
listen_key,
id.map(StreamId::from),
None,
)
.await)
}
/// Aggregate Trade Streams
///
/// The Aggregate Trade Streams push market trade information that is aggregated for fills with same price and taking side every 100 milliseconds.
///
/// Update Speed: 100ms
///
/// # Arguments
///
/// - `params`: [`AggregateTradeStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::AggregateTradeStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Aggregate-Trade-Streams).
///
pub async fn aggregate_trade_streams(
&self,
params: AggregateTradeStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::AggregateTradeStreamsResponse>>> {
self.websocket_market_streams_api_client
.aggregate_trade_streams(params)
.await
}
/// All Book Tickers Stream
///
/// Pushes any update to the best bid or ask's price or quantity in real-time for all symbols.
///
/// Update Speed: Real-time
///
/// # Arguments
///
/// - `params`: [`AllBookTickersStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::AllBookTickersStreamResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/All-Book-Tickers-Stream).
///
pub async fn all_book_tickers_stream(
&self,
params: AllBookTickersStreamParams,
) -> anyhow::Result<Arc<WebsocketStream<models::AllBookTickersStreamResponse>>> {
self.websocket_market_streams_api_client
.all_book_tickers_stream(params)
.await
}
/// All Market Liquidation Order Streams
///
/// The All Liquidation Order Snapshot Streams push force liquidation order information for all symbols in the market.
/// For each symbol,only the latest one liquidation order within 1000ms will be pushed as the snapshot. If no liquidation happens in the interval of 1000ms, no stream will be pushed.
///
/// Update Speed: 1000ms
///
/// # Arguments
///
/// - `params`: [`AllMarketLiquidationOrderStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::AllMarketLiquidationOrderStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/All-Market-Liquidation-Order-Streams).
///
pub async fn all_market_liquidation_order_streams(
&self,
params: AllMarketLiquidationOrderStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::AllMarketLiquidationOrderStreamsResponse>>>
{
self.websocket_market_streams_api_client
.all_market_liquidation_order_streams(params)
.await
}
/// All Market Mini Tickers Stream
///
/// 24hr rolling window mini-ticker statistics for all symbols. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before. Note that only tickers that have changed will be present in the array.
///
/// Update Speed: 1000ms
///
/// # Arguments
///
/// - `params`: [`AllMarketMiniTickersStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<Vec<models::AllMarketMiniTickersStreamResponseInner>>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/All-Market-Mini-Tickers-Stream).
///
pub async fn all_market_mini_tickers_stream(
&self,
params: AllMarketMiniTickersStreamParams,
) -> anyhow::Result<Arc<WebsocketStream<Vec<models::AllMarketMiniTickersStreamResponseInner>>>>
{
self.websocket_market_streams_api_client
.all_market_mini_tickers_stream(params)
.await
}
/// All Market Tickers Streams
///
/// 24hr rolling window ticker statistics for all symbols. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before. Note that only tickers that have changed will be present in the array.
///
/// Update Speed: 1000ms
///
/// # Arguments
///
/// - `params`: [`AllMarketTickersStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<Vec<models::AllMarketTickersStreamsResponseInner>>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/All-Market-Tickers-Streams).
///
pub async fn all_market_tickers_streams(
&self,
params: AllMarketTickersStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<Vec<models::AllMarketTickersStreamsResponseInner>>>>
{
self.websocket_market_streams_api_client
.all_market_tickers_streams(params)
.await
}
/// Continuous Contract Kline/Candlestick Streams
///
/// Kline update every second
///
/// Update Speed: 250ms
///
/// # Arguments
///
/// - `params`: [`ContinuousContractKlineCandlestickStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::ContinuousContractKlineCandlestickStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Continuous-Contract-Kline-Candlestick-Streams).
///
pub async fn continuous_contract_kline_candlestick_streams(
&self,
params: ContinuousContractKlineCandlestickStreamsParams,
) -> anyhow::Result<
Arc<WebsocketStream<models::ContinuousContractKlineCandlestickStreamsResponse>>,
> {
self.websocket_market_streams_api_client
.continuous_contract_kline_candlestick_streams(params)
.await
}
/// Contract Info Stream
///
/// `ContractInfo` stream pushes when contract info updates(listing/settlement/contract bracket update). `bks` field only shows up when bracket gets updated.
///
/// Update Speed: Real-time
///
/// # Arguments
///
/// - `params`: [`ContractInfoStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::ContractInfoStreamResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Contract-Info-Stream).
///
pub async fn contract_info_stream(
&self,
params: ContractInfoStreamParams,
) -> anyhow::Result<Arc<WebsocketStream<models::ContractInfoStreamResponse>>> {
self.websocket_market_streams_api_client
.contract_info_stream(params)
.await
}
/// Diff. Book Depth Streams
///
/// Bids and asks, pushed every 250 milliseconds, 500 milliseconds, or 100 milliseconds
///
/// Update Speed: 250ms or 500ms or 100ms
///
/// # Arguments
///
/// - `params`: [`DiffBookDepthStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::DiffBookDepthStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Diff-Book-Depth-Streams).
///
pub async fn diff_book_depth_streams(
&self,
params: DiffBookDepthStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::DiffBookDepthStreamsResponse>>> {
self.websocket_market_streams_api_client
.diff_book_depth_streams(params)
.await
}
/// Index Kline/Candlestick Streams
///
/// Index Kline/Candlestick Streams
///
/// Update Speed: 250ms
///
/// # Arguments
///
/// - `params`: [`IndexKlineCandlestickStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::IndexKlineCandlestickStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Index-Kline-Candlestick-Streams).
///
pub async fn index_kline_candlestick_streams(
&self,
params: IndexKlineCandlestickStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::IndexKlineCandlestickStreamsResponse>>> {
self.websocket_market_streams_api_client
.index_kline_candlestick_streams(params)
.await
}
/// Index Price Stream
///
/// Index Price Stream
///
/// Update Speed: 3000ms OR 1000ms
///
/// # Arguments
///
/// - `params`: [`IndexPriceStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::IndexPriceStreamResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Index-Price-Stream).
///
pub async fn index_price_stream(
&self,
params: IndexPriceStreamParams,
) -> anyhow::Result<Arc<WebsocketStream<models::IndexPriceStreamResponse>>> {
self.websocket_market_streams_api_client
.index_price_stream(params)
.await
}
/// Individual Symbol Book Ticker Streams
///
/// Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.
///
/// Update Speed: Real-time
///
/// # Arguments
///
/// - `params`: [`IndividualSymbolBookTickerStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::IndividualSymbolBookTickerStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Individual-Symbol-Book-Ticker-Streams).
///
pub async fn individual_symbol_book_ticker_streams(
&self,
params: IndividualSymbolBookTickerStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::IndividualSymbolBookTickerStreamsResponse>>>
{
self.websocket_market_streams_api_client
.individual_symbol_book_ticker_streams(params)
.await
}
/// Individual Symbol Mini Ticker Stream
///
/// 24hr rolling window mini-ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before.
///
/// Update Speed: 500ms
///
/// # Arguments
///
/// - `params`: [`IndividualSymbolMiniTickerStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::IndividualSymbolMiniTickerStreamResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Individual-Symbol-Mini-Ticker-Stream).
///
pub async fn individual_symbol_mini_ticker_stream(
&self,
params: IndividualSymbolMiniTickerStreamParams,
) -> anyhow::Result<Arc<WebsocketStream<models::IndividualSymbolMiniTickerStreamResponse>>>
{
self.websocket_market_streams_api_client
.individual_symbol_mini_ticker_stream(params)
.await
}
/// Individual Symbol Ticker Streams
///
/// 24hr rolling window ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window from requestTime to 24hrs before.
///
/// Update Speed: 500ms
///
/// # Arguments
///
/// - `params`: [`IndividualSymbolTickerStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::IndividualSymbolTickerStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Individual-Symbol-Ticker-Streams).
///
pub async fn individual_symbol_ticker_streams(
&self,
params: IndividualSymbolTickerStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::IndividualSymbolTickerStreamsResponse>>> {
self.websocket_market_streams_api_client
.individual_symbol_ticker_streams(params)
.await
}
/// Kline/Candlestick Streams
///
/// The Kline/Candlestick Stream push updates to the current klines/candlestick every 250 milliseconds (if existing).
///
/// Update Speed: 250ms
///
/// # Arguments
///
/// - `params`: [`KlineCandlestickStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::KlineCandlestickStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Kline-Candlestick-Streams).
///
pub async fn kline_candlestick_streams(
&self,
params: KlineCandlestickStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::KlineCandlestickStreamsResponse>>> {
self.websocket_market_streams_api_client
.kline_candlestick_streams(params)
.await
}
/// Liquidation Order Streams
///
/// The Liquidation Order Snapshot Streams push force liquidation order information for specific symbol.
///
/// For each symbol,only the latest one liquidation order within 1000ms will be pushed as the snapshot. If no liquidation happens in the interval of 1000ms, no stream will be pushed.
///
/// Update Speed: 1000ms
///
/// # Arguments
///
/// - `params`: [`LiquidationOrderStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::LiquidationOrderStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Liquidation-Order-Streams).
///
pub async fn liquidation_order_streams(
&self,
params: LiquidationOrderStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::LiquidationOrderStreamsResponse>>> {
self.websocket_market_streams_api_client
.liquidation_order_streams(params)
.await
}
/// Mark Price Kline/Candlestick Streams
///
/// Mark Price Kline/Candlestick Streams
///
/// Update Speed: 250ms
///
/// # Arguments
///
/// - `params`: [`MarkPriceKlineCandlestickStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::MarkPriceKlineCandlestickStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Mark-Price-Kline-Candlestick-Streams).
///
pub async fn mark_price_kline_candlestick_streams(
&self,
params: MarkPriceKlineCandlestickStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::MarkPriceKlineCandlestickStreamsResponse>>>
{
self.websocket_market_streams_api_client
.mark_price_kline_candlestick_streams(params)
.await
}
/// Mark Price of All Symbols of a Pair
///
/// Mark Price of All Symbols of a Pair
///
/// Update Speed: 3000ms OR 1000ms
///
/// # Arguments
///
/// - `params`: [`MarkPriceOfAllSymbolsOfAPairParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<Vec<models::MarkPriceOfAllSymbolsOfAPairResponseInner>>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Mark-Price-of-All-Symbols-of-a-Pair).
///
pub async fn mark_price_of_all_symbols_of_a_pair(
&self,
params: MarkPriceOfAllSymbolsOfAPairParams,
) -> anyhow::Result<Arc<WebsocketStream<Vec<models::MarkPriceOfAllSymbolsOfAPairResponseInner>>>>
{
self.websocket_market_streams_api_client
.mark_price_of_all_symbols_of_a_pair(params)
.await
}
/// Mark Price Stream
///
/// Mark price update stream
///
/// Update Speed: 3000ms OR 1000ms
///
/// # Arguments
///
/// - `params`: [`MarkPriceStreamParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::MarkPriceStreamResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Mark-Price-Stream).
///
pub async fn mark_price_stream(
&self,
params: MarkPriceStreamParams,
) -> anyhow::Result<Arc<WebsocketStream<models::MarkPriceStreamResponse>>> {
self.websocket_market_streams_api_client
.mark_price_stream(params)
.await
}
/// Partial Book Depth Streams
///
/// Top **<levels\>** bids and asks, Valid **<levels\>** are 5, 10, or 20.
///
/// Update Speed: 250ms, 500ms or 100ms
///
/// # Arguments
///
/// - `params`: [`PartialBookDepthStreamsParams`]
/// The parameters for this operation.
///
/// # Returns
///
/// [`Arc<WebsocketStream<models::PartialBookDepthStreamsResponse>>`] on success.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the stream request fails, if parameters are invalid, or if parsing the response fails.
///
///
/// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/derivatives/coin-margined-futures/websocket-market-streams/Partial-Book-Depth-Streams).
///
pub async fn partial_book_depth_streams(
&self,
params: PartialBookDepthStreamsParams,
) -> anyhow::Result<Arc<WebsocketStream<models::PartialBookDepthStreamsResponse>>> {
self.websocket_market_streams_api_client
.partial_book_depth_streams(params)
.await
}
}