Skip to main content
The Molecule WebSocket API delivers real-time event streams for orders, fills, positions, balances, order books, and trade prints. Rather than polling REST endpoints, you subscribe to the relevant stream and receive pushed updates as events occur on the platform. All WebSocket connections authenticate via signed query parameters derived from your Ed25519 key — the SDK generates these URLs automatically.

Available endpoints


Authentication

WebSocket connections authenticate via signed query parameters rather than HTTP headers. The query string includes three parameters: The SDK’s client.ws.*() methods generate correctly signed URLs automatically. Pass any additional filter parameters (such as subaccount_id or instrument_id) as a dict — they are merged into the signed query string.
Signed URLs expire after 30 seconds. Generate a fresh URL for each new connection; do not cache and reuse a previously signed URL.

Consuming messages

The SDK provides two patterns for consuming WebSocket streams:

Pattern 1: client.iter_ws — blocking iterator

client.iter_ws(path, params) connects to the signed URL, then yields parsed JSON objects for each message received. This is the simplest pattern for synchronous consumers.
client.iter_ws requires the websockets package. Install it with pip install websockets if it is not already present in your environment. The iterator blocks until the connection closes or raises an exception.

Pattern 2: client.ws.url — signed URL for any WebSocket library

client.ws.url(path, params) returns a signed wss:// URL you can pass to any WebSocket library — useful when integrating with async frameworks or custom reconnection logic.

client.iter_ws

Blocking generator. Simplest way to consume a single stream synchronously. Connect, iterate, done.

client.ws.url

Returns a signed URL. Use with any WebSocket library, async framework, or custom reconnect wrapper.

Path aliases

When calling client.ws.url() or client.iter_ws(), you can pass either the full path or a short alias:
See the Streams reference for per-stream URL builder methods and their parameters.