Skip to main content

WebSocketClient Setup

The WebSocketClient connects to the Limitless Exchange WebSocket server for real-time market data, position updates, order lifecycle events, and transaction notifications.

Constructor Options

Public subscriptions (market prices) do not require authentication. Authenticated subscriptions (positions, order events, transactions) require hmacCredentials — see Authentication to generate a token.

Public Subscriptions

Market Prices

Subscribe to real-time price updates for one or more markets. No authentication required.
Subscriptions replace previous ones. To listen to both CLOB (by slug) and AMM (by address) markets, include both marketSlugs and marketAddresses in a single subscribe_market_prices call.

Authenticated Subscriptions

These subscriptions require hmacCredentials passed to the constructor. The SDK signs the WebSocket handshake automatically.

Positions

Subscribe to real-time updates when your positions change:

Order Events

Subscribe to CLOB order lifecycle and settlement events for your account:
orderEvent uses source as a discriminator:
  • source: 'OME' — off-chain order state changes: placement, update, cancellation.
  • source: 'SETTLEMENT' — on-chain settlement results for the taker order and each matched maker order.
For settlement events, clientOrderId is the id of the recipient’s own orderId. If only one side of a trade supplied a clientOrderId, only that side’s event includes it. Counterparty order ids inside takerOrderId or makerMatches[] are not resolved to client ids.

Transactions

Subscribe to transaction confirmations:

Events

orderbookUpdate (CLOB markets)

Fired when a CLOB market orderbook changes. Contains the full updated orderbook.

newPriceData (AMM markets)

Fired when AMM market prices update.

positions

Fired when any of your positions change (fill, cancel, resolution).

tx

Fired on transaction events related to your account.

Type Definitions

Connection Management

Disconnect handling

Listen for disconnections and clean up resources:
When autoReconnect is enabled, the client automatically attempts to reconnect. However, you must re-send your subscriptions after reconnection. Listen for the reconnect event to resubscribe.

Graceful shutdown

Clean up the WebSocket connection on process exit:

Debugging

Log all raw events to inspect the data the server sends:
Use raw event logging during development to discover event shapes and debug subscription issues. Remove it before deploying to production.

Full Example

A complete script that subscribes to market prices and positions: