Skip to main content
Molecule exposes signed WebSocket streams for every major account and market event. Use these streams to receive low-latency updates on your orders, fills, positions, and balances without polling the REST API, and to consume live order book depth and public trade prints for market-making or monitoring strategies. All WebSocket URLs are authenticated with the same Ed25519 credentials used for REST requests — the SDK signs the connection URL automatically.

Available Streams

Authentication

WebSocket connections are authenticated using signed query parameters rather than headers. The SDK appends three parameters to every WebSocket URL it constructs: The canonical WebSocket message format is:
The signature covers the path and any stream-specific query parameters (such as subaccount_id or instrument_id) but excludes the signing parameters themselves to avoid circular dependencies. You do not need to construct this manually — the SDK handles it whenever a key_id and private_key are configured.
The signed timestamp must be within 30 seconds of the server clock. Connections with a stale timestamp are rejected with an unauthorized / stale_timestamp error.

Connecting with the SDK

client.iter_ws(path, params)

The primary way to consume a stream is client.iter_ws(path, params). It returns a synchronous iterator that yields parsed JSON messages from the stream. The iterator blocks until the connection closes or an exception is raised. Subscribe to order updates:
Subscribe to order book updates for a specific instrument:

Obtaining a Signed URL

If you prefer to manage the WebSocket connection yourself — for example, using a library with reconnect logic or async support — retrieve a pre-signed URL with client.ws.url(path, params) or a convenience method, and pass it to your WebSocket client.

Convenience URL Methods

The client.ws sub-client provides named methods for every available stream. Each method returns a fully signed URL string ready for direct use with any WebSocket library.

Stream Reference

client.iter_ws() is a synchronous, blocking iterator. It holds the calling thread open for the duration of the connection. To consume multiple streams concurrently, run each in a separate thread or use the signed URL methods (client.ws.*) with an async WebSocket library in an asyncio event loop.