Module websocket

Module websocket 

Source
Expand description

Python bindings for the Deribit 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<RwLock<T>>:

  • Connection mode and signal are shared via Arc.

§Connection Flow

  1. Clone the client for async operation.
  2. Connect and populate shared state on the clone.
  3. Spawn stream handler as background task.
  4. Return immediately (non-blocking).

§Important Notes

  • Never use block_on() - it blocks the runtime.
  • Always clone before async blocks for lifetime requirements.