# Write WebSocket — `/v1/exchange/ws`

The write WebSocket is the low-latency path for `place`, `modify`, and
`cancel` requests. It also carries [maintenance announcements](#maintenance-announcements).
An order frame carries one `POST /v1/exchange` request, and its answer is the
`POST /v1/exchange` answer with the frame's `id`. A subscription frame uses
`method` and `subscription`. The connection takes an API key:

```http
Authorization: Bearer <your-api-key>
```

Production URL: `wss://production.mosaiq.0d.finance/v1/exchange/ws`.

Heartbeats and per-IP connection limits are shared with the
[user-data WebSocket](/api/websocket#heartbeats). For socket layout,
pipelining, and recovery, see [Optimizing latency](/api/optimizing-latency).

## Cancel on disconnect

```text
wss://production.mosaiq.0d.finance/v1/exchange/ws?cancelAllOnDisconnect=true&reconnectGraceMs=2000
```

| Query parameter | Default | Description |
| --- | --- | --- |
| `cancelAllOnDisconnect` | `false` | Cancel the user's open orders after the last opted-in write connection disconnects. |
| `reconnectGraceMs` | `2000` | Delay before cancelling so an opted-in reconnect can suppress it. Requires `cancelAllOnDisconnect=true`; maximum `30000`. |

Only opted-in connections participate. Cancellation starts after the last
one disconnects and its pending requests finish. Reconnecting with the option
inside the grace window prevents cancellation. A heartbeat timeout counts as
a disconnect. Unknown query parameters or values that cannot be parsed fail
the upgrade with HTTP `400 invalid_request` and the detail `invalid_query`. A
`reconnectGraceMs` above `30000`, or supplied without
`cancelAllOnDisconnect=true`, returns HTTP `400 invalid_request` with the
detail `bad_request`.

During a planned server shutdown, Mosaiq also attempts to cancel these orders
without waiting for `reconnectGraceMs`.

The option also protects your Hyperliquid quotes while Mosaiq moves USDC on
one of its Hyperliquid accounts. Mosaiq cancels your Hyperliquid orders on that
account first, and refuses your places and modifies there with the detail
`account_operation_in_progress` until the move is done.
[Account operations](/api/optimizing-latency#account-operations) gives the
steps and the limits. The protection covers you while an opted-in connection
is open, and after the last one closes until its cancellation ends.

After the grace window, Mosaiq attempts to cancel every open order. Retries
are limited and can stop with orders still open. Waiting for a venue to
recover can extend cancellation beyond a few seconds. Each retry targets
every order open at that moment, including orders placed while it waited.

If you reconnect with `cancelAllOnDisconnect=true` before cancellation
completes, Mosaiq stops retrying and leaves your remaining orders open. Cancels
it already sent still complete, so an order can still disappear shortly after
you reconnect. On every reconnect, query
[`GET /v1/openOrders`](/api/open-orders), watch `orderUpdates` for cancels that
complete late, and cancel the orders you no longer want. A reconnect without
the option does not stop cancellation.

While a venue connection is halted, cancellation has no time limit: it waits
for that venue to accept cancels again. A reconnect without
`cancelAllOnDisconnect=true` does not stop it, so orders you place meanwhile,
on any venue, are cancelled when it finally runs.

:::warning\[Best effort only]
A process crash, a venue failure, or a partial cancellation can leave orders
open. After reconnecting, reconcile with
[`GET /v1/openOrders`](/api/open-orders) and cancel explicitly.
:::

## Venue client order ids

```text
wss://production.mosaiq.0d.finance/v1/exchange/ws?includeVenueCloid=true
```

| Query parameter | Default | Description |
| --- | --- | --- |
| `includeVenueCloid` | `false` | Add `venueCloid` to the `accepted` items of place and modify answers on this connection. |

`venueCloid` is the client order id that Mosaiq gave the order at its venue.
Use it to find your orders in venue data, as
[Find your orders in venue data](/api/exchange#find-your-orders-in-venue-data)
explains. With the parameter, an accepted place or modify item also answers
`venueCloid`, as on REST. A cancel item never carries it. Without the
parameter, no item carries `venueCloid`. `orderUpdates` rows on `/v1/ws`
name `venueCloid` only when that connection sets the same parameter. You can
combine the parameter with
`cancelAllOnDisconnect`. A value that cannot be parsed fails the upgrade with
HTTP `400 invalid_request` and the detail `invalid_query`.

Mosaiq seals every Hyperliquid place that names its `c` with your account's
key, so you can recognize your orders in Hyperliquid data before the answer
arrives. See [Keyed venue cloids](/api/optimizing-latency#keyed-venue-cloids).
If Mosaiq cannot get your account's key when you connect, the upgrade fails
with HTTP `503 temporarily_unavailable` and the detail
`venue_cloid_keys_unavailable`. Retry the connection.

## Answer format

```text
wss://production.mosaiq.0d.finance/v1/exchange/ws?nestedFormat=false
```

| Query parameter | Default | Description |
| --- | --- | --- |
| `nestedFormat` | `true` | `false` answers each frame with the body of `POST /v1/exchange` and the frame's `id`, as [Answers](#answers) shows. `true` keeps Hyperliquid's `post` envelope, the answer of earlier releases. |

Open your connections with `nestedFormat=false`. Mosaiq still answers the
`post` envelope by default, so a client of earlier releases keeps working
while it switches. A later release will answer only the REST body. Mosaiq
announces that release, and its date, before it ships.
[Migrate from the post envelope](#migrate-from-the-post-envelope) maps one
format to the other. A value that cannot be parsed fails the upgrade with
HTTP `400 invalid_request` and the detail `invalid_query`. You can combine the
parameter with the others.

## Limits

* Frames share the user's exchange budget with REST, across API-key rotations
  and connections. An exhausted budget returns a `rate_limited`
  [frame error](#frame-errors),
  whose `retryAfterMs` gives the time until the budget admits a frame again;
  the socket stays open. A frame counts when Mosaiq reads it, so a frame
  refused after that still counts. A frame that does not parse, or a binary
  frame that is not UTF-8, also counts. A `cancel` frame with a
  `fastCancel: true` item counts twice. With 1 unit left it is still accepted,
  and the next frame waits until 2 units refill (see
  [Rate limits](/api/http-public#rate-limits)).
* Frames also count against the
  [per-IP WebSocket message budget](/api/websocket#rate-limits). Exceeding it
  closes the connection.
* At most 128 requests are in flight per client IP, across all of that IP's
  connections. Clients behind one NAT address share this limit.
  * A request is in flight until its answer, which comes once Mosaiq launched
    its venue send or refused it. Ping, pong, close, and maintenance frames
    never count.
  * At the limit, Mosaiq answers `rate_limited` with the detail
    `inflight_limit_exceeded` and no `retryAfterMs`. Send again once one of
    your answers arrives.
  * If Mosaiq cannot deliver these refusals in time, it tries to close the
    connection with code `1013` and the reason `in-flight refusal queue full`
    or `in-flight refusal expired`. A blocked socket can keep the close frame
    from arriving. After you reconnect, check each order without an answer by
    `cloid` before you send it again.
* Frames are limited to 1 MiB. A larger frame closes the connection.
* The outbound queue holds 256 messages, including responses, maintenance
  messages, and control frames. A message that cannot be queued closes the
  connection. The shared [outbound byte and age limits](/api/websocket#rate-limits)
  also apply.

## Disconnects and shutdown

Requests already owned by Mosaiq can continue after a client disconnect, even
if their responses are lost. A server crash before durable acceptance may
discard a place, modify, or cancel. REST and WebSocket share the
[acceptance and recovery contract](/api/exchange#disconnects-and-shutdown).
Reconnect and check each order by `cloid` before retrying a frame with no response.

## Ordering

Send a dependent `cancel` or `modify` after its `place` on the same connection,
using the same `(venue, cloid)`. Mosaiq orders these actions without requiring
you to wait for the placement's response.

Consecutive modify frames for the same `(venue, cloid)` execute in arrival
order. Each waits for the earlier modify's venue outcome before admission. A
modify's `accepted` answer does not confirm the changed order state; the order's
`orderUpdates` row does. If the earlier modify remains unresolved after the
two-second confirmation wait, the waiting item returns
`blocked_by_other_action` with the detail `modify_in_flight`, without being
sent.

Whether a modify waits for its placement depends on the venue:

* On Hyperliquid, a modify does not wait for the venue's answer to its place.
  Mosaiq sends it behind the place on the same connections (see
  [Modify](/api/exchange#modify)). It returns `blocked_by_other_action` with
  the detail `modify_placement_not_confirmed` only if the placement already
  failed or became `uncertain`.
* On Lighter, a modify sent right after its place waits up to two seconds for
  Lighter to confirm the place. If Lighter has not confirmed the placement by
  then, the modify returns `blocked_by_other_action` with the detail
  `modify_placement_not_confirmed`, without being sent.

Unrelated orders continue independently.

A cancel following a pending placement on any supported venue can stop that
placement before it is sent. This applies whether the placement, the cancel,
or both arrive in batches. A later cancel supersedes only its targeted
placement; unrelated batch items continue. Earlier pending actions on the
same order, such as a modification, still retain their ordering barriers.
On a Hyperliquid perp, a modify under the $10 minimum value of an `Alo` order
that is not reduce-only stops its pending placement the same way: Hyperliquid would
cancel the order (see [Modify](/api/exchange#modify)).

For example, after `place [A, B]`, a `cancel [A]` can prevent A while B
proceeds. The placement response still includes both items in their original
positions. A prevented placement answers `accepted`, like its cancel, and
`orderUpdates` reports it `cancelled` with no `failure` and with
`neverOnVenue: true`.

Prevention is best effort. If the placement has already been sent, the cancel
follows the normal venue path and a fill can still occur.

Batch duplicate rejection remains in effect when a placement is prevented.
For example, send `place [A, A]` with the same `cloid` and venue for both items,
then `cancel [A]` on the same connection. The second placement is rejected
with `duplicate_id` and the detail `duplicate_cloid`. If the cancel prevents
the first placement before dispatch, neither placement is sent to the venue. Preventing the first does
not make the second eligible for submission.

Unrelated items can run concurrently, including items within one batch. On
Hyperliquid, the items of one frame that share a packing key leave together,
as one action in array order. See [Batches](/api/exchange#batches).
Do not rely on request order across separate connections. Responses, order
updates, and fills can arrive out of order. Match responses by frame `id`
and order state by `cloid`.

## Frames

An order frame is a numeric `id` and one `request`, the body of
[`POST /v1/exchange`](/api/exchange). `id` is required, must be an unsigned
integer, and comes back in the answer. Placements use the REST fields; `c` is
required on every WebSocket placement.

`fastCancel: true` on a `cancel` item adds a best-effort kill-modify when you
cancel a young Hyperliquid perp `Alo` order whose place may still be in flight
(see [Fast cancel](/api/optimizing-latency#fast-cancel)). The cancels of
`cancelAllOnDisconnect` never carry it. A `place` or `modify` that carries
`fastCancel` gets the frame error `bad_request`, like any unknown field.

```jsonc
{
  "id": 41,
  "request": {
    "type": "place",
    "orders": [
      {
        "a": "BTC",
        "b": "buy",
        "p": "64000",
        "s": "1",
        "venue": "hyperliquid",
        "t": "Alo",
        "c": "0x00000000000000000000000000000005"
      }
    ]
  }
}
```

### Answers

On a connection opened with `nestedFormat=false`, Mosaiq answers each frame
once, with the body that `POST /v1/exchange` answers for the same request and
the frame's `id` first. The items are the
[REST items](/api/exchange#response), so one decoder reads both transports.
Without the parameter, Mosaiq answers Hyperliquid's `post` envelope, as
[Answer format](#answer-format) explains and
[Migrate from the post envelope](#migrate-from-the-post-envelope) shows:

```json
{
  "id": 41,
  "status": "ok",
  "data": [
    {
      "status": "accepted",
      "orderId": "0b0f9c0e-6d4e-4a1b-9f37-2c5d8e1a4b05",
      "cloid": "0x00000000000000000000000000000005",
      "venue": "hyperliquid",
      "size": "1"
    },
    {
      "status": "error",
      "code": "duplicate_id",
      "detail": "duplicate_cloid",
      "msg": "duplicate client order id in batch: 0x00000000000000000000000000000005",
      "cloid": "0x00000000000000000000000000000005"
    }
  ],
  "server_time_ms": 1788646149474,
  "server_receive_time_ms": 1788646149462
}
```

* `status` is `ok`, and `data` holds one item per entry of `orders`, in order.
  An item answers once Mosaiq launched its venue send or refused it, so no
  answer waits for the venue. `server_receive_time_ms` is when Mosaiq received
  the frame, and `server_time_ms` when it answered.
* An `accepted` item carries `orderId`, `cloid`, `venue`, and, for a place or a
  modify, `size`. A place's `orderId` is its order's, which the order's
  [`orderUpdates`](/api/websocket#orderupdates) rows carry. A modify's is the
  modified order's, and its `size` is the size that its send carries. An
  outcome buy that a payout cap lowered also carries `clippedBy`, the cap, and
  its `size` is the admitted size (see [the REST response](/api/exchange#response)). A
  cancel's `orderId` names the cancel itself: no row carries it, so match a
  cancel's answer by `cloid` and read how its order ended on that order's rows.
  `accepted` says nothing about the venue's verdict. Read it on `orderUpdates`,
  as [Follow each write on orderUpdates](/api/exchange#follow-each-write-on-orderupdates)
  shows. A connection opened with `includeVenueCloid=true` also gets
  `venueCloid` on place and modify items, as
  [Venue client order ids](#venue-client-order-ids) shows.
* An `error` item carries the [error object](/api/errors) and its
  `cloid`: `code`, `detail`, `msg`, and `maybeSent`, `retryAfterMs` or `cap`
  when they apply. An item without `maybeSent` was refused before any venue
  effect, so no `orderUpdates` row follows, except after a launch that failed
  after the action became durable. An item with `maybeSent: true`, such as
  `request_uncertain`, may still execute (see the
  [REST response](/api/exchange#response)). Other items in the frame are still
  submitted.

A cancel answers its own `orderId`, and no `size`:

```json
{
  "id": 41,
  "status": "ok",
  "data": [
    {
      "status": "accepted",
      "orderId": "0b0f9c0e-6d4e-4a1b-9f37-2c5d8e1a4b06",
      "cloid": "0x00000000000000000000000000000005",
      "venue": "hyperliquid"
    }
  ],
  "server_time_ms": 1788646149474,
  "server_receive_time_ms": 1788646149462
}
```

### Frame errors

When Mosaiq refuses a whole frame, it took none of it. The answer is the REST
error body with the frame's `id`:

```json
{
  "id": 41,
  "status": "error",
  "data": {
    "code": "rate_limited",
    "detail": "rate_limited",
    "msg": "rate limit exceeded",
    "retryAfterMs": 350
  },
  "server_time_ms": 1788646149474
}
```

| `code` | `detail` | When |
| --- | --- | --- |
| `invalid_request` | `bad_request` | The frame does not parse: invalid JSON, JSON that is not an object, a missing `id`, an unknown field, a decimal string that is not [plain](/api/exchange#fields), or a binary frame that is not UTF-8. Also an empty `place` or `modify`, and a `cloid` that appears twice in one `modify` frame. |
| `invalid_request` | `batch_too_large`, `invalid_cancel` | A batch over the limit, or an empty `cancel`, as on [REST](/api/exchange#batches). |
| `invalid_request` | `unsupported` | `mass_cancel`, `deposit`, `withdraw`, or `transfer`. Send them to `POST /v1/exchange`. |
| `rate_limited` | `rate_limited` | The exchange budget is spent. `retryAfterMs` is when it admits a frame again. The socket stays open. |
| `rate_limited` | `inflight_limit_exceeded` | 128 frames of this IP are in flight. There is no `retryAfterMs`: send again once one of your answers arrives. |

A frame error carries the frame's `id` whenever Mosaiq can read it, even when
the rest of the frame is wrong:

```json
{
  "id": 41,
  "status": "error",
  "data": {
    "code": "invalid_request",
    "detail": "bad_request",
    "msg": "bad request: invalid exchange websocket request: invalid value: string \"0_5\", expected a plain decimal string such as \"0.5\" at line 1 column 164"
  },
  "server_time_ms": 1788646149474
}
```

The `id` is `null`, never absent, only when the text is not a JSON object with
an unsigned integer `id`: text that is not JSON, a missing or string `id`, or a
binary frame that is not UTF-8. No pending frame can be matched then: check
every frame still unanswered by `cloid`.

```json
{
  "id": null,
  "status": "error",
  "data": {
    "code": "invalid_request",
    "detail": "bad_request",
    "msg": "bad request: invalid exchange websocket request: EOF while parsing an object at line 1 column 34"
  },
  "server_time_ms": 1788646149474
}
```

A missing `c` on a placement is an item-level `invalid_request` with the
detail `bad_request`. If Mosaiq cannot prepare an item for submission within 2
seconds, it answers `temporarily_unavailable` with the detail
`pre_venue_resource_timeout` for that item, and nothing was sent.

### Routing

Every text frame that the socket sends is a write answer or a
[maintenance](#maintenance-announcements) message. A write answer always has
`id`, and never `topic`. A maintenance message has `topic`, and never `id`.
Answers arrive in completion order, not in send order, and a frame error can
overtake the answer of an earlier frame. Match answers by `id`.

If Mosaiq cannot send an answer, it closes the connection. Reconnect and check
each frame without an answer by `cloid`, as after any
[disconnect](#disconnects-and-shutdown).

## Supported actions

* `place`, `modify`, and `cancel` batches, with the shape and venue codes of
  REST.
* Limit and market placements, including `reduceOnly`.
* `modify` on Hyperliquid and Lighter, without `t`.
* `fastCancel` on `cancel` items.

`mass_cancel`, `deposit`, `withdraw`, and `transfer` get the
[frame error](#frame-errors) `unsupported`.

## Maintenance announcements

The `maintenance` topic tells you when Mosaiq itself will stop, when
Hyperliquid or Lighter announced a maintenance, and when trading on a Mosaiq
venue stops because of it. Mosaiq stops for every release and for some
maintenance. Use the warning to put your orders and positions in the state you
want before the stop.

The topic only informs. No order is refused because of a Mosaiq maintenance.
During a venue maintenance, Mosaiq refuses place and modify on that venue only:
see [Venue trading stops](#venue-trading-stops).

Subscribe on the same authenticated `/v1/exchange/ws` connection used for orders.
The API key must belong to a registered wallet, as for execution requests.
[`/v1/ws`](/api/websocket) and [`/v1/market-data/ws`](/api/market-data-websocket)
take the same subscription and send the same messages.
[`GET /v1/maintenance`](/api/maintenance) answers the same state over HTTP.
Maintenance messages use a `status` / `topic` envelope; write answers carry
`id` instead of `topic`.

```json
{ "method": "subscribe", "subscription": { "type": "maintenance" } }
```

This subscription has no `user`, venue filter, or `unsubscribe` method.
Do not mix `id` or `request` action fields into this subscription frame. Subscribe
requests share the connection's IP and user request limits. Repeated requests
while a subscription is loading can return `rate_limited`. Subscription
errors keep the connection open; continue reading write answers and
heartbeats while waiting or retrying.

This account-independent topic covers Mosaiq itself in `data.platform`,
Hyperliquid mainnet and Lighter Core in `data.sources`, and trading on each
Mosaiq venue in `data.venues`.
The first message has `data.message_type: "snapshot"`; subsequent messages use `update`.
Every message replaces the complete `data.platform` object and the complete
`data.sources` and `data.venues` arrays, including source freshness. Updates
may repeat unchanged announcements. After reconnecting, subscribe again; there
is no replay of changes missed while disconnected.

### Snapshot and update messages

Illustrative snapshot (not a live status report), written by the gateway's own
serializers:

```json
{
  "data": {
    "message_type": "snapshot",
    "platform": {
      "announcement": null,
      "boot_hold": null
    },
    "sources": [
      {
        "checked_at_ms": 1788646149474,
        "last_success_ms": 1788646149474,
        "maintenances": [],
        "source_url": "https://hyperliquid.statuspage.io/api/v2/scheduled-maintenances.json",
        "status": "fresh",
        "venue": "hyperliquid"
      },
      {
        "checked_at_ms": 1788646149474,
        "last_success_ms": 1788646149474,
        "maintenances": [
          {
            "id": "1051290",
            "scheduled_end_ms": 1788700531000,
            "scheduled_start_ms": 1788692431000,
            "source_url": "https://status.lighter.xyz/maintenance/1051290",
            "status": "scheduled",
            "title": "Network Upgrade"
          }
        ],
        "source_url": "https://status.lighter.xyz/index.json",
        "status": "fresh",
        "venue": "lighter"
      }
    ],
    "venues": [
      {
        "announcement": null,
        "venue": "hyperliquid"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:xyz"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:mkts"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:io"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:para"
      },
      {
        "announcement": {
          "id": "1051290",
          "status": "scheduled",
          "window_end_ms": 1788700531000,
          "window_start_ms": 1788692431000
        },
        "venue": "lighter"
      },
      {
        "announcement": {
          "id": "1051290",
          "status": "scheduled",
          "window_end_ms": 1788700531000,
          "window_start_ms": 1788692431000
        },
        "venue": "lighter:robinhood"
      }
    ]
  },
  "server_time_ms": 1788646149474,
  "status": "ok",
  "topic": "maintenance"
}
```

Updates have the same shape with `message_type: "update"`. Route these frames
by `topic: "maintenance"`, and write answers by `id`.
Replace the whole platform object and the whole `sources` and `venues` arrays on
either message type; do not append events on every update. A new subscription
starts with a snapshot, not a replay of all changes while disconnected.

### Mosaiq maintenance

`data.platform` has two parts, `announcement` and `boot_hold`. Either, both, or
neither can be present; an absent part is `null`. When both are `null`, as in
the snapshot sample above, Mosaiq is running normally.

`announcement` is a planned stop of Mosaiq. There is at most one at a time. A
new announcement replaces the previous one and has a new `id`: forget the old
one when you see a new `id`. Its fields:

| Field | Meaning |
|---|---|
| `id` | The announcement. A UUID. |
| `status` | `scheduled`, `in_progress`, or `shutting_down`. |
| `window_start_ms` | Mosaiq may stop at or after this time. |
| `shutdown_at_ms` | Only while `shutting_down`: Mosaiq stops at this time. |
| `expected_downtime_s` | How long Mosaiq expects to stay down, in seconds. |

* `scheduled`: the window has not started.
* `in_progress`: the window is open. Mosaiq may stop at any moment.
* `shutting_down`: Mosaiq stops at `shutdown_at_ms`. The countdown can be
  short: a release gives 60 seconds. After the stop, the socket closes and stays down for
  about `expected_downtime_s`. Mosaiq sends nothing while it is down, even if
  the downtime runs longer.

Mosaiq sends an `update` when the clock alone changes the state too: at
`window_start_ms`, and at `hold_until_ms`.

While a stop nears, Mosaiq also sends the current state again as an `update`,
even if nothing changed. The schedule counts back from `window_start_ms` while
`scheduled`, and from `shutdown_at_ms` while `shutting_down`. The state comes
every 10 minutes down to 10 minutes left, then every minute down to 1 minute,
then every 10 seconds down to 10 seconds, then every second down to 1 second.
While `in_progress`, it comes every 10 minutes after `window_start_ms`. Treat
each message as the whole current state, as for any other update.

`boot_hold` shows after every start of Mosaiq, planned or not. Mosaiq is
still being checked: hold your volume until `hold_until_ms`. Its fields are
`id`, `booted_at_ms`, and `hold_until_ms`. After a planned stop, the hold has
the `id` of the announcement that announced the stop. Mosaiq can extend the
hold. The hold ends at `hold_until_ms` or earlier.

A start of Mosaiq during an announced window keeps the announcement, so the
same message can show `announcement` and `boot_hold` together. This sample
shows Mosaiq after a restart during a countdown: it still stops at
`shutdown_at_ms`.

```json
{
  "data": {
    "message_type": "update",
    "platform": {
      "announcement": {
        "expected_downtime_s": 600,
        "id": "019a9d5a-6b80-7c3e-9f41-2d7e8a05c113",
        "shutdown_at_ms": 1788646194474,
        "status": "shutting_down",
        "window_start_ms": 1788646134474
      },
      "boot_hold": {
        "booted_at_ms": 1788646147474,
        "hold_until_ms": 1788647047474,
        "id": "019a9d5a-8f20-7a41-b6c2-51e90d374a88"
      }
    },
    "sources": [
      {
        "checked_at_ms": 1788646149474,
        "last_success_ms": 1788646149474,
        "maintenances": [],
        "source_url": "https://hyperliquid.statuspage.io/api/v2/scheduled-maintenances.json",
        "status": "fresh",
        "venue": "hyperliquid"
      },
      {
        "checked_at_ms": 1788646149474,
        "last_success_ms": 1788646149474,
        "maintenances": [
          {
            "id": "1051290",
            "scheduled_end_ms": 1788700531000,
            "scheduled_start_ms": 1788692431000,
            "source_url": "https://status.lighter.xyz/maintenance/1051290",
            "status": "scheduled",
            "title": "Network Upgrade"
          }
        ],
        "source_url": "https://status.lighter.xyz/index.json",
        "status": "fresh",
        "venue": "lighter"
      }
    ],
    "venues": [
      {
        "announcement": null,
        "venue": "hyperliquid"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:xyz"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:mkts"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:io"
      },
      {
        "announcement": null,
        "venue": "hyperliquid:para"
      },
      {
        "announcement": {
          "id": "1051290",
          "status": "scheduled",
          "window_end_ms": 1788700531000,
          "window_start_ms": 1788692431000
        },
        "venue": "lighter"
      },
      {
        "announcement": {
          "id": "1051290",
          "status": "scheduled",
          "window_end_ms": 1788700531000,
          "window_start_ms": 1788692431000
        },
        "venue": "lighter:robinhood"
      }
    ]
  },
  "server_time_ms": 1788646149474,
  "status": "ok",
  "topic": "maintenance"
}
```

An `update` with both parts `null` after a message with a part present means
that every limitation is lifted.

### Venue maintenance

Each source contains `venue`, `source_url`, `status`, `checked_at_ms`,
`last_success_ms`, and `maintenances`. Source status is `unknown` before the
first poll, `fresh` after success, or `stale` after a failed fetch or invalid
response. Failed polls keep the previous announcements. Also treat a source
as stale when `last_success_ms` is more than 180 seconds old.
Both timestamp fields may be `null` before any observation. An empty
`maintenances` array with an unknown or stale source does not establish that
no maintenance is planned.

Each maintenance contains `id`, `title`, `source_url`, `status`,
`scheduled_start_ms`, and nullable `scheduled_end_ms`. Times are UTC Unix
milliseconds. The end is the source's scheduled estimate, not proof that
trading has resumed. Status is `scheduled`, `in_progress`, `verifying`,
`completed`, or `unknown`. Completion requires an explicit source state.
Missing previously active entries become `unknown`, never `completed`.

Announcements come from [Hyperliquid Statuspage](https://hyperliquid.statuspage.io/api/v2/scheduled-maintenances.json)
and [Lighter Core status](https://status.lighter.xyz/index.json), checked every
60 seconds. There is no separate Robinhood source: Lighter announcements also
apply to `lighter:robinhood`, and Hyperliquid announcements apply to its HIP-3
venues. Coverage excludes Telegram-only announcements. Lighter's `scheduled`
and `in_progress` states follow its published
start time; they do not independently confirm venue downtime.

Snapshots include at most 128 events per venue and retain completed or
missing events for seven days after their scheduled window. They are not a
complete history.

An `in_progress` venue announcement can reject place and modify requests with
`temporarily_unavailable` and the detail `maintenance_in_progress` while its
source is `fresh` and was successfully
checked within five minutes. This refusal ends 15 seconds after the scheduled
end, if provided; without an end, it lasts while the fresh source reports
`in_progress`. A completed announcement or stale source also ends this
maintenance refusal, and so does Mosaiq when it reaches the venue again before
the announcement says so. After the maintenance, place and modify on the venue
get the detail `maintenance_awaiting_prices` until each market of the venue has
a new price. Other trading restrictions may still apply. Cancels and
cancel-on-disconnect are not blocked by this check.
[Venue trading stops](#venue-trading-stops) tells you when this refusal starts
and ends on each venue.

### Venue trading stops

`data.venues` tells you when trading on a Mosaiq venue stops because of an
announced maintenance. Use it to reduce a position or to hedge it on another
venue before the stop. It has one entry per Mosaiq venue, always in this order:
`hyperliquid`, `hyperliquid:xyz`, `hyperliquid:mkts`, `hyperliquid:io`,
`hyperliquid:para`, `lighter`, `lighter:robinhood`. Each entry has `venue` and
`announcement`. `announcement` is `null` when Mosaiq knows no window for the
venue. As for `sources`, a `null` with a stale or unknown source does not
prove that no maintenance is planned.

Each venue follows the status page of its network: `lighter:robinhood` follows
the Lighter page, and each `hyperliquid:<dex>` venue follows the Hyperliquid
page. So one window can show on several venues.

| Field | Meaning |
|---|---|
| `id` | The `id` of the window in `sources`. |
| `status` | `scheduled` or `in_progress`. |
| `window_start_ms` | The start of the window, from the status page. |
| `window_end_ms` | The end of the window, from the status page. `null` when the page gives no end. |

* `scheduled`: the earliest window that the venue's page shows as scheduled
  and that is not over: its `window_end_ms` has not passed, or, with no end,
  its `window_start_ms`. Mosaiq refuses place and modify on the venue when the
  page reports the window in progress, which is usually at `window_start_ms`.
* `in_progress`: Mosaiq refuses place and modify on the venue now.

There is at most one announcement per venue: the window in progress, else the
earliest scheduled one. `in_progress` follows Mosaiq, not the status page. It
starts when Mosaiq stops trading on the venue. It ends when Mosaiq trades on
the venue again, after each market of the venue has a new price. This can come
before the page says `completed`. After it, `announcement` shows the next
scheduled window, or `null`.

During a venue window, Mosaiq does this:

* A place or a modify on the venue gets `temporarily_unavailable`, with the
  detail `maintenance_in_progress`, then `maintenance_awaiting_prices` until
  each market of the venue has a new price.
* A cancel on the venue goes through when the venue accepts it.
* Orders on the other venues are not refused, also for an account that holds
  positions on the venue in maintenance.
* Account reads answer as usual. The markets of the venue show their last
  price, and `withdrawableUsdc` is `null` for an account with a position on the
  venue.
* Mosaiq does not liquidate a position on the venue until the venue is back
  and has a new price.
* A withdrawal or a transfer of an account with a position on the venue gets
  the detail `maintenance_in_progress`, then `maintenance_awaiting_prices`
  until each market of the venue has a new price. See [errors](/api/errors).

While a venue announcement is `scheduled`, Mosaiq sends the current state again
on the schedule of a Mosaiq stop, counted back from `window_start_ms`: every 10
minutes, then every minute from 10 minutes before, every 10 seconds from 1
minute before, and every second from 10 seconds before. While it is
`in_progress`, the state comes every 10 minutes after `window_start_ms`. When
reminders of several venues, or of a venue and of Mosaiq, fall at the same
time, Mosaiq sends one message.

The topic shows announced maintenance only. A request that Mosaiq refuses for
another cause, for example a venue that recovers after an outage, gets its own
code.

`venues` is a required field of every `maintenance` message from this release
on. A client that refuses unknown fields must update before it reads this
release.

### Subscription errors

A subscription error uses the maintenance envelope, for example:

```json
{
  "data": {
    "code": "rate_limited",
    "detail": "rate_limited",
    "msg": "rate limit exceeded",
    "retryAfterMs": 1200
  },
  "server_time_ms": 1788646149474,
  "status": "error",
  "topic": "maintenance"
}
```

Branch on `data.code` and treat `data.msg` as explanatory text. Invalid
subscription fields return `invalid_request` with the detail
`invalid_websocket_subscription`.

## Migrate from the post envelope

Earlier releases wrapped each answer in Hyperliquid's `post` envelope, with an
item of Hyperliquid's shape. Mosaiq still answers that envelope on a
connection opened without `nestedFormat=false`, until an announced release
drops it (see [Answer format](#answer-format)). Switch by opening your connections with
`nestedFormat=false` and reading the fields below. Requests, `maintenance`
frames, pings, and closes do not change, except that every text frame must be
a JSON object, in both formats. Earlier
releases also read a JSON array of a frame's values in field order:
`[41, {"type": "cancel", ...}]` ran as the frame `41`. Such an array is now a
frame error `bad_request` with `"id": null`. A client that reads both shapes
during the switch tells them apart by where the id is: at the top level now,
under `data` before.

The answer to an accepted place, in the `post` envelope:

```jsonc schematic
{ "channel": "post", "data": { "id": 41, "response": { "type": "action", "payload": { "status": "ok", "response": { "type": "order", "data": { "statuses": [ { "accepted": { "cloid": "0x00000000000000000000000000000005" } } ] } } } } } }
```

With `nestedFormat=false`:

```json
{
  "id": 41,
  "status": "ok",
  "data": [
    {
      "status": "accepted",
      "orderId": "0b0f9c0e-6d4e-4a1b-9f37-2c5d8e1a4b05",
      "cloid": "0x00000000000000000000000000000005",
      "venue": "hyperliquid",
      "size": "1"
    }
  ],
  "server_time_ms": 1788646149474,
  "server_receive_time_ms": 1788646149462
}
```

The refusal of a whole frame, in the `post` envelope:

```jsonc schematic
{ "channel": "post", "data": { "id": 41, "response": { "type": "error", "payload": { "status": "error", "data": { "code": "rate_limited", "detail": "rate_limited", "msg": "rate limit exceeded", "retryAfterMs": 350 }, "server_time_ms": 1788646149474 } } } }
```

With `nestedFormat=false`:

```json
{
  "id": 41,
  "status": "error",
  "data": {
    "code": "rate_limited",
    "detail": "rate_limited",
    "msg": "rate limit exceeded",
    "retryAfterMs": 350
  },
  "server_time_ms": 1788646149474
}
```

| You read | Read now |
| --- | --- |
| `data.id` | `id`. It is `null` when Mosaiq could not read the frame's `id`. |
| `data.response.type`: `action` or `error` | `status`: `ok` or `error`. |
| `data.response.payload.response.data.statuses` | `data`, the [REST items](/api/exchange#response). |
| `data.response.payload.data` | `data`, the error object. |
| `{ "accepted": { "cloid" } }` | `{ "status": "accepted", "orderId", "cloid", "venue", "size" }`. A cancel's `orderId` is its own, and it has no `size`. |
| `{ "error": "<code>: <msg>", "code", "detail", "msg" }` | `{ "status": "error", "code", "detail", "msg", "cloid" }`. |
| `channel: "post"` versus `topic` | `id` versus `topic`. |
