pub struct WebSocketConnector { /* private fields */ }Expand description
A connector for establishing WebSocket connections to the HTX WebSocket API.
The WebSocketConnector provides methods to create a new connector and connect to the WebSocket server.
It handles the initial connection setup and returns a WebSocketConnection for further operations.
§Examples
use bothan_htx::api::websocket::WebSocketConnector;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let connector = WebSocketConnector::new("wss://api.huobi.pro/ws");
let connection = connector.connect().await?;
Ok(())
}Implementations§
Source§impl WebSocketConnector
impl WebSocketConnector
Sourcepub fn new(url: impl Into<String>) -> Self
pub fn new(url: impl Into<String>) -> Self
Creates a new instance of WebSocketConnector with the given URL.
§Parameters
url: The WebSocket URL for the HTX API
§Returns
A new WebSocketConnector instance with the specified URL.
§Examples
use bothan_htx::api::websocket::WebSocketConnector;
let connector = WebSocketConnector::new("wss://api.huobi.pro/ws");Sourcepub async fn connect(&self) -> Result<WebSocketConnection, Error>
pub async fn connect(&self) -> Result<WebSocketConnection, Error>
Connects to the HTX WebSocket API.
This method establishes a WebSocket connection to the HTX server and returns
a WebSocketConnection instance for further operations.
§Returns
Returns a Result containing a WebSocketConnection on success,
or a tungstenite::Error if the connection fails.
§Examples
use bothan_htx::api::websocket::WebSocketConnector;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let connector = WebSocketConnector::new("wss://api.huobi.pro/ws");
let connection = connector.connect().await?;
Ok(())
}§Errors
Returns a tungstenite::Error if:
- The WebSocket connection cannot be established
- The URL is invalid
- Network connectivity issues occur
Trait Implementations§
Source§impl AssetInfoProviderConnector for WebSocketConnector
impl AssetInfoProviderConnector for WebSocketConnector
Source§fn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<WebSocketConnection, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<WebSocketConnection, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Connects to the HTX WebSocket API and returns a WebSocketConnection.
This method is part of the AssetInfoProviderConnector trait implementation,
providing a standardized way to establish WebSocket connections for asset workers.
Source§type Provider = WebSocketConnection
type Provider = WebSocketConnection
Auto Trait Implementations§
impl Freeze for WebSocketConnector
impl RefUnwindSafe for WebSocketConnector
impl Send for WebSocketConnector
impl Sync for WebSocketConnector
impl Unpin for WebSocketConnector
impl UnwindSafe for WebSocketConnector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request