> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baibai.cx/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket requests and subscriptions

> Hyperliquid action requests, order and fill subscriptions, and reconnects.

Connect to `/ws` on the base URL supplied by Spire. This endpoint uses Hyperliquid's WebSocket wire. It sends no session greeting and requires no book snapshot or per-connection account binding.

## Send actions or queries

Wrap the same signed request you would send to `POST /exchange`:

```json theme={null}
{
  "method": "post",
  "id": 42,
  "request": {"type": "action", "payload": {"action": {}, "nonce": 0, "signature": {}}}
}
```

The empty action/signature above marks where your SDK-generated signed request goes. The response echoes your ID:

```json theme={null}
{
  "channel": "post",
  "data": {
    "id": 42,
    "response": {
      "type": "action",
      "payload": {"status":"ok","response":{"type":"order","data":{"statuses":[{"resting":{"oid":123}}]}}}
    }
  }
}
```

For reads, use `request.type: "info"` and the ordinary `/info` payload. Match replies by ID; subscription messages may arrive between them.

## Subscribe

```json theme={null}
{"method":"subscribe","subscription":{"type":"orderUpdates","user":"YOUR_MASTER_ADDRESS"}}
```

Use the full master address in place of the placeholder. The server acknowledges on `subscriptionResponse`. Supported subscriptions are:

| Type           | Fields and messages                                                     |
| -------------- | ----------------------------------------------------------------------- |
| `orderUpdates` | `user`; arrays of `{order,status,statusTimestamp}`                      |
| `userFills`    | `user`; starts with `{isSnapshot:true,user,fills}` then sends new fills |
| `l2Book`       | `coin`, such as `@0`; up to 20 levels per side with `{px,sz,n}`         |
| `allMids`      | no required fields; `{mids:{...}}`                                      |

Unsubscribe by sending the same subscription with `method:"unsubscribe"`. Queries and subscriptions for a user address are public, as on Hyperliquid. Book price aggregation and `aggregateByTime:true` are unsupported and rejected.

## Keep alive and reconnect

Send `{"method":"ping"}` periodically; the reply is `{"channel":"pong"}`. The connection closes after 60 seconds without a received message. Limits are 32 subscriptions per connection and 1 MiB per input message. Slow consumers are disconnected when their output queue fills or they fall behind retained events.

GTC orders remain open after disconnect. On reconnect, query `openOrders` and `userFills`, restore subscriptions, and deduplicate fills by master and `tid`. The fill snapshot is bounded to the latest 2000 records. Persist your own history; no `fill_ack` is required. See [fills](/makers/fills).
