/*
* Prediction Trading Streams
*
* Binance Web3 Prediction pushes 14 kinds of real-time events over the Binance SApi WebSocket channel, covering market and limit trading, reward claims, fund transfers and market resolution, plus order book (bid/ask) quotes per market. Trading events go only to the user they belong to; order book quotes go to everyone subscribed. A message may occasionally be missed, order is not guaranteed, and nothing is stored while you are offline — after reconnecting, fetch the latest state from the REST API and drop duplicates using `pushId` (business events) or `marketId` + `updateTimestampMs` (order book).
*
* 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.
*/
use crate::{common::config::ConfigurationWebsocketStreams, models::WebsocketStreamsConnectConfig};
use super::WebsocketStreams;
#[derive(Clone)]
pub struct WebsocketStreamsHandle {
configuration: ConfigurationWebsocketStreams,
}
impl WebsocketStreamsHandle {
#[must_use]
pub fn new(configuration: ConfigurationWebsocketStreams) -> Self {
Self { configuration }
}
/// Connects to a WebSocket stream using default configuration.
///
/// # Returns
///
/// A `Result` containing a `WebsocketStreams` instance if the connection is successful,
/// or an error if the connection fails.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the connection fails.
///
/// # Examples
///
///
/// let handle = `WebsocketStreamsHandle::new(configuration)`;
/// let streams = handle.connect().await?;
///
pub async fn connect(&self) -> anyhow::Result<WebsocketStreams> {
self.connect_with_config(Default::default()).await
}
/// Connects to a WebSocket stream with a custom configuration.
///
/// # Arguments
///
/// * `cfg` - A configuration object specifying connection details for the WebSocket stream.
///
/// # Returns
///
/// A `Result` containing a `WebsocketStreams` instance if the connection is successful,
/// or an error if the connection fails.
///
/// # Errors
///
/// Returns an [`anyhow::Error`] if the connection fails.
///
/// # Examples
///
///
/// let handle = `WebsocketStreamsHandle::new(configuration)`;
/// let `custom_config` = `WebsocketStreamsConnectConfig::default()`;
/// let streams = `handle.connect_with_config(custom_config).await`?;
///
pub async fn connect_with_config(
&self,
cfg: WebsocketStreamsConnectConfig,
) -> anyhow::Result<WebsocketStreams> {
WebsocketStreams::connect(self.configuration.clone(), cfg.streams, cfg.mode).await
}
}