pub struct KrakenFuturesWebSocketClient { /* private fields */ }Expand description
WebSocket client for the Kraken Futures v1 streaming API.
Implementations§
Source§impl KrakenFuturesWebSocketClient
impl KrakenFuturesWebSocketClient
Sourcepub fn new(url: String, heartbeat_secs: u64, proxy_url: Option<String>) -> Self
pub fn new(url: String, heartbeat_secs: u64, proxy_url: Option<String>) -> Self
Creates a new client with the given URL.
Sourcepub fn with_credentials(
url: String,
heartbeat_secs: u64,
credential: Option<KrakenCredential>,
auth_timeout_secs: Option<u64>,
transport_backend: TransportBackend,
proxy_url: Option<String>,
) -> Self
pub fn with_credentials( url: String, heartbeat_secs: u64, credential: Option<KrakenCredential>, auth_timeout_secs: Option<u64>, transport_backend: TransportBackend, proxy_url: Option<String>, ) -> Self
Creates a new client with API credentials for authenticated feeds.
Sourcepub fn with_socket_control(self, control: SocketControl) -> Self
pub fn with_socket_control(self, control: SocketControl) -> Self
Configures socket state reporting and reconnect control.
Sourcepub fn has_credentials(&self) -> bool
pub fn has_credentials(&self) -> bool
Returns true if the client has API credentials set.
Sourcepub async fn wait_until_active(
&self,
timeout_secs: f64,
) -> Result<(), KrakenWsError>
pub async fn wait_until_active( &self, timeout_secs: f64, ) -> Result<(), KrakenWsError>
Waits until the WebSocket connection is active or timeout.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Returns true if the WebSocket is authenticated for private feeds.
Sourcepub async fn wait_until_authenticated(
&self,
timeout_secs: f64,
) -> Result<(), KrakenWsError>
pub async fn wait_until_authenticated( &self, timeout_secs: f64, ) -> Result<(), KrakenWsError>
Waits until the WebSocket is authenticated or the timeout elapses.
Returns an error on timeout or explicit auth failure.
Sourcepub async fn authenticate(&self) -> Result<(), KrakenWsError>
pub async fn authenticate(&self) -> Result<(), KrakenWsError>
Authenticates the WebSocket connection for private feeds.
Sends a challenge request and waits for the handler to parse the response,
sign it, and mark the AuthTracker successful. Private subscriptions gate
on the stored challenge / signed-challenge pair.
Sourcepub async fn connect(&mut self) -> Result<(), KrakenWsError>
pub async fn connect(&mut self) -> Result<(), KrakenWsError>
Connects to the WebSocket server.
Sourcepub async fn disconnect(&mut self) -> Result<(), KrakenWsError>
pub async fn disconnect(&mut self) -> Result<(), KrakenWsError>
Disconnects from the WebSocket server.
Sourcepub async fn close(&mut self) -> Result<(), KrakenWsError>
pub async fn close(&mut self) -> Result<(), KrakenWsError>
Closes the WebSocket connection.
Sourcepub async fn subscribe_mark_price(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_mark_price( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to mark price updates for the given instrument.
Sourcepub async fn unsubscribe_mark_price(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_mark_price( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from mark price updates for the given instrument.
Sourcepub async fn subscribe_index_price(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_index_price( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to index price updates for the given instrument.
Sourcepub async fn unsubscribe_index_price(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_index_price( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from index price updates for the given instrument.
Sourcepub async fn subscribe_funding_rate(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_funding_rate( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to funding rate updates for the given instrument.
Sourcepub async fn unsubscribe_funding_rate(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_funding_rate( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from funding rate updates for the given instrument.
Sourcepub async fn subscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_quotes( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to quote updates for the given instrument.
Uses the order book channel for low-latency top-of-book quotes.
Sourcepub async fn unsubscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_quotes( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from quote updates for the given instrument.
Sourcepub async fn subscribe_trades(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_trades( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to trade updates for the given instrument.
Sourcepub async fn unsubscribe_trades(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_trades( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from trade updates for the given instrument.
Sourcepub async fn subscribe_book(
&self,
instrument_id: InstrumentId,
_depth: Option<u32>,
) -> Result<(), KrakenWsError>
pub async fn subscribe_book( &self, instrument_id: InstrumentId, _depth: Option<u32>, ) -> Result<(), KrakenWsError>
Subscribes to order book updates for the given instrument.
Note: The depth parameter is accepted for API compatibility with spot client but is
not used by Kraken Futures (full book is always returned).
Sourcepub async fn unsubscribe_book(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_book( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from order book updates for the given instrument.
Sourcepub fn take_output_rx(
&mut self,
) -> Option<UnboundedReceiver<KrakenFuturesWsMessage>>
pub fn take_output_rx( &mut self, ) -> Option<UnboundedReceiver<KrakenFuturesWsMessage>>
Gets the output receiver for processed messages.
Sourcepub async fn set_auth_credentials(
&self,
original_challenge: String,
signed_challenge: String,
) -> Result<(), KrakenWsError>
pub async fn set_auth_credentials( &self, original_challenge: String, signed_challenge: String, ) -> Result<(), KrakenWsError>
Set authentication credentials directly (for when challenge is obtained externally).
Sourcepub fn sign_challenge(&self, challenge: &str) -> Result<String, KrakenWsError>
pub fn sign_challenge(&self, challenge: &str) -> Result<String, KrakenWsError>
Sign a challenge with the API credentials.
Returns the signed challenge on success.
Sourcepub async fn authenticate_with_challenge(
&self,
challenge: &str,
) -> Result<(), KrakenWsError>
pub async fn authenticate_with_challenge( &self, challenge: &str, ) -> Result<(), KrakenWsError>
Complete authentication with a received challenge.
Sourcepub fn set_account_id(&self, account_id: AccountId)
pub fn set_account_id(&self, account_id: AccountId)
Sets the account ID for execution report parsing.
Sourcepub fn account_id(&self) -> Option<AccountId>
pub fn account_id(&self) -> Option<AccountId>
Returns the account ID if set.
Returns a reference to the shared account ID.
Sourcepub fn truncated_id_map(&self) -> &Arc<AtomicMap<String, ClientOrderId>> ⓘ
pub fn truncated_id_map(&self) -> &Arc<AtomicMap<String, ClientOrderId>> ⓘ
Returns a reference to the truncated ID map.
Sourcepub fn order_instrument_map(&self) -> &Arc<AtomicMap<String, InstrumentId>> ⓘ
pub fn order_instrument_map(&self) -> &Arc<AtomicMap<String, InstrumentId>> ⓘ
Returns a reference to the order-to-instrument map.
Returns a reference to the shared instruments map.
Sourcepub fn subscriptions(&self) -> &SubscriptionState
pub fn subscriptions(&self) -> &SubscriptionState
Returns a reference to the subscription state.
Sourcepub fn cache_instrument(&self, instrument: InstrumentAny)
pub fn cache_instrument(&self, instrument: InstrumentAny)
Caches an instrument for execution report parsing.
Sourcepub fn cache_instruments(&self, instruments: &[InstrumentAny])
pub fn cache_instruments(&self, instruments: &[InstrumentAny])
Caches multiple instruments for execution report parsing.
Sourcepub fn cache_client_order(
&self,
client_order_id: ClientOrderId,
venue_order_id: Option<VenueOrderId>,
instrument_id: InstrumentId,
_trader_id: TraderId,
_strategy_id: StrategyId,
)
pub fn cache_client_order( &self, client_order_id: ClientOrderId, venue_order_id: Option<VenueOrderId>, instrument_id: InstrumentId, _trader_id: TraderId, _strategy_id: StrategyId, )
Caches a client order for truncated ID resolution and instrument lookup.
Kraken Futures limits client order IDs to 18 characters, so orders with longer IDs are truncated. This method stores the mapping from truncated to full ID, and from venue order ID to instrument ID for cancel messages.
Sourcepub async fn subscribe_open_orders(&self) -> Result<(), KrakenWsError>
pub async fn subscribe_open_orders(&self) -> Result<(), KrakenWsError>
Subscribes to open orders feed (private, requires authentication).
Sourcepub async fn subscribe_fills(&self) -> Result<(), KrakenWsError>
pub async fn subscribe_fills(&self) -> Result<(), KrakenWsError>
Subscribes to fills feed (private, requires authentication).
Sourcepub async fn subscribe_executions(&self) -> Result<(), KrakenWsError>
pub async fn subscribe_executions(&self) -> Result<(), KrakenWsError>
Subscribes to both open orders and fills (convenience method).
Trait Implementations§
Source§impl Clone for KrakenFuturesWebSocketClient
impl Clone for KrakenFuturesWebSocketClient
Auto Trait Implementations§
impl !Freeze for KrakenFuturesWebSocketClient
impl !RefUnwindSafe for KrakenFuturesWebSocketClient
impl !UnwindSafe for KrakenFuturesWebSocketClient
impl Send for KrakenFuturesWebSocketClient
impl Sync for KrakenFuturesWebSocketClient
impl Unpin for KrakenFuturesWebSocketClient
impl UnsafeUnpin for KrakenFuturesWebSocketClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more