Expand description
Python bindings for the Kraken WebSocket client.
§Design Pattern: Clone and Share State
The WebSocket client must be cloned for async operations because PyO3’s future_into_py
requires 'static futures (cannot borrow from self). To ensure clones share the same
connection state, key fields use Arc:
ws_client: Option<Arc<WebSocketClient>>- The WebSocket connection.subscriptions: Arc<DashMap<String, KrakenWsChannel>>- Subscription tracking.
Without shared state, clones would be independent, causing:
- Lost WebSocket messages.
- Missing subscription data.
- Connection state desynchronization.
§Connection Flow
- Clone the client for async operation.
- Connect and populate shared state on the clone.
- Spawn stream handler as background task.
- Return immediately (non-blocking).
§Important Notes
- Never use
block_on()- it blocks the runtime. - Always clone before async blocks for lifetime requirements.