# TypeScript SDK — WebSocket Reference

Every WebSocket stream and method, with the exact payload field names. WebSocket messages use a compact wire format with single-letter field names — this page maps each letter to its meaning so you never need to inspect the source.

All streams and methods are on `client.websocket`. See the [WebSocket guide](/tools/typescript-sdk/websocket) for lifecycle, reconnection, and usage patterns.

## Public streams

No authentication required. Each returns a `WebSocketStream<T>` you subscribe to with `.on("message", …)`.

| Method | Payload type | Description |
| --- | --- | --- |
| `trades(symbol, options?)` | `Trade` | Real-time trade prints |
| `bookTicker(symbol, options?)` | `BookTicker` | Best bid/ask updates |
| `depthUpdates(symbol, options?)` | `DepthUpdate` | Incremental order book diffs |
| `depth(symbol, options)` | `OrderBookSnapshot` | Periodic top-N depth snapshots (`options.levels`: 5, 10, or 20) |
| `contractStatus(options?)` | `ContractStatus` | Prediction market contract status changes |
| `rfqs(options?)` | `RfqPublicEvent` | Public request-for-quote events (**sandbox/planning only** — not enabled in production) |

## Authenticated streams

Require an `auth` strategy and the server entry point (browser WebSocket cannot set upgrade headers).

| Method | Payload type | Description |
| --- | --- | --- |
| `orders(options)` | `OrderUpdate` | Order lifecycle updates (`options.scope`: `"account"` or `"session"`) |
| `balances(options?)` | `BalanceUpdate` | Balance changes (`options.intervalMs`: 0 or 1000) |
| `positions(options?)` | `PositionReport` | Position updates (`options.intervalMs`: 0 or 1000) |
| `rfqDeliveries(options)` | `RfqPrivateDelivery` | Private RFQ delivery confirmations (`options.scope`) (**sandbox/planning only** — not enabled in production) |

## Request/response methods

These send a request and resolve with a response, rather than streaming.

| Method | Returns | Description |
| --- | --- | --- |
| `placeOrder(params, options?)` | `OrderActionResponse` | Place an order over WebSocket |
| `cancelOrder(params, options?)` | `OrderActionResponse` | Cancel a single order |
| `cancelAllOrders(options)` | `OrderActionResponse` | Cancel all orders (`options.confirm` must be `true`) |
| `cancelSessionOrders(options)` | `OrderActionResponse` | Cancel session orders (`options.confirm` must be `true`) |
| `ping(options?)` | `GenericSuccessResponse` | Round-trip liveness check |
| `time(options?)` | `GenericSuccessResponse` | Server time |
| `conninfo(options?)` | `GenericSuccessResponse` | Connection info |
| `listSubscriptions(options?)` | `ListSubscriptionsResponse` | Current active subscriptions |
| `depthSnapshot(symbol, options?)` | `DepthResponse` | One-shot depth snapshot |

### RFQ quote methods

> **Note:** RFQ streams and methods are currently **sandbox/planning only** and are not enabled in production.

Accessed via `client.websocket.rfq`:

| Method | Params | Returns |
| --- | --- | --- |
| `rfq.submitQuote(params, options?)` | `RfqSubmitQuoteParams` | `RfqSubmitQuoteResponse` |
| `rfq.withdrawQuote(params, options?)` | `RfqWithdrawQuoteParams` | `RfqWithdrawQuoteResponse` |
| `rfq.confirmQuote(params, options?)` | `RfqConfirmQuoteParams` | `RfqConfirmQuoteResponse` |

## Wire format

WebSocket payloads use single-letter field names. These are the exact fields on each type. Prices and quantities are **decimal strings** (never floats — see [Data Types](/tools/typescript-sdk/deep-dives/data-types)); timestamps and IDs may be `bigint`.

### Trade

```ts
const trades = client.websocket.trades("BTCUSD");
trades.on("message", (t) => console.log(t.p, t.q, t.m));
```

| Field | Type | Meaning |
| --- | --- | --- |
| `E` | `number \| bigint` | Event time (nanoseconds) |
| `s` | `string` | Symbol |
| `t` | `number \| bigint` | Trade ID |
| `p` | `string` | Price |
| `q` | `string` | Quantity |
| `m` | `boolean` | Whether the buyer is the maker |

### BookTicker

| Field | Type | Meaning |
| --- | --- | --- |
| `u` | `number \| bigint` | Update ID |
| `E` | `number \| bigint` | Event time (nanoseconds) |
| `s` | `string` | Symbol |
| `b` | `string` | Best bid price |
| `B` | `string` | Best bid quantity |
| `a` | `string` | Best ask price |
| `A` | `string` | Best ask quantity |
| `c` | `string?` | Last trade price (present once the book has traded) |
| `C` | `string?` | Last trade quantity |

### DepthUpdate

| Field | Type | Meaning |
| --- | --- | --- |
| `e` | `"depthUpdate"` | Event type discriminator |
| `E` | `number \| bigint` | Event time (nanoseconds) |
| `s` | `string` | Symbol |
| `U` | `number \| bigint` | First update ID in this diff |
| `u` | `number \| bigint` | Last update ID in this diff |
| `b` | `string[][]` | Bid changes as `[price, quantity]` pairs |
| `a` | `string[][]` | Ask changes as `[price, quantity]` pairs |

A quantity of `"0"` means the level was removed. See [Order Book Reconstruction](/tools/typescript-sdk/deep-dives/order-book) for how the SDK applies these.

### OrderUpdate

```ts
const orders = client.websocket.orders({ scope: "session" });
orders.on("message", (o) => console.log(o.i, o.X, o.z));
```

| Field | Type | Meaning |
| --- | --- | --- |
| `e` | `"orderUpdate"` | Event type discriminator |
| `E` | `number \| bigint` | Event time (nanoseconds) |
| `s` | `string` | Symbol |
| `i` | `number \| bigint` | Order ID |
| `c` | `string?` | Client order ID |
| `S` | `"BUY" \| "SELL"` (optional) | Side |
| `o` | `"LIMIT" \| "MARKET" \| "STOP_LIMIT" \| "STOP_MARKET"` (optional) | Order type |
| `X` | `"NEW" \| "OPEN" \| "FILLED" \| "PARTIALLY_FILLED" \| "CANCELED" \| "REJECTED" \| "MODIFIED"` | Order status |
| `O` | `"YES" \| "NO"` (optional) | Prediction outcome |
| `p` | `string?` | Order price |
| `P` | `string?` | Stop price |
| `q` | `string?` | Order quantity |
| `z` | `string?` | Remaining quantity |
| `Z` | `string?` | Executed quantity (last fill for FILLED/PARTIALLY_FILLED; cumulative for CANCELED and other terminal events) |
| `L` | `string?` | Last fill price |
| `t` | `number \| bigint` (optional) | Trade ID of the last fill |
| `n` | `string?` | Commission |
| `m` | `boolean?` | Whether this order was the maker |
| `r` | `string?` | Reject reason |
| `T` | `number \| bigint` | Transaction time (nanoseconds) |

### BalanceUpdate

```ts
const balances = client.websocket.balances();
balances.on("message", (u) => {
  for (const b of u.B) console.log(b.a, b.f, b.c);
});
```

| Field | Type | Meaning |
| --- | --- | --- |
| `e` | `"balanceUpdate"` | Event type discriminator |
| `E` | `number \| bigint` | Event time (nanoseconds) |
| `u` | `number \| bigint` | Update ID |
| `B` | `Balance[]` | Balance entries |

Each `Balance`:

| Field | Type | Meaning |
| --- | --- | --- |
| `a` | `string` | Asset |
| `f` | `string` | Free (available) balance |
| `c` | `string` | Locked balance |

### PositionReport

| Field | Type | Meaning |
| --- | --- | --- |
| `e` | `"positionReport"` | Event type discriminator |
| `E` | `number \| bigint` | Event time (nanoseconds) |
| `u` | `number \| bigint` | Last account-update timestamp (nanoseconds) |
| `A` | `number \| bigint` | Account reference |
| `P` | `PositionRow[]` | Position entries |

Each `PositionRow`:

| Field | Type | Meaning |
| --- | --- | --- |
| `t` | `string` | Type |
| `s` | `string` | Symbol |
| `a` | `NamedAmount[]` | Named amounts for the position |

### ContractStatus

| Field | Type | Meaning |
| --- | --- | --- |
| `e` | `"contractStatus"` | Event type discriminator |
| `E` | `number \| bigint` | Event time (milliseconds) |
| `s` | `string` | Symbol |
| `k` | `string` | Event ticker |
| `c` | `string` | Contract ticker |
| `i` | `number \| bigint` | Contract ID |
| `p` | `string?` | Price |
| `o` | `string` | Previous status |
| `n` | `string` | New status |

## What's next

- [Order Book Reconstruction](/tools/typescript-sdk/deep-dives/order-book) — how depth diffs become a live book
- [RFQ Protocol](/tools/typescript-sdk/deep-dives/rfq) — the request-for-quote maker flow
- [Data Types](/tools/typescript-sdk/deep-dives/data-types) — why timestamps are `bigint` and prices are strings
