binance_sdk/spot/websocket_api/handle.rs
1/*
2 * Spot WebSocket API
3 *
4 * Access market data, manage accounts, and trade on Binance Spot.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 *
9 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
10 * https://openapi-generator.tech
11 * Do not edit the class manually.
12 */
13
14use crate::{common::config::ConfigurationWebsocketApi, models::WebsocketApiConnectConfig};
15
16use super::WebsocketApi;
17
18#[derive(Clone)]
19pub struct WebsocketApiHandle {
20 configuration: ConfigurationWebsocketApi,
21}
22
23impl WebsocketApiHandle {
24 pub fn new(configuration: ConfigurationWebsocketApi) -> Self {
25 Self { configuration }
26 }
27
28 /// Connects to the WebSocket API using default configuration.
29 ///
30 /// # Returns
31 ///
32 /// A `Result` containing the connected `WebsocketApi` instance if successful,
33 /// or an error if the connection fails.
34 ///
35 /// # Errors
36 ///
37 /// Returns an [`anyhow::Error`] if the connection fails.
38 ///
39 pub async fn connect(&self) -> anyhow::Result<WebsocketApi> {
40 self.connect_with_config(Default::default()).await
41 }
42
43 /// Connects to the WebSocket API with a custom configuration.
44 ///
45 /// # Arguments
46 ///
47 /// * `cfg` - A configuration object specifying connection parameters.
48 ///
49 /// # Returns
50 ///
51 /// A `Result` containing the connected `WebsocketApi` instance if successful,
52 /// or an error if the connection fails.
53 ///
54 /// # Errors
55 ///
56 /// Returns an [`anyhow::Error`] if the connection fails.
57 ///
58 pub async fn connect_with_config(
59 &self,
60 cfg: WebsocketApiConnectConfig,
61 ) -> anyhow::Result<WebsocketApi> {
62 WebsocketApi::connect(self.configuration.clone(), cfg.mode).await
63 }
64}