Expand description
Python bindings for the Coinbase Intx 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>>
:
inner: Arc<RwLock<Option<WebSocketClient>>>
- The WebSocket connection.
Without shared state, clones would be independent, causing:
- Lost WebSocket messages.
- Missing instrument 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.
RwLock
is preferred over Mutex (many reads, few writes).