pub struct SpotWsClient { /* private fields */ }Expand description
Kraken Spot WebSocket client.
Provides methods to connect to public and private WebSocket channels with automatic reconnection and subscription restoration.
Implementations§
Source§impl SpotWsClient
impl SpotWsClient
Sourcepub fn with_config(config: WsConfig) -> Self
pub fn with_config(config: WsConfig) -> Self
Create a new WebSocket client with custom configuration.
Sourcepub fn with_urls(
public_url: impl Into<String>,
auth_url: impl Into<String>,
) -> Self
pub fn with_urls( public_url: impl Into<String>, auth_url: impl Into<String>, ) -> Self
Create a client with custom URLs (useful for testing).
Sourcepub fn public_url(&self) -> &str
pub fn public_url(&self) -> &str
Get the public WebSocket URL.
Sourcepub async fn connect_public(&self) -> Result<KrakenStream, KrakenError>
pub async fn connect_public(&self) -> Result<KrakenStream, KrakenError>
Connect to the public WebSocket endpoint.
Returns a stream of market data messages.
§Example
ⓘ
use kraken_api_client::spot::ws::SpotWsClient;
use kraken_api_client::spot::ws::messages::{SubscribeParams, channels};
use futures_util::StreamExt;
let client = SpotWsClient::new();
let mut stream = client.connect_public().await?;
// Subscribe to ticker updates
stream.subscribe(SubscribeParams::public(channels::TICKER, vec!["BTC/USD".into()])).await?;
while let Some(msg) = stream.next().await {
println!("Message: {:?}", msg);
}Sourcepub async fn connect_public_with_config(
&self,
config: WsConfig,
) -> Result<KrakenStream, KrakenError>
pub async fn connect_public_with_config( &self, config: WsConfig, ) -> Result<KrakenStream, KrakenError>
Connect to the public WebSocket endpoint with custom configuration.
Sourcepub async fn connect_private(
&self,
token: impl Into<String>,
) -> Result<KrakenStream, KrakenError>
pub async fn connect_private( &self, token: impl Into<String>, ) -> Result<KrakenStream, KrakenError>
Connect to the private (authenticated) WebSocket endpoint.
Requires a valid WebSocket token obtained from the REST API.
§Example
ⓘ
use kraken_api_client::spot::ws::SpotWsClient;
use kraken_api_client::spot::rest::SpotRestClient;
use kraken_api_client::auth::StaticCredentials;
use kraken_api_client::spot::ws::messages::{SubscribeParams, channels};
use futures_util::StreamExt;
use std::sync::Arc;
// First, get a WebSocket token from the REST API
let credentials = Arc::new(StaticCredentials::new("api_key", "api_secret"));
let rest_client = SpotRestClient::builder().credentials(credentials).build();
let token_response = rest_client.get_websocket_token().await?;
// Then connect to the private WebSocket
let ws_client = SpotWsClient::new();
let mut stream = ws_client.connect_private(token_response.token).await?;
// Subscribe to execution updates
stream.subscribe(SubscribeParams::private(channels::EXECUTIONS, &token_response.token)).await?;
while let Some(msg) = stream.next().await {
println!("Message: {:?}", msg);
}Sourcepub async fn connect_private_with_config(
&self,
token: impl Into<String>,
config: WsConfig,
) -> Result<KrakenStream, KrakenError>
pub async fn connect_private_with_config( &self, token: impl Into<String>, config: WsConfig, ) -> Result<KrakenStream, KrakenError>
Connect to the private WebSocket endpoint with custom configuration.
Trait Implementations§
Source§impl Clone for SpotWsClient
impl Clone for SpotWsClient
Source§fn clone(&self) -> SpotWsClient
fn clone(&self) -> SpotWsClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpotWsClient
impl Debug for SpotWsClient
Auto Trait Implementations§
impl Freeze for SpotWsClient
impl RefUnwindSafe for SpotWsClient
impl Send for SpotWsClient
impl Sync for SpotWsClient
impl Unpin for SpotWsClient
impl UnwindSafe for SpotWsClient
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
Mutably borrows from an owned value. Read more