# HTTP — `POST /v1/exchange`

One request carries one action type: a batch of up to 20 places, modifies, or
cancels, a mass cancel, a deposit request, a withdrawal request, or a transfer
between two accounts of the owner. Every order names its `venue`; Mosaiq never
reroutes it.

Separate HTTP requests can arrive and complete out of order, even for the
same user. Once received, actions on the same user, venue, and client order ID
share dependencies with the [write WebSocket](/api/exchange-websocket#ordering).
Use one write WebSocket when you need the server to receive a placement before
a following cancel or modify.

```http
POST /v1/exchange
Authorization: Bearer <your-api-key>
```

| Action | Auth |
| --- | --- |
| `place`, `modify`, `cancel`, `mass_cancel` | API key, on the key's account |
| `deposit` | API key of the master account, or Para JWT |
| `withdraw` | Para JWT (`X-Tessera-Wallet` when the JWT holds several EVM wallets) |
| `transfer` | Para JWT (`X-Tessera-Wallet` when the JWT holds several EVM wallets) |

The Para JWT acts for the master account of the owner. An API key acts for its
own account, which can be a [sub-account](/concepts/sub-accounts).

## Disconnects and shutdown

REST and WebSocket use the same acceptance and recovery contract for place,
modify, and cancel. Once the server owns an action, a client disconnect does not
cancel its processing. A server crash before durable acceptance may discard the
action, including a cancel. The answer is the acknowledgement. Mosaiq sends no
receipt before it.

If the connection closes before the answer arrives, treat the result as
unknown. The server may already have launched the venue send. Check
`orderUpdates` and `openOrders` by `cloid` before retrying.

## Place

A placement is a limit order when it carries `p` and `t`, and a market order
when it carries `slippage` instead. Mosaiq refuses `slippage` with `p` or `t`,
and `p` or `t` alone, with `invalid_request` and the detail `unsupported`.

Limit `t` is `Ioc` or `Alo` (post-only). Mosaiq refuses `Gtc` with
`invalid_request` and the detail `unsupported_tif`.

A market order is a bounded IOC. `slippage` is a fraction in `(0, 0.5]`; the
venue-side limit is the venue mid price moved by that fraction. A market buy
with `priorityFeeBps` is also capped at the higher of the Mosaiq oracle price
and Hyperliquid's mid price, moved by that fraction. Margin is reserved at the
Mosaiq oracle price moved by the same fraction, and for a market buy with
`priorityFeeBps` at that cap.

When Mosaiq has no fresh venue price for the market at send time, it does not
send a market order. The placement answers `accepted`, and `orderUpdates`
reports it `failed` with `failure.code` `temporarily_unavailable` and the
detail `execution_price_unavailable`.

```jsonc
{
  "type": "place",
  "orders": [
    {
      "a": "BTC",
      "b": "buy",
      "s": "1",
      "slippage": "0.01",
      "venue": "hyperliquid",
      "c": "0x00000000000000000000000000000001"
    }
  ]
}
```

### Reduce-only

`reduceOnly: true` requires a current position on the selected venue and a
reducing side (sell against a long, buy against a short). A flat position or
the wrong side is rejected with `limit_reached` and the detail `reduce_only`
before venue dispatch.

While your account is being liquidated, Mosaiq refuses every place and modify,
with or without `reduceOnly`, with `trading_restricted` and the detail
`liquidation_in_progress`, or `operations_halted` on a halted market. Cancels
pass.

An oversized request is clamped to the reducible position rather than
rejected. Existing reduce-only orders are not subtracted when computing that
clamp. Newer placements and size increases take capacity first and can
permanently trim or cancel older reduce-only orders on the same user, asset,
venue, and side. A position decrease trims them too. A trim or a cancel of an
older order is final, even when the placement that caused it never reaches the
venue, for example an `Ioc` that Mosaiq refuses before sending it. Mosaiq does
not place the older order again: you get its trimmed or `cancelled` update, and
you send it again if you still want it. That `cancelled` update has no
`cancelCause`. A trim that waits for your pending modify of the older order
uses the price and venue minimum that the venue confirmed for that modify. If
what remains is below that minimum, the older order is cancelled.
While another reduce-only replacement on the same market, venue and side is
unresolved, a placement that would exceed the position is rejected with
`blocked_by_other_action` and the detail `reduce_only_transition_in_flight`.
Wait until `orderUpdates` shows the outcome of that replacement, then retry.

Mosaiq re-applies the venue size increment and minimums after clamping; if the
result is not a valid venue order the item is rejected with `invalid_request`
and the detail `min_notional`.
This applies to `Ioc` and market reduce-only orders as well, so an immediate
order can displace older resting protection even when it does not fill. The
accepted response returns the clamped `size`; reconcile later values from
`openOrders` or `orderUpdates`.

A reduce-only place or modify gets no priority on Mosaiq's post queues and
local rate budget. When they are full, Mosaiq refuses it with
`temporarily_unavailable` and the detail `send_capacity`, and does not send it,
as for any other order. Mosaiq does not hold it to send it later. To close a
position, send the reduce-only order again after a short delay.

On the request quota of Mosaiq's Hyperliquid account, a reduce-only order does
get priority. It can spend the reserve that Mosaiq keeps for safety actions,
unless it carries `expiresAfter`. When the quota is spent, Mosaiq sends one
reduce-only order every 10 seconds and holds the others until their turn.

```jsonc
{
  "type": "place",
  "orders": [
    {
      "a": "BTC",
      "b": "sell",
      "p": "65000",
      "s": "0.5",
      "venue": "hyperliquid",
      "t": "Ioc",
      "reduceOnly": true,
      "c": "0x00000000000000000000000000000005"
    }
  ]
}
```

#### Closing orders on a reduce-only venue

An operator can put a venue in `user_reduce_only`. On that venue, Mosaiq treats
a perp order without `reduceOnly` as reduce-only when it reduces your position
on that market and venue: a sell against a long, or a buy against a short.

* Mosaiq refuses every other order without `reduceOnly`, and every modify
  that can add exposure, with `trading_restricted` and the detail
  `venue_reduce_only`.
* Mosaiq cancels your resting orders without `reduceOnly` on that venue. Their
  `cancelled` row on `orderUpdates` carries `cancelCause` `venue_reduce_only`.
* The clamp, the trims of your older reduce-only orders, and the errors
  above apply to a closing order. The accepted answer returns the clamped
  `size`.
* Its fills are not capped at your position. If two closing orders race, or
  your position shrinks before a fill, the venue can fill more than your
  position. You keep the whole fill, and your position can flip to the other
  side. Set `reduceOnly: true` to never hold more than your position.
* A closing `Alo` order can carry `priorityFeeBps`, and pays its fee at
  placement as usual.
* The order stays reduce-only until it ends, even after the venue opens
  again. To replace it with an order without `reduceOnly`, cancel it and place
  a new order.
* While the market is halted, a closing order passes only when it executes
  immediately (market or `Ioc`). Its fills then stop at zero, as with
  `reduceOnly`.

Mosaiq admits orders the same way, whatever the venue's mode, on a Lighter
market that Lighter keeps reduce-only. There an order without `reduceOnly`
passes only when it reduces your position and Lighter can execute it from Mosaiq's account.
Otherwise Mosaiq refuses it with `trading_restricted` and the detail
`market_reduce_only`, or with `temporarily_unavailable` and the detail
`omnibus_position_not_reducible`.

### Spot markets

:::note\[Not open in production yet]
Spot trading is not open in production yet. `GET /v1/spotMeta` lists no
market until Mosaiq opens it.
:::

A spot order uses the same fields. `a` is a market of
[`GET /v1/spotMeta`](/api/spot-meta), such as `HYPE/USDC`, and `venue` is its
venue. Your token cash pays for a buy and receives the proceeds of a sale
([token cash](#token-cash)).

* A buy holds USDC for its notional and the Mosaiq fee. When that is more than
  your buying power, Mosaiq refuses the buy with `limit_reached` and the detail
  `cap_exceeded`. Buying power never includes unrealized perp profit.
* A sell needs free tokens: the tokens that you hold minus the tokens that your
  sells hold. Mosaiq refuses a larger sell the same way.
* While Mosaiq keeps spot trading closed, each spot order fails with
  `temporarily_unavailable` and the detail `spot_unavailable`. Perp orders are
  not affected.
* A spot market takes `Ioc` and `Alo` limit orders and market orders. Mosaiq
  refuses `reduceOnly` with `limit_reached` and the detail `reduce_only`. It
  refuses a `Gtc` limit with `invalid_request` and the detail `unsupported_tif`,
  and `expiresInMs`, `expiresAfter` or `replaces` with `invalid_request` and the
  detail `unsupported`. A modify of a spot or outcome order gets
  `invalid_request` with the detail `unsupported` and the `msg` `modify is not
  supported on spot and outcome markets; cancel and place a new order`. A spot
  `Ioc` or market order can carry `priorityFeeBps`: a buy holds the fee with its
  notional. A spot `Alo` refuses it with `invalid_request` and the detail
  `unsupported`.
* An `Alo` rests as a maker order and pays no fee when it fills: the Mosaiq
  maker fee is 0, and Mosaiq pays the venue's maker fee. Hyperliquid refuses an
  `Alo` that would cross: `orderUpdates` reports it `failed` with
  `failure.code` `venue_rejected`, the detail `invalid_order` and `rawCode`
  `badAloPxRejected`.
* A spot limit price must lie between 5% and 195% of the spot reference mid, or
  Mosaiq refuses it with `invalid_request` and the detail `invalid_price`.
  Without a spot reference mid of at most 5 minutes, the spot order fails with
  `temporarily_unavailable` and the detail `oracle_unavailable`.
  [`GET /v1/spotMeta`](/api/spot-meta) shows that mid as `midPx`, and omits it
  when no mid is fresh.
* A spot market order reserves at a bound: `mid x (1 + slippage)` for a buy and
  `mid x (1 - slippage)` for a sell. Mosaiq never signs a buy above the bound or
  a sell below it, so a buy can fill less, or not at all, when the market moves
  up. Without a fresh venue mid, the order fails as a perp market order does.
* When the Mosaiq spot balance on the venue cannot pay a spot buy that your own
  funds cover, `orderUpdates` reports the buy with `failure.code`
  `temporarily_unavailable` and the detail `broker_capacity`, as it does for a
  perp order when the pooled account lacks margin. Mosaiq then moves USDC to
  that balance, and `failure.retryAfterMs` says when to retry. A spot sell never
  gets this detail.

```jsonc
{
  "type": "place",
  "orders": [
    {
      "a": "HYPE/USDC",
      "b": "buy",
      "s": "0.28",
      "slippage": "0.01",
      "venue": "hyperliquid",
      "c": "0x0000000000000000000000000000a001"
    }
  ]
}
```

### Outcome markets

:::note\[Not open in production yet]
Outcome trading is not open in production yet. `GET /v1/outcomeMeta` answers
`tradingEnabled: false` and no market until Mosaiq opens it.
:::

An outcome order uses the same fields. `a` is a market of
[`GET /v1/outcomeMeta`](/api/outcome-meta), such as
`BTC-1D-261104-0600-GE76637-YES/USDC`, and `venue` is `hyperliquid`. A token
pays 1 USDC at the expiry when its side wins, and 0 when it loses.

* Your token cash pays for a buy and receives the proceeds of a sale and the
  payout of a settlement
  ([`GET /v1/outcomeSettlements`](/api/outcome-settlements)). A buy holds token
  cash for its notional and the Mosaiq fee: 1 bp of the notional for a taker
  order, 0 for an `Alo`. A buy that your token cash cannot pay gets
  `temporarily_unavailable` and the detail `broker_capacity` with
  `retryAfterMs`. The same refusal moves the difference from your USDC balance,
  as [token cash](#token-cash) describes. Send the buy again after the delay.
  You never move cash yourself.
* A sell needs free tokens: Mosaiq refuses a larger sell with
  `limit_reached` and the detail `cap_exceeded`.
  An account with no Hyperliquid sub-account yet holds no outcome token, so its
  sell gets `limit_reached` and the detail `token_account_required`.
* An outcome market takes `Ioc` and `Alo` limit orders and market orders. Like
  a spot market, it refuses `reduceOnly`, `Gtc`, `expiresInMs`, and a modify.
  It also refuses `priorityFeeBps` on every order, with `invalid_request` and
  the detail `unsupported`, because Hyperliquid takes no priority fee on an
  outcome. An `Alo` rests and fills as on a spot market.
* A limit price is a multiple of 0.00001 inside `(0, 1)`. Mosaiq rounds a buy
  down and a sell up to that step. It refuses a price outside the range with
  `invalid_request` and the detail `invalid_price`.
* A market order is priced from a reference. Mosaiq uses the stream mid when it
  is at most 60 seconds old. Otherwise it reads Hyperliquid's book once: the
  reference is the mid when the book has both sides, or the best price of the
  side that the order takes. Your other orders do not wait for that read.
  Mosaiq sends an `Ioc` at the bound, `reference x (1 + slippage)` for a buy
  and `reference x (1 - slippage)` for a sell, inside `[0.00001, 0.99999]`. A
  quiet market is not a refusal.
* The order gets `temporarily_unavailable` with the detail
  `execution_price_unavailable`, and nothing is sent, when the side that it
  takes is empty, the book cannot be read, Hyperliquid's book is more than 60
  seconds old, or Mosaiq used its book reads for the minute.
* Two payout caps apply to buys. Your tier caps the open payout of all the
  accounts of your owner on outcome markets, and Mosaiq caps the open payout of
  each outcome over every client. Both sides of every outcome count. A buy above
  the room left under a cap is accepted at that room, in whole tokens: its
  answer carries the accepted `size` and `clippedBy`, the code of the cap,
  `max_outcome_owner_payout` or `max_outcome_payout`. When the room is below the
  minimum notional of the market, the buy gets `limit_reached` and the detail
  `cap_exceeded`, and its `msg` names the cap. Under the cap of your tier, `cap`
  also names it (`max_outcome_owner_payout`); the cap of one outcome is no
  limit of your tier and has no `cap`. A sell is never capped.
* A resent place, with the same `c`, answers its clipped `size` without
  `clippedBy`, because Mosaiq does not store the cap. When you resend a place,
  read `size`, and do not depend on `clippedBy`.
* An order that Mosaiq receives at or after the expiry of its market gets
  `invalid_request` and the detail `market_expired`. At the expiry, Mosaiq cancels your resting orders on the
  market: [`orderUpdates`](/api/websocket#orderupdates) shows each one
  `cancelled` with `cancelCause` `market_expired`.
* With outcome trading off, every outcome order gets
  `trading_restricted` and the detail `outcome_trading_disabled`.
  While a fault keeps your sub-account closed to outcome orders, they get
  `temporarily_unavailable` and the detail `token_account_closed`. Perp orders are not affected. A fault of the outcome
  lane alone leaves spot orders open, but a fault of the account part, such as
  an unreadable balance, closes both lanes: your spot orders then get the
  detail `spot_unavailable`.
* Your resting `Alo` that your own `Ioc` would cross is cancelled by
  Hyperliquid's self-trade prevention: `orderUpdates` shows it `cancelled` with
  `failure.code` `venue_rejected` and the detail `self_trade`. Orders of two accounts trade on two venue
  addresses and fill against each other.

```jsonc
{
  "type": "place",
  "orders": [
    {
      "a": "BTC-1D-261104-0600-GE76637-YES/USDC",
      "b": "buy",
      "s": "400",
      "p": "0.5",
      "t": "Ioc",
      "venue": "hyperliquid",
      "c": "0x0000000000000000000000000000c001"
    }
  ]
}
```

With 150 tokens of room left under your tier cap, the buy above is accepted at
150 tokens, and its answer in `data` reads:

```jsonc
{
  "status": "accepted",
  "orderId": "0192f0c4-0000-7000-8000-00000000c001",
  "cloid": "0x0000000000000000000000000000c001",
  "venue": "hyperliquid",
  "size": "150",
  "clippedBy": "max_outcome_owner_payout"
}
```

The write WebSocket answers this item with the frame's `id`.

## Cancel

Cancels identify the order by `venue` and `c`. The asset is resolved from the
original placement. Venue order IDs are never exposed.

A cancel answers `accepted` once Mosaiq launched its venue send. The answer does
not prove that the order ended. The order's own `orderUpdates` rows tell how it
ended: `cancelled`, `filled`, or `failed`. A cancel has no row of its own, and
the venue's answer to the cancel changes nothing on the order.

* A cancel of a placement that Mosaiq never sent needs no venue send, so it is
  accepted even while the venue reconnects.
* A cancel sent while the venue cannot take it, for example during a
  reconnect, answers `temporarily_unavailable` with the detail
  `venue_unavailable` at once. Nothing was accepted, so send it again.
* If the venue refuses an accepted cancel, or does not answer it, Mosaiq
  cancels the same order again once the venue can take it, up to five times
  within about 60 s. If those cancels fail too, the order stays open. Check it
  on `orderUpdates` and cancel it again.
* A repeated cancel of the same order joins the pending one. It answers once
  the launch of that cancel is known: the same item, or the launch's error.
* On Hyperliquid, when your first cancel has no final answer yet, each
  repeated cancel or `mass_cancel` sends the cancel to Hyperliquid once more,
  over REST or the write WebSocket alike. Use it when your own view of
  Hyperliquid shows that the first cancel missed a place that landed after it.
  Mosaiq does not resend this way a first cancel that was part of a
  `mass_cancel`, or a cancel that Mosaiq sent for its own reasons.

```jsonc
{
  "type": "cancel",
  "orders": [
    {
      "venue": "hyperliquid",
      "c": "0x00000000000000000000000000000002",
      "fastCancel": true
    }
  ]
}
```

## Modify

`modify` replaces the price and size of a resting limit order by `c`, on
Hyperliquid or Lighter. `a` and `b` must match the original placement. Order
type and time-in-force cannot change and are read from the existing order;
sending `t` is an unknown field and fails with HTTP `422 invalid_request`.
Modifying a market order fails with `invalid_request` and the detail
`unsupported_order_type`.

Mosaiq does not convert `s` from one venue's meaning to another's. `s` means what the
venue's own modify means:

| Venue | `s` is | Already filled |
| --- | --- | --- |
| `hyperliquid`, `hyperliquid:<dex>` | The size of the order from now on. Hyperliquid replaces the order with a new order of size `s`. | Does not count against `s`. Any positive `s` is valid. |
| `lighter`, `lighter:robinhood` | The order's total size, filled part included. | Counts against `s`. An `s` below the filled size fails with `invalid_request` and the detail `bad_request`. |

Example: an order of 10 has 5 filled, and you want 2 more to rest. Send `s = 2`
on Hyperliquid and `s = 7` on Lighter. On Hyperliquid, a fill that lands on the
old order while the modify is in flight adds to `filledSize`, and the new order
still rests with `s`.

For a reduce-only order, a modify that leaves more size resting than the order
has now takes new allocation priority, and that resting size is clamped to the
reducible position. On Hyperliquid this compares `s` with the order's
`remainingSize`; on Lighter it compares `s` with the order's `size`. A
price-only modify or a size decrease keeps its priority, and trimmed size stays
trimmed.

A modify answers `accepted` once Mosaiq launched its venue send, and its `size`
is the size that send carries after the reduce-only clamp. The venue's verdict
shows on the order's `orderUpdates` row, with the new price and size or with the
previous price and size and a `failure`.

On Hyperliquid, a modify does not wait for the venue's answer to its place. If
the place has no answer yet, Mosaiq writes the modify behind the place on the
same connections without waiting. What Hyperliquid does next depends on the gap
between your place and your modify:

* With no gap (place and modify sent back to back), Hyperliquid can run them in
  either order, as it would for any direct client.
* With a gap of a few tens of milliseconds or more, Hyperliquid processes the
  place first.

If Hyperliquid runs the modify before the place, it refuses the modify, and the
order rests at the price and size of its place until you cancel or modify it
again. A size decrease of a reduce-only order is the exception: it stays, and
Mosaiq trims the order to it. Mosaiq does not resend any other modify. The
order's `orderUpdates` stream
shows a row with `failure.detail` set to `modify_before_place_answer` and
`status` either `"open"` (or `"partially_filled"`) on that row, or `"accepted"`
followed by `"open"` on the next row once Hyperliquid confirms the place. Read
`status`, `price`, `size`, and `filledSize` to track the order, not the venue's
raw `reason` text (which reads `Cannot modify canceled or filled order` even
while the order rests).

At most one modify per order is unresolved at a time. A second modify waits up
to two seconds for the earlier modify's venue outcome, then answers
`blocked_by_other_action` with the detail `modify_in_flight`. Because only one
modify is unresolved at a time, any modify `failure` on `orderUpdates` names
that modify. If the placement already failed or became `uncertain`, a modify
answers `blocked_by_other_action` with the detail
`modify_placement_not_confirmed` and is not sent.

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 place by then,
the modify answers `blocked_by_other_action` with the detail
`modify_placement_not_confirmed`, and Mosaiq does not send it.

On a Hyperliquid perp market, Mosaiq sends a modify even when the new order is
worth less than Hyperliquid's $10 minimum order value (`s × p < 10`).
Hyperliquid cancels the existing order and refuses the new one, so the order
ends `cancelled`. Before the `cancelled` row, an `orderUpdates` row can show
the modify's `failure` with detail `invalid_order` and `rawCode`
`minTradeNtlRejected`. When such a modify of an `Alo` order that is not
reduce-only reaches Mosaiq before its place has left for Hyperliquid, Mosaiq
sends neither of them. A plain close that Mosaiq handles as reduce-only, for
example while the venue is in `user_reduce_only`, counts as reduce-only here:
its modify goes to Hyperliquid behind its place. The modify answers `accepted` with the order's `orderId` and its new
`size`, and the order ends `cancelled` with `neverOnVenue: true` and no modify
`failure`.

To remove an order whose place has no answer yet, send a `cancel` with
`fastCancel: true` rather than a modify under the minimum. If you send such a
modify anyway, follow it with a `cancel` of the same `c`, in its own frame
right after the modify's frame, on the same WebSocket connection. A frame
carries one action type, so the cancel cannot share the modify's frame. Mosaiq
handles the actions of one `c` in the order it receives them, and Hyperliquid
runs the cancel after the orders of its block. The cancel therefore ends the
order even when Hyperliquid ran the modify before the place. When the modify
stopped the place before it left for Hyperliquid, the order has already
ended: that cancel answers `order_not_found` with the detail
`order_not_found_for_cancel`, as a second `cancel` does after a first `cancel`
stopped the place. The order's `cancelled` row on `orderUpdates` is the
outcome.

On Lighter, a modify under the minimum answers
`invalid_request` with the detail `min_notional`, and Mosaiq does not send it.

On Hyperliquid, a modify can carry its own deadline, `expiresAfter` (see
[Venue-specific fields](#venue-specific-fields)). Mosaiq checks it again after
any wait, and a modify whose deadline passed meanwhile answers
`invalid_request` with the detail `deadline_unreachable` and is not sent. A
modify whose failure on `orderUpdates` has the detail `expired` or
`deadline_unreachable` never ran: the order stays `open` with its previous
price and size.

```jsonc
{
  "type": "modify",
  "orders": [
    {
      "venue": "hyperliquid",
      "c": "0x00000000000000000000000000000005",
      "a": "BTC",
      "b": "buy",
      "p": "63000",
      "s": "1"
    }
  ]
}
```

## Mass cancel

`mass_cancel` cancels every open order of the authenticated user. `venues`
restricts it; omit it or pass `[]` for all venues. An unknown venue code fails
the whole request with `invalid_request` and the detail `unknown_venue`.

```jsonc
{ "type": "mass_cancel", "venues": ["hyperliquid"], "fastCancel": true }
```

The response `data` holds one item per targeted open order, in no guaranteed
order. Each item answers once Mosaiq launched that order's cancel: `accepted`
with the `orderId` of that cancel, the order's `cloid`, and its `venue`, or that
order's own error. An order that another cancel already holds answers like a
repeated cancel. The answer does not wait for any order to end. Each order then
ends on its own `orderUpdates` rows, as after a single cancel. A user with
nothing open gets `"data": []`. The 20-action cap does not apply.

## Deposit

A deposit is USDC on Arbitrum from the registered wallet to the returned
treasury address. The request is tracked for one hour. `amount` is at least 1
USDC with at most 6 decimals; otherwise the request fails with HTTP 422
`invalid_request`.

Mosaiq credits the account only after it sees a transfer whose sender is the
registered wallet and whose amount equals `amount` exactly, before
`expiresAtMs`. Mosaiq ignores transfers below 1 USDC. A deposit above 10,000
USDC, and any other transfer that matches no request, waits for a manual
review before Mosaiq credits it.

A deposit always credits the master account. A deposit request with the API
key of a sub-account fails with `403 forbidden` and the detail
`master_account_required`. To fund a
sub-account, deposit to the master account, then send a [`transfer`](#transfer).

```jsonc
{ "type": "deposit", "amount": "100" }
```

```jsonc
{
  "status": "ok",
  "data": [
    {
      "status": "accepted",
      "requestId": "...",
      "kind": "deposit",
      "amount": "100",
      "chain": "arbitrum",
      "from": "0x...",
      "to": "0x...",
      "expiresAtMs": 1780003600100
    }
  ],
  "server_time_ms": 1780000000100,
  "server_receive_time_ms": 1780000000088
}
```

## Withdraw

`withdraw` creates a tracked request that pays the registered wallet. It is not
an instant payout. A withdrawal takes the wallet session. An API key gets
`401 unauthorized` with the detail `wallet_auth_required`, and Mosaiq writes no
withdrawal request.

| Rule | Refusal |
| --- | --- |
| `amount` is above 0, with at most 6 decimals. | HTTP `422 invalid_request` |
| `amount` is at most the lower of `totalCashUsdc` and `availableFunds`, and no other withdrawal of the account is pending. | HTTP `403 limit_reached`, detail `insufficient_available_funds` |
| Same rule, when your token cash covers the difference. Mosaiq moves your token cash back to your USDC balance ([token cash](#token-cash)). | HTTP `403 temporarily_unavailable`, detail `broker_capacity`, with `retryAfterMs` |
| The withdrawals of all Mosaiq clients together stay under a rolling cap, 10,000 USDC per hour. Pending and completed requests count. | HTTP `429 rate_limited`, detail `withdraw_limit_exceeded` |
| No funding settlement is pending for the account. | HTTP `409 temporarily_unavailable`, detail `funding_settlement_pending` |

The withdrawals of other clients can fill the rolling cap, so retry when the
window has room, or with a smaller amount. After `funding_settlement_pending`,
retry once settlement completes. Funding settlement can also delay the payout
of a withdrawal that is already pending.

```http
Authorization: Bearer <para-jwt>
X-Tessera-Wallet: 0x... # required when the JWT has multiple EVM wallets
```

```jsonc
{ "type": "withdraw", "amount": "100" }
```

```jsonc
{
  "status": "ok",
  "data": [
    {
      "status": "accepted",
      "requestId": "...",
      "kind": "withdraw",
      "amount": "100",
      "chain": "arbitrum",
      "destination": "0x..."
    }
  ],
  "server_time_ms": 1780000000100,
  "server_receive_time_ms": 1780000000088
}
```

Track both request kinds through [`GET /v1/funding`](/api/funding).

A withdrawal always debits the master account and pays the owner's wallet. To
withdraw the cash of a sub-account, transfer it to the master account first.

## Transfer

`transfer` moves USDC between two accounts of the session owner: from the
master account to a [sub-account](/concepts/sub-accounts), back to the master
account, or between two sub-accounts. A transfer takes the wallet session. An
API key gets `401 unauthorized` with the detail `wallet_auth_required`, and the
write WebSocket refuses a transfer with `invalid_request` and the detail
`unsupported`.

```http
Authorization: Bearer <para-jwt>
X-Tessera-Wallet: 0x... # required when the JWT has multiple EVM wallets
```

```json
{
  "type": "transfer",
  "transferId": "8f1e3c2a-5f0b-4a3e-9c2d-1b7d1e6f0a11",
  "from": "0x0000000000000000000000000000000000000001",
  "to": "0x9f3c5d0e7a41b2c86f1d94e03a5b7c2d18e6f0a1",
  "amount": "250.50"
}
```

| Field | Rule |
| --- | --- |
| `transferId` | Your id for this transfer: 1 to 64 ASCII letters, digits, `-`, or `_`. It is unique per owner. A UUID is a good choice. |
| `from` | The address of the account that sends the USDC. |
| `to` | The address of the account that receives the USDC. It is not `from`. |
| `amount` | A plain decimal string above 0, with at most 6 decimals. |

The amount must not exceed the `withdrawableUsdc` of the `from` account in
[`clearinghouseState`](/api/clearinghouse-state#positions-and-margin): the
lower of its cash and its available margin, with its orders in flight
counted. Unlike a withdrawal, a transfer has no rolling cap and no pending
state.

The transfer is complete when the answer arrives. Mosaiq debits `from` and
credits `to` in one step. A refused transfer moves nothing. `data` is one
object, not an array, and the answer has no `server_receive_time_ms`:

```jsonc
{
  "status": "ok",
  "data": {
    "type": "transfer",
    "transferId": "8f1e3c2a-5f0b-4a3e-9c2d-1b7d1e6f0a11",
    "from": "0x0000000000000000000000000000000000000001",
    "to": "0x9f3c5d0e7a41b2c86f1d94e03a5b7c2d18e6f0a1",
    "amount": "250.5",
    "status": "completed",
    "completedAtMs": 1790000000012,
    "fromAvailableAfter": "749.5",
    "toTotalCashAfter": "250.5"
  },
  "server_time_ms": 1790000000020
}
```

| Field | Meaning |
| --- | --- |
| `status` | Always `completed`. |
| `completedAtMs` | When Mosaiq recorded the transfer. |
| `fromAvailableAfter` | The `withdrawableUsdc` of `from` when Mosaiq answered. `null` when Mosaiq cannot price the margin of `from` at that time. |
| `toTotalCashAfter` | The cash of `to` when Mosaiq answered. |

### Send the same transfer again

If the connection closes before the answer arrives, send the same request
again with the same `transferId`. If the first attempt completed, the answer
is `200` with the stored transfer and its first `completedAtMs`. Nothing moves
again, even if `from` no longer has the funds. The balance fields show the
values at the time of the retry. If the first attempt did not complete, the
retry is a new transfer.

A `transferId` that names a transfer with other accounts or another amount
fails with `409 duplicate_id` and the detail `transfer_id_reused`. To send a
new transfer, use a new `transferId`.

### Transfer refusals

| HTTP | `code` | `detail` | Meaning |
| --- | --- | --- | --- |
| `409` | `temporarily_unavailable` | `funding_settlement_pending` | Funding settlement is pending for `from`. Retry after settlement completes. |
| `503` | `temporarily_unavailable` | `oracle_unavailable`, `margin_unavailable` | Mosaiq cannot price the margin of `from`. |
| `503` | `temporarily_unavailable` | `startup_recovery_in_progress`, `risk_engine_stalled` | As for `withdraw`. Retry later. |
| `503` | `temporarily_unavailable` | `risk_core_unavailable`, `gateway_unavailable` | Mosaiq cannot process the transfer. Retry with the same `transferId`. |
| `422` | `invalid_request` | `invalid_request` | A field is missing or unknown, `from` or `to` is not an EVM address, or `amount` is not a plain decimal string (for example `"1e3"`), is not above 0, or has more than 6 decimals. |
| `400` | `invalid_request` | `invalid_transfer_id` | `transferId` breaks the id rule. |
| `400` | `invalid_request` | `same_account` | `from` and `to` are the same account. |
| `403` | `limit_reached` | `insufficient_funds` | `amount` exceeds the `withdrawableUsdc` of `from`. `msg` gives that value when Mosaiq knows it. |
| `403` | `trading_restricted` | `operations_halted` | `from` holds a position on a market that Mosaiq halted. |
| `409` | `duplicate_id` | `transfer_id_reused` | The `transferId` names a transfer with other accounts or another amount. |
| `401` | `unauthorized` | `wallet_auth_required` | The bearer is an API key. |
| `403` | `forbidden` | `account_not_owned` | `from` or `to` is not an account of the session owner. |

A transfer spends the exchange request budget of the master account. Read
the transfers of the owner in [`GET /v1/funding`](/api/funding#transfers).

## Batches

`orders` carries up to 20 actions of one kind: places (limit and market, any
venues), modifies, or cancels. Receipt order follows the array. Unrelated items
can execute independently, so array order does not determine which placement
reserves margin first. `data` answers item by item, by input index. An empty
`orders` array fails the request with `invalid_request` and the detail
`bad_request` (place, modify) or `invalid_cancel` (cancel); more than 20 items
fails it with `invalid_request` and the detail `batch_too_large`, and nothing
is processed.

A batch is not atomic. Each item has its own outcome. On the
[WebSocket API](/api/exchange-websocket#ordering), a later cancel can prevent
an eligible pending placement inside a batch. The other items continue, and
the prevented item answers `accepted` in its original position.

On Hyperliquid, the items of one batch that share a packing key leave as one
Hyperliquid action, in array order. One action uses one request of the IP
budget and one nonce. The key depends on the kind of item:

* Places share a key when they go to the same venue, Mosaiq account and
  signing agent, and have the same order type (`Alo`, or `Ioc` and market),
  the same `reduceOnly`, the same `priorityFeeBps` and the same
  `expiresAfter`.
* Cancels share a key when they cancel orders of one Mosaiq account that the
  same agent signed and that Mosaiq sends on the same connection.
* Modifies share a key when their orders are on one Mosaiq account and signed
  by one agent, when they have the same `expiresAfter` and the same
  reduce-only status, and when Mosaiq sends them on the same connection. A
  modify of an order whose place is still unanswered goes on the connection of
  that place, so modifies of orders placed in one action can still split.

Each dedicated signing agent has its own keys, so one batch of a client with
two agents can leave as two actions. While a Mosaiq account runs low on its
Hyperliquid request budget, its reduce-only places and modifies leave alone.

Each item keeps its own answer in `data` and its own `orderUpdates` rows. When
Hyperliquid refuses a whole action, for example as expired or congested, each
order of the action gets that refusal. An item that reaches Mosaiq's venue
client after the first item of its batch leaves in its own action. A batch of
one Hyperliquid item, a `mass_cancel`, every Lighter item, every spot or
outcome item, and a place with `replaces` leave alone.

```jsonc
{
  "type": "place",
  "orders": [
    { "a": "BTC", "b": "buy", "p": "65000", "s": "1", "venue": "lighter", "t": "Alo", "expiresInMs": 3600000, "c": "0x00000000000000000000000000000003" },
    { "a": "ETH", "b": "sell", "s": "0.1", "slippage": "0.01", "venue": "hyperliquid", "c": "0x00000000000000000000000000000004" }
  ]
}
```

## Fields

| Field | Type | Description |
| --- | --- | --- |
| `type` | `string` | `place`, `modify`, `cancel`, `mass_cancel`, `deposit`, `withdraw`, or `transfer`. |
| `orders` | `array` | The items of a `place`, `modify`, or `cancel`, at most 20. See [Batches](#batches). |
| `a` | `string` | Canonical asset from `data.assetData.universe[*].name`, or a market from [`GET /v1/spotMeta`](/api/spot-meta) or [`GET /v1/outcomeMeta`](/api/outcome-meta). Place and modify. |
| `b` | `string` | `buy` or `sell`. Place and modify. |
| `p` | `string` | Limit price. Required with `t` and on modify; absent on market orders. |
| `s` | `string` | Size in base units. Place and modify. |
| `slippage` | `string` | Market-order slippage fraction in `(0, 0.5]`, for example `"0.01"`. |
| `venue` | `string` | Venue code from `data.assetData.universe[*].venues[*].venue`, or from `markets[*].venue` of `GET /v1/spotMeta` for a spot market. Required on place, modify, and cancel. |
| `venues` | `array` | `mass_cancel` filter; empty means all. |
| `t` | `string` | `Ioc` or `Alo`. Required on limit placements; not accepted on modify. |
| `reduceOnly` | `boolean` | Place only. See [Reduce-only](#reduce-only). |
| `c` | `string` | Client order id. Optional on place, required on modify and cancel. |
| `expiresInMs`, `expiresAfter`, `priorityFeeBps`, `replaces`, `fastCancel` | `number`, `string` or `boolean` | Optional fields of one venue. See [Venue-specific fields](#venue-specific-fields). |
| `amount` | `string` | USDC amount for `deposit`, `withdraw`, and `transfer`. |
| `transferId`, `from`, `to` | `string` | `transfer` only. See [Transfer](#transfer). |

`c` is `0x` followed by exactly 32 lowercase hexadecimal characters and must
not be all zeros. Uppercase is rejected. If omitted on a REST placement, Mosaiq
generates one and returns it. A user cannot hold two open orders with the same
`c`; a repeated `c` inside one place or cancel batch fails the later item with
`duplicate_id` and the detail `duplicate_cloid`. A modify batch that names one
`c` twice is refused whole with HTTP `400`, `invalid_request` and the detail
`bad_request`, and nothing is sent.

For placements, this batch rule applies to both REST and WebSocket. A later
duplicate remains rejected if the first placement fails margin admission or
is prevented by a cancel before venue dispatch. The later item does not
become a fallback placement. See [WebSocket ordering](/api/exchange-websocket#ordering)
for cancellation of pending placements. Separate REST requests have no
ordering guarantee.

Decimal values are JSON strings in both directions. Send each decimal field
(`p`, `s`, `slippage`, `priorityFeeBps`, `amount`) as a plain decimal: digits
and an optional `.` followed by digits, for example `"0.5"` or `"65000"`.
Mosaiq refuses every other form and never reads it as another number. This
includes separators (`"0_5"`), exponents (`"1e-1"`, `"5E-3"`), a `+` sign,
spaces, `".5"`, `"5."`, an empty string, a JSON number, and more than 28 digits
after the point. The whole request then fails with HTTP `422 invalid_request`,
and Mosaiq sends no item. A negative value fails the rule of its field instead.

A USDC `amount` is held in whole micro-USDC, the unit of an on-chain USDC
transfer. A `deposit` amount is at least 1, and a `withdraw` or `transfer`
amount is above 0. Each has at most 6 decimals; trailing zeros past the sixth
are allowed, so `"100.0000000"` is 100 USDC. An amount that breaks its rule
also fails the whole request with HTTP `422 invalid_request`.

Mosaiq returns the `amount` of a deposit, a withdrawal, or a transfer without
trailing zeros, whatever digits the request had. A `deposit` sent with
`"1.50"` or with `"1.5"` returns `"amount": "1.5"`, and `"100.000010"` returns
`"100.00001"`. Compare a returned amount with the amount you sent as numbers,
not as strings.

### Venue-specific fields

Some optional fields exist on one venue only. Sending one elsewhere returns
`invalid_request` with the detail `unsupported`.

Hyperliquid:

* `expiresAfter` (`number`, Unix milliseconds). An optional absolute deadline
  for this placement or modify, on any Hyperliquid perp market. Mosaiq signs it
  into the Hyperliquid action, and Hyperliquid refuses the action if it reaches
  a block after that time, so a late quote never rests. It is not
  `expiresInMs`. Spot markets and Lighter do not accept it.
  * The deadline must leave at least 150 ms for an `Alo` order and 450 ms for an
    `Ioc` or market order when Mosaiq checks it. Hyperliquid puts an `Ioc` or
    market order in a block about 280 ms after an `Alo` order that it gets at
    the same time. `priorityFeeBps` does not change these minimums. A modify
    sends an order with the time-in-force of the order it modifies, so it takes
    the minimum of that order.
  * With less time left, the item returns `invalid_request` with the detail
    `deadline_unreachable`, and Mosaiq sends nothing. `msg` gives the time
    left, the minimum and the order type,
    for example `deadline unreachable: expiresAfter 1762862400300 leaves 300 ms,
    under the 450 ms floor for Ioc and market orders`. A modify is checked when
    Mosaiq finds its order, and again after any wait for an earlier modify. A
    deadline more than 24 hours ahead, for example one in microseconds, returns
    `invalid_request` with the detail `invalid_expiry`. Send milliseconds, not
    seconds or microseconds.
  * Mosaiq checks the deadline again before it signs, before it hands the
    action to its sockets, and before each copy goes to Hyperliquid. When the
    check before signing or before the handoff fails, or when every copy is
    dropped, nothing is sent, and `orderUpdates` reports `failure.code`
    `invalid_request` with the detail `deadline_unreachable`. When only some
    copies are dropped, the copy already sent decides the outcome. When
    Hyperliquid refuses the action as late, `orderUpdates` reports
    `failure.code` `venue_rejected` with the detail `expired`.
  * On a placement, both details mean that no order exists: the row is `failed`.
    On a modify, they mean that the modify never ran: the order stays `open`
    with its previous price and size, and its row carries the modify's
    `failure`. Read `status`, not `failure.code`.
  * A modify's deadline belongs to that modify only. A modify does not inherit
    the deadline that its order was placed with.
  * An action carries one deadline, so orders of one batch with the same
    `expiresAfter` share an action (see [Batches](#batches)). Hyperliquid
    charges an action that it refuses as late five times its usual address
    rate limit, for each order of the action.

* `priorityFeeBps` (`string`, basis points, for example `"2.5"`). An optional
  Hyperliquid priority fee, when Mosaiq enables priority fees. Every Hyperliquid
  market accepts it: core perps, HIP-3 perps and spot. A spot `Alo` order and an
  order on an outcome market refuse it. Mosaiq signs your rate into the action
  of the order. An action carries one rate, so orders of one batch with the
  same rate and the same `expiresAfter` share an action (see
  [Batches](#batches)). How you pay depends on the order:

  * An `Ioc` or market order pays the rate on each fill, in USDC, on your filled
    notional. The fill shows it in `fees.priority`. An order that does not fill
    pays nothing. The rate must be at most the limit of your account. That
    limit is 8 bp unless Mosaiq raised it for you, and at most 20 bp. A rate
    above it is refused with `invalid_request` and the detail
    `invalid_priority_fee`. Its `msg` names the limit.
  * An `Alo` order pays the rate once, in USDC, on its resting notional (size
    times limit price), when Hyperliquid accepts the order. You pay it whether
    the order fills or not, and a cancel refunds nothing. The order's
    `orderUpdates` row shows it in `priorityFee`. Its fills pay no priority fee.
    An order that Hyperliquid refuses pays nothing, for example a post-only
    order that would cross the book. The rate must be at most the limit of
    your account, as for an `Ioc`. Your free
    collateral must cover the order's margin plus the fee, and Mosaiq holds the
    fee until Hyperliquid accepts the order. You can modify the order.
    Hyperliquid's modify carries no priority fee: the new order has no priority
    and pays no fee. Mosaiq does not refund the fee that the order paid at its
    placement, and the order's `priorityFee` still shows that fee.
  * A reduce-only `Alo` order and a `Gtc` order do not accept it.
  * The rate must be above 0, in steps of 0.0001 bp. A finer rate is refused, not
    rounded.
  * Send a plain decimal string, such as `"0.5"`. A separator or an exponent
    (`"0_5"`, `"5e-1"`) fails the whole request with `422 invalid_request`.
  * Lighter and modify requests do not accept it.
  * On a perp `Ioc` or market order, your margin must cover the highest fee of
    the order, the rate times its size at the higher of its limit price and the
    oracle price, on top of its initial margin. A reduce-only order is refused
    with `limit_reached` and the detail `cap_exceeded` when your equity cannot
    pay that fee.
  * A perp market buy is signed at most at the higher of the oracle price and
    Hyperliquid's mid, moved by its `slippage`. Mosaiq sizes its margin and its
    fee at that same price. Without a Hyperliquid mid from the last 10 s, it
    uses the oracle alone. When the Hyperliquid ask is above that price, the buy
    fills nothing and pays nothing.
  * When the stake that pays Hyperliquid cannot cover the fee, or while Mosaiq
    does not know that stake, the item gets `temporarily_unavailable` with the
    detail `broker_capacity`, and nothing is sent: retry shortly, or send the
    order without `priorityFeeBps`. An `Alo` needs its whole fee at once, so a
    large one at a high rate can get this error while smaller orders pass.
  * Mosaiq signs the order to expire 10 s after it signs it, or at the
    order's `expiresAfter` when that comes first. Hyperliquid rejects an order
    that it has not included by then: the answer is `accepted`, and
    `orderUpdates` then reports the order `failed` with `failure.code`
    `venue_rejected` and the detail `expired`. When the
    10 s passed first, the failure also has the `rawCode`
    `actionAlreadyExpired`: nothing of the order executed, so you can send it
    again. An `Alo` that Hyperliquid included in time rests as usual. The
    expiry bounds only when Hyperliquid may include the order.
  * Your `expiresAfter` keeps the minimum of its order type: with less time
    left, the item returns `invalid_request` with the detail
    `deadline_unreachable`, and Mosaiq does not sign its own 10 s instead.
    When its own 10 s comes first, Mosaiq checks no
    deadline before the handoff or before each copy: only Hyperliquid refuses
    the order after the 10 s.

  See the [Hyperliquid priority fees documentation](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/priority-fees).

* `replaces` (`string`, a client order id). The `c` of your order that this
  placement replaces. Mosaiq sends the placement as one Hyperliquid
  always-place modify of that order. Hyperliquid cancels the replaced order if
  it is still on the book, then places this order. It places this order even
  when the replaced order already filled or was canceled. When the replaced
  order has already ended at Mosaiq, Mosaiq sends this order as a plain
  placement.
  * This order is a new order with its own new `c`, and it answers like any
    placement. The replaced order keeps its `c`. Its `orderUpdates` row shows
    `cancelled` once Hyperliquid cancels it, or `filled` if it filled first.
  * This order is admitted as a new placement. Until Hyperliquid cancels the
    replaced order, both orders count toward your margin, your caps and your
    open-order limit.
  * The replaced order must be on the same market and venue, with the same `b`
    and `reduceOnly`. A
    [closing order on a reduce-only venue](#closing-orders-on-a-reduce-only-venue)
    counts as reduce-only, even after the venue opens again: replace it with
    `reduceOnly: true`, or cancel it and place a new order. An `Alo` order
    replaces only an `Alo` order, and any other order only a non-`Alo` one. A
    mismatch returns `invalid_request` with the detail `bad_request`, as does a
    `replaces` equal to the placement's own `c`.
  * Hyperliquid must have accepted the replaced order, with no modify of it in
    flight. Mosaiq does not wait. Otherwise the item returns
    `blocked_by_other_action`, with the detail `modify_placement_not_confirmed`
    or `modify_in_flight`, and is not sent. An order that may still be on the book while not open, for
    example with a cancel in flight, also gets the detail
    `modify_placement_not_confirmed`.
  * A `replaces` that matches none of your orders on that venue returns
    `order_not_found` with the detail `order_not_found_for_cancel`.
  * Lighter, spot markets and an order with `priorityFeeBps` do not accept it.
  * When Hyperliquid refuses this order, it may still have canceled the
    replaced order. Two refusals are exceptions: a refusal for the order's
    `expiresAfter`, and a refusal because too many actions of the venue account
    were still waiting for a block. With the detail `expired`,
    `deadline_unreachable` or `venue_busy`, the modify never ran, and the
    replaced order stays as it was.
  * When Hyperliquid sheds the action because its L1 is congested, Mosaiq cannot
    tell whether the replaced order was canceled. The order then becomes
    `uncertain` instead of failing with the detail `venue_busy`, and Mosaiq
    reconciles it by `cloid`.

* `fastCancel` (`boolean`, `cancel` item and `mass_cancel` only, `false` when
  absent; alias `fast_cancel`). Best-effort acceleration for cancelling a
  Hyperliquid perp `Alo` order whose placement has not been answered by the
  venue yet. When applicable, Mosaiq pairs the cancel with a kill-modify so
  the order is removed even if the cancel reaches Hyperliquid ahead of its
  placement. See [Fast cancel](/api/optimizing-latency#fast-cancel). An order
  that left in one Hyperliquid action with other orders of its batch gets no
  nonce-invalidation noop, because a noop voids the whole action.
  * Best effort everywhere: `fastCancel: true` never refuses a cancel. On
    Lighter, on spot or outcome markets, on `Ioc`, market or reduce-only
    orders, on already-resting orders, or when one lot is worth $10 or more,
    Mosaiq runs the normal cancel and skips the kill-modify. Mosaiq also skips
    the kill-modify when the connection that sent the order to Hyperliquid has
    no room for one more order at that moment, when the Hyperliquid address
    that sent the order has spent its request quota, or when too little of the
    cancel's deadline is left. A new order can still go to Hyperliquid on
    another connection at that moment. The kill-modify uses the room for new
    orders on the connection of its order, never the room that Mosaiq keeps
    for cancels.
  * `cancelAllOnDisconnect` uses classic cancels only and never sends a
    kill-modify.
  * Passing `fastCancel` on a `place` or `modify` item returns `invalid_request`
    (HTTP 422 with detail `invalid_request` on REST; detail `bad_request` on
    WebSocket) as an unknown field.
  * Neither the cancel answer nor `orderUpdates` or read endpoints report
    whether a kill-modify was sent.
  * `fastCancel: true` changes the cost of the request: the `cancel` or
    `mass_cancel` costs 2 units of your exchange budget, on every venue, where
    it costs 1 without the field (see [Rate limits](/api/rate-limits)). The
    second unit never refuses the request: with 1 unit left, it is still
    accepted, and your next request waits until 2 units refill. The kill-modify
    that Mosaiq sends costs no more units and has no fee.

Lighter (`lighter` and `lighter:robinhood`):

* `expiresInMs` (`number`). Lifetime of an `Alo` placement, from `610000`
  milliseconds (10 minutes 10 seconds) to `2592000000` milliseconds (30 days).
  Omitting it uses 30 days. An out-of-range value returns `invalid_request`
  with the detail `invalid_expiry`.
  Lighter removes the order from the book when it expires.

Lighter trades some markets only in isolated margin. On such a market, Mosaiq
stops a placement before it reaches the venue while the Mosaiq venue account is
not yet set to isolated margin there. The placement still answers `accepted`,
and `orderUpdates` reports the order `failed` with `failure.code`
`trading_restricted`, the detail `market_unavailable`, and the reason. Retry
later, or send the order to another
venue. Reduce-only placements are not stopped for this reason.

## Precision and constraints

Clients send decimal strings for `p` and `s` and never encode venue-native
formats. Each venue market publishes its constraints in
[`data.assetData.universe[*].venues[*].constraints`](/api/clearinghouse-state):

| Field | Meaning |
| --- | --- |
| `sizeDecimals`, `sizeIncrement` | Size precision and step. |
| `priceDecimals`, `tickSize` | Price precision and grid. |
| `minNotional`, `minBaseAmount` | Minimum quote notional and base size, when the venue has them. |
| `maxBaseAmount`, `maxLimitNotional`, `maxMarketNotional` | Maximums; exceeding one fails with `invalid_request` and the detail `bad_request`. |
| `supportsReduceOnly`, `supportsPostOnly`, `requiresIsolatedMargin` | Venue capabilities. |
| `maxPositionNotional`, `openInterestCap`, `maxOpenOrders` | Limits that the venue publishes, when it has them. Your own open-order limit is `maxOpenOrders` of `userCaps`. |

Mosaiq fits the request to the selected venue before sending it:

* `s` rounds down to the venue's size precision and increment.
* A buy limit `p` rounds down and a sell limit `p` rounds up, so the price
  never becomes more aggressive.

After fitting, Mosaiq refuses the item with `invalid_request` and one of these
details. Only that item fails.

| Case | `detail` |
| --- | --- |
| The size rounds to zero. | `bad_request` |
| The price rounds to zero. | `invalid_price` |
| The price cannot be placed on the tick grid. | `invalid_precision` |
| The notional is below the minimum. | `min_notional` |

Use `constraints` to check and size orders before you send them. Mosaiq still
decides at acceptance time.

## Response

The [write WebSocket](/api/exchange-websocket#answers) answers a frame with this
body and the frame's `id` first, on a connection opened with
`nestedFormat=false`.

`data` is an array aligned by index with `orders` (see
[Mass cancel](#mass-cancel) and [Transfer](#transfer) for the exceptions). Each item is an
acknowledgement, not a venue outcome, and no item waits for the venue. Each item
carries a `status`:

* `accepted`: Mosaiq owns the action and launched its venue send. A placement
  carries `orderId`, `cloid`, `venue`, and `size`, the size after venue fitting
  and any reduce-only clamp. A modify carries the same fields, and its `size` is
  the size its send carries. A cancel carries its own `orderId`, not the order's,
  with `cloid` and `venue` and no `size`. A placement that your own cancel
  stopped before any send also answers `accepted`. Funding requests carry their
  request metadata. `accepted` does not prove that the venue took the order, that
  it rests, or that it filled or ended.
* `error`: Mosaiq refused the action. The item carries the
  [error object](/api/errors), `code`, `detail`, `msg`, and
  `maybeSent`, `retryAfterMs` or `cap` when they apply, with `cloid` when known.
  Without `maybeSent`, the refusal came before any venue effect. No
  `orderUpdates` row follows for that `cloid`, except after a failed launch
  (below), and you can use it again. With `maybeSent: true`, the action may
  have reached the venue. Check it on `orderUpdates` or `openOrders` before you
  send it again. Other items in the batch keep their own results.

Every venue outcome reaches you only on [`orderUpdates`](/api/websocket#orderupdates)
and [`userFills`](/api/websocket#userfills), as
[Follow each write on orderUpdates](#follow-each-write-on-orderupdates) shows.

```jsonc
// success: one item accepted, one refused
{
  "status": "ok",
  "data": [
    {
      "status": "accepted",
      "orderId": "...",
      "cloid": "0x00000000000000000000000000000002",
      "venue": "hyperliquid",
      "size": "1"
    },
    {
      "status": "error",
      "code": "invalid_request",
      "detail": "min_notional",
      "msg": "minimum notional not met: BTC notional must be >= 10 on hyperliquid",
      "cloid": "0x00000000000000000000000000000003"
    }
  ],
  "server_time_ms": 1780000000100,
  "server_receive_time_ms": 1780000000088
}

// request-level error: no data[] is returned
{
  "status": "error",
  "data": {
    "code": "invalid_request",
    "detail": "batch_too_large",
    "msg": "batch too large: batch has 21 orders, max is 20"
  },
  "server_time_ms": 1780000000100
}
```

An item refused while Mosaiq runs an operation on its Hyperliquid account
carries the wait in `retryAfterMs`:

```jsonc
{
  "status": "error",
  "code": "temporarily_unavailable",
  "detail": "account_operation_in_progress",
  "msg": "Hyperliquid places and modifies are paused for at most 1250 ms while Mosaiq runs an operation on its Hyperliquid account. Cancels and Lighter are not affected.",
  "retryAfterMs": 1250,
  "cloid": "0x00000000000000000000000000000004"
}
```

The top-level `status` is `ok` once the request itself was processed, even if
every item is an `error`. Request-level errors cover authentication, rate
limits, malformed bodies, empty or oversized batches, an unknown
`mass_cancel` venue, and funding failures. Risk-engine, recovery, and halt
rejections are item-level for `place` and `modify`. One Lighter failure mode
is also request-level: when every `place` or `modify` item of a REST request
meets the degraded Lighter transaction quota before its launch, the whole
response becomes HTTP `503` with `temporarily_unavailable` and the detail
`venue_unavailable`, and nothing was sent. When only some items meet it, each
of them answers that error and the others keep their own results. Cancel
batches return their item results instead.

An unexpected processing failure can also return a request-level error after
earlier actions were sent. That error carries `maybeSent: true`. Check the
batch's orders before retrying it.

The details `risk_core_unavailable` and `gateway_unavailable`, with
`temporarily_unavailable`, and `gateway_out_of_service`, with `out_of_service`,
can affect the whole request or one item. An item-level error with one of these
details and no `maybeSent` means that item was not sent; other items may
already have succeeded. A retry can succeed after `temporarily_unavailable`.
After `out_of_service`, Mosaiq refuses every new request, and every retry
fails the same way until Mosaiq restores service. Retrying sooner does not
help. The item detail `venue_contained` is the one exception: it closes only one
venue, and your actions on the other venues go through.

Two kinds of item error can still be followed by an `orderUpdates` row:

* An error with `maybeSent: true`, such as `request_uncertain`: Mosaiq cannot
  confirm whether it accepted the action, or the action may have left before
  the error. The action may still execute after recovery, and a cancel may
  already have stopped a pending placement. Reconcile through `orderUpdates` or
  `openOrders` before retrying. Sibling results remain in `data[]`, including
  orders already accepted. Do not retry an entire batch on the assumption that
  no item was sent.
* A launch that fails after Mosaiq recorded the action, with nothing sent.
  This happens when Mosaiq's sender for the venue stopped, or when Mosaiq
  cannot prepare another of its venue accounts that a reduce-only placement
  needs. The item answers its error, without `maybeSent`. For a placement,
  the order then shows one `failed` row; for a modify, the order's row shows
  the modify's `failure`. That failure carries no `maybeSent` either. It has
  the item's detail when an order failure of that name proves that nothing was
  sent, such as `congestion_share_exhausted` or `send_capacity`, and otherwise the detail
  `venue_unavailable` with `failure.code` `temporarily_unavailable`. A cancel
  leaves its order unchanged, and your next cancel of that order is a new
  cancel.

### Find your orders in venue data

Mosaiq never sends your `cloid` to the venue, because one venue account holds
the orders of many users. Mosaiq gives each order its own client order id at
the venue, the `venueCloid`. The order's
[`orderUpdates`](/api/websocket#orderupdates) rows name it. To get it in the
answer too, add `includeVenueCloid=true` to the request URL:

```text
POST /v1/exchange?includeVenueCloid=true
```

An `accepted` placement or modify then also carries `venueCloid`. A cancel
never carries it. Without the parameter, the answer does not change.

```json
{ "status": "accepted", "orderId": "01a0f6a1-2cfb-7313-93a3-35e8d2902c88", "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "size": "1", "venueCloid": "0x7d3f0c2a9b8e4f51a6c2d9e0b1f3a4c5" }
```

Use `venueCloid` to find the order in venue data:

* On Hyperliquid, it is the order's `cloid`.
* On Lighter, it is the order's `client_order_index` in hexadecimal. For
  example, `0x00000000002a` is index `42`.

The `venueCloid` of an order does not change, and a modify keeps it. It is
read-only. To modify or cancel the order, send its `cloid` in `c`, not its
`venueCloid`. A placement that your own cancel stopped before the venue held it
still names a `venueCloid`, and its `cancelled` row carries
`neverOnVenue: true`.

If the answer is lost or is a `request_uncertain` error, read the `venueCloid`
from the order's `orderUpdates` rows on a `/v1/ws` connection opened with
`includeVenueCloid=true`. `openOrders` does
not show it yet. On the write WebSocket, connect with `includeVenueCloid=true`
to get it in the answers, as
[Venue client order ids](/api/exchange-websocket#venue-client-order-ids) shows.

You can also recognize your orders without the answer. Mosaiq seals the venue
cloid of each Hyperliquid place that names its `c` with your account's key. The
account's owner gets that key once from the Mosaiq app. Decrypt the venue cloid
to recognize the order, whether or not the answer arrives.
[Keyed venue cloids](/api/optimizing-latency#keyed-venue-cloids) gives the
derivation, the client code and test vectors. If Mosaiq cannot seal a place,
the item answers `temporarily_unavailable` with the detail
`venue_cloid_keys_unavailable`, and Mosaiq sends nothing.

### Follow each write on orderUpdates

Each example below shows the REST answer, then the order's
[`orderUpdates`](/api/websocket#orderupdates) rows, trimmed to the fields that
matter. The write WebSocket answers the same items, in the same body with the
frame's `id` first, on a connection opened with `nestedFormat=false`
([Answers](/api/exchange-websocket#answers)).

A placement is accepted, then rests. An `accepted` row can come first, while the
order is on its way to the venue. `open` means venue evidence shows it resting:

```json
{ "status": "accepted", "orderId": "01a0f6a1-2cfb-7313-93a3-35e8d2902c88", "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "size": "1" }
```

```json
{ "orderId": "01a0f6a1-2cfb-7313-93a3-35e8d2902c88", "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "accepted", "size": "1", "price": "64000", "filledSize": "0" }
{ "orderId": "01a0f6a1-2cfb-7313-93a3-35e8d2902c88", "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "open", "size": "1", "price": "64000", "filledSize": "0" }
```

Hyperliquid refuses a post-only placement that would cross the book. The answer
is still `accepted`. The row is `failed` with `failure.code` `venue_rejected`,
and `reason` and `rawCode` are the Hyperliquid status name. Hyperliquid's own
sentence is not shown:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "failed", "failure": { "code": "venue_rejected", "detail": "invalid_order", "reason": "badAloPxRejected", "rawCode": "badAloPxRejected", "maybeSent": true } }
```

Hyperliquid gets a placement with `expiresAfter` after its deadline. The answer
is still `accepted`. The row is `failed` with `failure.code` `venue_rejected`
and the detail `expired`, and the order did not execute:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "failed", "failure": { "code": "venue_rejected", "detail": "expired", "reason": "Action already expired", "maybeSent": true } }
```

The venue never answers. Two seconds after the launch, the order becomes
`uncertain` with `failure.code` `request_uncertain`. Mosaiq then reconciles it
by `cloid` and publishes its real state. It never sends the order again:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "uncertain", "failure": { "code": "request_uncertain", "detail": "transport_unavailable", "reason": "hyperliquid place acknowledgement timed out after 2000ms; venue send status unknown", "maybeSent": true } }
```

A modify is refused. The answer is `accepted` with the modify's `size`. The
order's row keeps its previous price and size and carries the modify's
`failure`:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "open", "size": "1", "price": "64000", "failure": { "code": "venue_rejected", "detail": "invalid_order", "reason": "badAloPxRejected", "rawCode": "badAloPxRejected", "maybeSent": true } }
```

A Hyperliquid modify with `expiresAfter` reaches Hyperliquid after its deadline.
Hyperliquid refuses the whole modify, so the order keeps its previous price and
size. Here the detail `expired` does not mean that the order is gone:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "open", "size": "1", "price": "64000", "failure": { "code": "venue_rejected", "detail": "expired", "reason": "Action already expired", "maybeSent": true } }
```

An in-flight Hyperliquid modify runs before its place. Hyperliquid refuses the
modify, and the place still rests at its original price and size. If the modify
refusal arrives before the place confirmation, the order first shows `accepted`
with `modify_before_place_answer`, then `open` once Hyperliquid confirms the
place:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "accepted", "size": "1", "price": "64000", "filledSize": "0", "failure": { "code": "venue_rejected", "detail": "modify_before_place_answer", "reason": "Cannot modify canceled or filled order", "maybeSent": true } }
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "open", "size": "1", "price": "64000", "filledSize": "0" }
```

If Hyperliquid's `open` confirmation arrives first, the `open` row itself
carries the `modify_before_place_answer` failure. In both cases, the order
rests at its place's price and size until you cancel or modify it again.

A cancel is accepted with its own `orderId`. The order's next row tells how it
ended. It is `cancelled` when the cancel won, `filled` when a fill came first,
and `failed` when the venue refused the placement. No cancel outcome shows as
`not_on_book`:

```json
{ "status": "accepted", "orderId": "7c1e2a90-55d4-4b0e-9a3f-0d6a1c5e8b21", "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid" }
```

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "cancelled", "size": "1", "filledSize": "0" }
```

Your cancel stops a placement before Mosaiq sends it. The placement and the
cancel both answer `accepted`, and the order shows a plain `cancelled` with no
`failure` and with `neverOnVenue: true`. The order never rested.

On Hyperliquid, a cancel that arrives just after the send can still stop the
placement. Mosaiq sends a noop on the placement's nonce, and Hyperliquid can
accept it before the placement. The order then shows `accepted`, and later the
same `cancelled` row:

```json
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "accepted", "size": "1", "filledSize": "0" }
{ "cloid": "0x00000000000000000000000000000005", "venue": "hyperliquid", "status": "cancelled", "neverOnVenue": true, "size": "1", "filledSize": "0" }
```

A `mass_cancel` answers one `accepted` per targeted order, each with the
`orderId` of the cancel launched for it. Each order then ends on its own rows:

```json
{
  "status": "ok",
  "data": [
    { "status": "accepted", "orderId": "3b9d6f12-8c4e-4f71-b2a5-6e0c9d1f7a34", "cloid": "0x00000000000000000000000000000003", "venue": "lighter" },
    { "status": "accepted", "orderId": "a4f08c3e-1d27-4b96-8e5a-2c7b9f0d6e13", "cloid": "0x00000000000000000000000000000004", "venue": "hyperliquid" }
  ],
  "server_time_ms": 1780000000100,
  "server_receive_time_ms": 1780000000088
}
```

### Cancel-only mode

While Mosaiq's risk engine catches up on a backlog, it accepts only cancels:

* Every `place` and `modify` item returns `temporarily_unavailable` with the
  detail `risk_engine_stalled`, reduce-only placements included. Nothing is
  sent to the venue. In a batch, the refusal is item-level and the response is
  HTTP `200`.
* `withdraw` returns HTTP `503` with `temporarily_unavailable` and the detail
  `risk_engine_stalled`.
* `cancel` and `mass_cancel` work as usual.

Your resting orders stay on the book and can still fill. Fills, funding, and
liquidations continue. The mode ends by itself once the backlog drains; retry
refused actions after a short delay.

### Startup recovery

After a restart, Mosaiq recovers its state on each venue before it opens
normal trading on that venue. Each venue opens on its own: a venue that is
still recovering does not keep the other venues closed. While the startup
recovery of a venue is in progress:

* Every `place` and `modify` item on that venue returns
  `temporarily_unavailable` with the detail `startup_recovery_in_progress`,
  reduce-only placements included. Nothing is sent to the venue. In a batch,
  the refusal is item-level and the response is HTTP `200`.
* `withdraw` returns HTTP `503` with `temporarily_unavailable` and the detail
  `startup_recovery_in_progress` until every venue has recovered.
* `cancel` and `mass_cancel` work as usual.

Once a venue has recovered, normal trading on it stays open: a later recovery
of that venue uses the detail `venue_recovering` instead. A recovering venue refuses only
its own orders. Retry refused actions after a short delay.

### Error codes

[Errors](/api/errors#exchange-errors) lists every `code` and `detail` that this
endpoint and the write WebSocket answer, at request level and per item.

### Token cash

:::note\[Not open in production yet]
Spot and outcome trading are not open in production yet, so no account holds
token cash.
:::

Your token buys spend token cash: your own USDC on the Hyperliquid sub-account
of your account. Mosaiq fills it from your USDC balance. A token buy that your
token cash cannot pay, while your withdrawable USDC covers the difference, gets
the item error `temporarily_unavailable` with the detail `broker_capacity`, and
is not sent. The same refusal starts one move from your USDC balance to your
token cash: the difference plus a margin (20% of the difference, at least 1
USDC), never more than your withdrawable USDC. When your account holds a perp
position or a resting perp order, the move is the difference alone: that USDC is the collateral of your
perp orders and positions. Your first such buy also gives your account its sub-account.

Mosaiq opens spot and outcome trading account by account, and each sub-account
of yours on its own. Until Mosaiq opens a market type for your account, each
buy of that type gets `trading_restricted` with the detail
`token_trading_not_enabled`, and your account gets no Hyperliquid sub-account.
Sells of the tokens that you hold, cancels and perp orders still pass.

* `retryAfterMs` is the number of milliseconds after which Mosaiq expects the
  move to land. It is absent when Mosaiq cannot tell. `msg` ends with
  `retry in <n> ms` when it is present, because the order WebSocket answers the
  message alone.
* A move larger than the USDC that Mosaiq keeps ready on Hyperliquid for these
  moves waits for Mosaiq to add USDC there, whatever its amount. Its buy gets
  `temporarily_unavailable` with the detail `broker_capacity` and no
  `retryAfterMs`. Send the buy again later, or read
  `lastTokenCashTransfer` until the move is `confirmed`.
* A buy refused while the move is on its way starts no other move and shows
  the delay of the same move.
* When your withdrawable USDC does not cover the difference, the buy gets the
  detail `cap_exceeded`, as before.
* A move that fails is never retried. Your next refused buy starts a new one.
  `lastTokenCashTransfer` on
  [`clearinghouseState`](/api/clearinghouse-state#token-cash) shows each move.
* A move that Mosaiq does not send within 5 minutes fails with reason
  `not_submitted`, and its amount stays in your USDC balance.
* While Mosaiq's moves are paused, or while too many other refusals start
  moves at the same time, the buy gets `temporarily_unavailable` with the detail
  `broker_capacity` and no `retryAfterMs`, and no move starts. `msg` is `moves between your USDC balance
  and token cash on hyperliquid are paused; retry shortly`. The perp order and
  the withdrawal below get the same answer, with their own status.

Mosaiq moves token cash back to your USDC balance in four cases. The first
two are refusals in the same way, with the same margin, never more than your
token cash. The last two move all your free token cash, and refuse nothing:

* A perp order or modify that your margin cannot cover, while your token cash
  covers the difference, gets the item error `temporarily_unavailable` with the
  detail `broker_capacity` and is not sent. `msg` is `token cash on hyperliquid is moving back to your USDC
  balance; retry shortly`. The difference is the initial margin that the order
  needs less your available margin. An order above your initial margin usage
  cap gets `limit_reached` with the detail `cap_exceeded` as before.
* A withdrawal above your withdrawable USDC, while your token cash covers the
  difference, gets HTTP `403`, `temporarily_unavailable` with the detail
  `broker_capacity`, the same message and `retryAfterMs`.
* When your equity falls below the initial margin of your perp positions, all
  your free token cash moves back, before a liquidation needs it. The move
  starts within seconds.
* Token cash that sees no activity for 24 hours moves back. A token buy refused
  for token cash and the end of a move count as activity.

```jsonc
{
  "status": "error",
  "code": "temporarily_unavailable",
  "detail": "broker_capacity",
  "msg": "token cash on hyperliquid is being funded from your USDC balance; retry shortly; retry in 5900 ms",
  "cloid": "0x0000000000000000000000000000a001",
  "retryAfterMs": 5900
}
```
