Connect to the WebSocket server.
Disconnect from the WebSocket server.
Signals all active generators to stop before closing the connection, so consumers are unblocked immediately even if the close handshake is slow.
Check if connected.
Check if permanently terminated (max reconnect attempts exhausted or disconnected).
Subscribe to balance updates. Returns an AsyncGenerator yielding BalanceUpdate messages.
Subscribe to order book depth updates.
The market ID (hex string).
A validated DepthPrecision created via
depthPrecision(level) where level is 1–18. The high-level
O2Client.streamDepth creates this automatically from a plain number.
An async generator yielding DepthUpdate messages.
Stream WebSocket connection lifecycle events.
Yields ConnectionEvent objects whenever the connection state changes. Use this to detect reconnects and re-sync state from the REST API — messages received during the disconnect window are lost.
Subscribe to nonce updates. Returns an AsyncGenerator yielding NonceUpdate messages.
Subscribe to order updates. Returns an AsyncGenerator yielding OrderUpdate messages.
Subscribe to trade updates. Returns an AsyncGenerator yielding TradeUpdate messages.
Unsubscribe from depth updates for a market.
Unsubscribe from order updates.
Unsubscribe from trade updates for a market.
WebSocket client for O2 Exchange real-time data streams.
Use via O2Client.streamDepth, O2Client.streamOrders, etc. for the simplest interface, or create a standalone instance for advanced use cases.
Example