binance_sdk/spot/websocket_streams/handle.rs
1/*
2 * Binance Spot WebSocket Streams
3 *
4 * OpenAPI Specifications for the Binance Spot WebSocket Streams
5 *
6 * API documents:
7 * - [Github web-socket-streams documentation file](https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md)
8 * - [General API information for web-socket-streams on website](https://developers.binance.com/docs/binance-spot-api-docs/web-socket-streams)
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
19use crate::{common::config::ConfigurationWebsocketStreams, models::WebsocketStreamsConnectConfig};
20
21use super::WebsocketStreams;
22
23#[derive(Clone)]
24pub struct WebsocketStreamsHandle {
25 configuration: ConfigurationWebsocketStreams,
26}
27
28impl WebsocketStreamsHandle {
29 #[must_use]
30 pub fn new(configuration: ConfigurationWebsocketStreams) -> Self {
31 Self { configuration }
32 }
33
34 /// Connects to a WebSocket stream using default configuration.
35 ///
36 /// # Returns
37 ///
38 /// A `Result` containing a `WebsocketStreams` instance if the connection is successful,
39 /// or an error if the connection fails.
40 ///
41 /// # Errors
42 ///
43 /// Returns an [`anyhow::Error`] if the connection fails.
44 ///
45 /// # Examples
46 ///
47 ///
48 /// let handle = `WebsocketStreamsHandle::new(configuration)`;
49 /// let streams = handle.connect().await?;
50 ///
51 pub async fn connect(&self) -> anyhow::Result<WebsocketStreams> {
52 self.connect_with_config(Default::default()).await
53 }
54
55 /// Connects to a WebSocket stream with a custom configuration.
56 ///
57 /// # Arguments
58 ///
59 /// * `cfg` - A configuration object specifying connection details for the WebSocket stream.
60 ///
61 /// # Returns
62 ///
63 /// A `Result` containing a `WebsocketStreams` instance if the connection is successful,
64 /// or an error if the connection fails.
65 ///
66 /// # Errors
67 ///
68 /// Returns an [`anyhow::Error`] if the connection fails.
69 ///
70 /// # Examples
71 ///
72 ///
73 /// let handle = `WebsocketStreamsHandle::new(configuration)`;
74 /// let `custom_config` = `WebsocketStreamsConnectConfig::default()`;
75 /// let streams = `handle.connect_with_config(custom_config).await`?;
76 ///
77 pub async fn connect_with_config(
78 &self,
79 cfg: WebsocketStreamsConnectConfig,
80 ) -> anyhow::Result<WebsocketStreams> {
81 WebsocketStreams::connect(self.configuration.clone(), cfg.streams, cfg.mode).await
82 }
83}