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

# PlaceOrder

> Place a market, limit or stop order on a Hypernova account, attach a take-profit or stop-loss, and close a position safely with retries.

`PlaceOrder` · **write key** · **write** rate class

Places one order: open a position, add to one, close one, or protect one with a take-profit or stop-loss.

## Body

| Field | Type | Description |
| - | - | - |
| `accountId` *required* | string | The account to trade on. |
| `clientOrderId` *required* | string | A UUID you mint for each order. It becomes the `orderId` and makes a retry safe. See [Retrying safely](#retrying-safely). |
| `symbol` *required* | string | Market symbol, exactly as ListMarkets lists it. |
| `type` *required* | OrderType | MARKET, LIMIT, STOP\_MARKET, TAKE\_PROFIT or STOP\_LOSS. |
| `side` *required* | OrderSide | Buy or sell. |
| `quantity` *required* | decimal | Size in the market's own unit, such as `"0.01"` BTC: a multiple of `lotSize` and at least it. An order other than a reduce-only order, take-profit or stop-loss may also need to be worth at least \$10: see [Limits](#limits). |
| `price` *optional* | decimal | Required for LIMIT. |
| `triggerPrice` *optional* | decimal | Required for STOP\_MARKET, TAKE\_PROFIT and STOP\_LOSS. |
| `reduceOnly` *optional* | boolean | Only shrink a position. Needs `positionId`, or answers `invalid_argument`. |
| `positionId` *optional* | string | The position to close or protect. Required for TAKE\_PROFIT, STOP\_LOSS and reduce-only orders. |
| `takeProfitPrice`, `stopLossPrice` *optional* | decimal | Exits attached to a MARKET or LIMIT order that opens a position. |
| `maxSlippageBps` *optional* | decimal | MARKET only: how far from the best bid or ask the fill may go, in basis points (`"50"` is 0.5%). Leave out for no cap. |

Every price, trigger, take-profit and stop-loss must be a multiple of the market's `tickSize` from [ListMarkets](https://hypernova.xyz/docs/api/accounts.md#listmarkets).

```json theme={null}
{ "accountId": "…", "clientOrderId": "7d3f1c2a-9b4e-4f6a-8c1d-2e3f4a5b6c7d", "symbol": "BTC", "type": "ORDER_TYPE_MARKET", "side": "ORDER_SIDE_BUY", "quantity": "0.01" }
```

## Response

| Field | Type | Description |
| - | - | - |
| `orderId` | string | Your `clientOrderId`, in lower case. |
| `status` | OrderStatus | OPEN for an order that rests or waits for its trigger, FILLED for one that filled at once. A retry answers the status now, except that an order since rejected answers `failed_precondition` with its reason, and a reduce-only MARKET that found the position gone answers `POSITION_ALREADY_CLOSED`. |
| `acceptedQuantity` *optional* | decimal | Sent only when less than requested was placed: a reduce-only order trimmed to the position, or a fill sized down to book liquidity. |
| `positionId` *optional* | string | The position the order filled against: the one to attach exits to; after a flip, the new position; after a full close, the closed one. |
| `averageFillPrice` *optional* | decimal | The price the order's fills were booked at. |
| `filledQuantity` *optional* | decimal | What actually filled, less than `quantity` when book liquidity sized the fill down. |
| `fee` *optional* | decimal | The total fee across the order's fills. |

```json theme={null}
{ "orderId": "7d3f1c2a-9b4e-4f6a-8c1d-2e3f4a5b6c7d", "status": "ORDER_STATUS_FILLED", "positionId": "019f8b1c-0d2e-7f31-a4b5-c6d7e8f90a1b", "averageFillPrice": "100012.4", "filledQuantity": "0.01", "fee": "0.4000496" }
```

The last four are sent for an order that fills during the call, a MARKET or a LIMIT that crosses the book.
They carry at most 8 decimal places. ListTrades has the price, quantity, fee and position of each recorded trade, and ListOrderHistory has the fill price once it is recorded on the order.
A resting order answers none of them; once it fills, a retry with its `clientOrderId` answers all four, omitting them until that fill's trades are recorded.

## Retrying safely

> [!WARNING]
>
> After a timeout, a 500 or a lost connection, the order may still have gone through. Retry only with the `clientOrderId` the first attempt carried: you get the first order back and nothing new is placed.

* Any RFC 9562 UUID version is accepted, in the 36-character hyphenated form, and will stay accepted, so a version 8 UUID that packs your own id works.
* The same `clientOrderId` with a different order answers `failed_precondition`, except a retry that only asks for a larger quantity, which can still answer the first order, with `acceptedQuantity` when the stored quantity is smaller than the retry asked for.
* `maxSlippageBps` is not compared: a retry answers the first order's execution whatever cap it carries, so a tighter cap on a retry neither reprices nor refuses a fill that already happened. Repeat the first attempt's parameters.
* A `clientOrderId` that already names an order on another account answers `already_exists`.

## Order types

### MARKET

* Fills against the book. A fill that would move past `maxSlippageBps` refuses the whole order with `failed_precondition` before any of it executes.
* `maxSlippageBps` is accepted on a MARKET order that opens or adds to a position and on a reduce-only MARKET, and refused on every other type, so an exit that rests or waits for a trigger is never price-capped.
* In the default one-way position mode, a MARKET order without `reduceOnly`, `takeProfitPrice` or `stopLossPrice`, opposite an open position that is not a pair leg, no larger than it and naming no other `positionId`, is placed as that position's reduce-only exit: it fills the visible depth instead of being refused for its size (`maxSlippageBps` still applies), `acceptedQuantity` gives the size filled, and it is listed with `reduceOnly` and the `positionId`.
* If the position or the mode cannot be read at that moment, the order is placed as an ordinary opening order instead, and if the position has closed meanwhile it opens one on the other side. For an exit that can never open a position, send `reduceOnly: true` with the `positionId`, or call [ClosePosition](https://hypernova.xyz/docs/api/cancel-orders.md#closeposition).

### LIMIT

* A LIMIT that crosses the book fills at once, as taker, at the book's average price.
* A crossing LIMIT without `reduceOnly`, even one opposite a position, is refused with `failed_precondition` when the visible depth is short of its size, or when that average is worse than its limit price by more than a tolerance, 10 basis points today.
* A LIMIT without `reduceOnly` is sized at its limit price, however far through the book: quantity × `price` must fit `maxPositionSize`, and attached exits must sit on the right side of `price`, or it answers `invalid_argument`.
* A LIMIT priced not to cross usually rests, but the market can move first, so it can still fill as taker. Only `postOnly` would guarantee a maker order, and PlaceOrder does not accept it.

> [!WARNING]
>
> **A reduce-only LIMIT that crosses has no price bound**: it fills the visible depth however far past its limit. To cap an exit's price, send a reduce-only MARKET with `maxSlippageBps` instead.

### Triggered orders

* STOP\_MARKET, TAKE\_PROFIT and STOP\_LOSS fire when the mark price or the best bid or offer on their executing side reaches `triggerPrice`, whichever comes first.
* A `triggerPrice` that the mark price or that best bid or offer has already reached answers `invalid_argument`, and the message names the price it had to be beyond. A stop refused this way means its level is already hit, so close at market instead of retrying the stop.
* A take-profit or stop-loss on an open position is TAKE\_PROFIT or STOP\_LOSS with its `positionId` and `triggerPrice`.
* Exits attached with `takeProfitPrice` and `stopLossPrice` appear only as fields on the opening order until it fills, then become separate TAKE\_PROFIT and STOP\_LOSS orders with their own ids. Find them in [ListOpenOrders](https://hypernova.xyz/docs/api/orders.md#listopenorders) by `positionId` and `type`.

### Markets with a fill cap

On markets whose fills are capped near the mark price, today BRENTOIL, CL, GOLD, SILVER, SP500 and XYZ100, size the book cannot fill within the cap fills at the cap price, so depth neither refuses nor cuts a LIMIT there.
While the cap cannot be set, as when the mark price is stale or far from the book, a MARKET or crossing LIMIT without `reduceOnly` there is refused with `failed_precondition` and can be retried a moment later; a reduce-only one fills the visible depth, and a triggered STOP\_MARKET fills uncapped.

## Exits

* To close or reduce a position, send `reduceOnly: true` with its `positionId`, the position's `symbol`, the opposite side and the quantity to close. A take-profit or stop-loss names the same symbol and side.
* A reduce-only MARKET larger than the position is trimmed to it, so it closes the whole position unless book liquidity sizes it down. [ClosePosition](https://hypernova.xyz/docs/api/cancel-orders.md#closeposition) does the same without a quantity, on the exit budget.
* Reduce-only LIMITs, take-profits and stop-losses each form their own ladder: one kind together covers at most the position's size, and the one closest to the market fills first.
* A new exit closer to the market than one of its kind shrinks or cancels the farther one, with no error. One lying wholly beyond what its ladder covers answers `failed_precondition`, kind `REDUCE_ONLY_NO_CAPACITY`. A reduce-only STOP\_MARKET never uses ladder capacity.
* An exit listed with `closePosition`, as the one an entry attaches with `stopLossPrice` or `takeProfitPrice` can be, covers the whole position and sits outside its ladder. A sized exit of the same kind placed farther from the market than it succeeds, and moves that protection: the whole-position order is cancelled and placed again under a new `orderId`, sized at the position less the sized exits, and your new order becomes the whole-position exit, listed with `closePosition`. On a 1 BTC long with an attached stop at 45,000, a 0.3 BTC stop at 44,000 leaves 0.7 BTC stopped at 45,000 and makes 44,000 the stop for whatever remains. When your new exit and the other sized exits already cover the whole position, nothing replaces the whole-position order: a 1 BTC stop at 44,000 on that long leaves it stopped at 44,000 only, so a full-size backup stop placed farther out removes the nearer one. Read ListOpenOrders after placing an exit to see what now protects the position.
* When the position closes, its reduce-only orders are cancelled, and a partial close shrinks any that would exceed what remains.
* An exit on a position that has already closed, as when two closes race, answers `failed_precondition`, kind `POSITION_ALREADY_CLOSED`: treat the close as done.
* An exit on a leg of a pair trade answers `failed_precondition`: a pair closes as a pair, in the app or through CloseAllPositions.

## Limits

An account is limited to 300 resting orders that open or add to a position, untriggered stops included.
One more answers `failed_precondition`, kind `TOO_MANY_OPEN_ORDERS`, until one fills or is cancelled; reduce-only orders, take-profits and stop-losses do not count.

An account may separately be limited to 300 resting reduce-only orders, take-profits and stop-losses.
One more answers the same code and kind, and so does an order that attaches `takeProfitPrice` or `stopLossPrice`. The message tells the two limits apart, beginning `too many open orders` or `too many open exit orders`, and says how many to cancel.
The exits an entry attaches are still created when it fills, so an account can hold more than 300, and a reduce-only MARKET is never refused for either limit, so a position can always be closed.

An order may also be refused with `invalid_argument` when it is worth less than \$10, on every market.
A LIMIT is valued at its `price`, a STOP\_MARKET at its `triggerPrice` and a MARKET at the price it would fill at.
Reduce-only orders, take-profits, stop-losses and a MARKET placed as a position's reduce-only exit are never refused for it. A LIMIT or STOP\_MARKET without `reduceOnly` is measured even when it would only reduce a position, so send a small exit with `reduceOnly: true`.

## Examples

| Goal | Body after `accountId` and `clientOrderId` |
| - | - |
| Market buy capped at 0.5% | `"symbol":"BTC","type":"ORDER_TYPE_MARKET","side":"ORDER_SIDE_BUY","quantity":"0.01","maxSlippageBps":"50"` |
| Limit buy with take-profit and stop-loss | `"symbol":"BTC","type":"ORDER_TYPE_LIMIT","side":"ORDER_SIDE_BUY","quantity":"0.01","price":"95000","takeProfitPrice":"105000","stopLossPrice":"92000"` |
| Stop-market breakout entry | `"symbol":"BTC","type":"ORDER_TYPE_STOP_MARKET","side":"ORDER_SIDE_BUY","quantity":"0.01","triggerPrice":"108000"` |
| Take-profit on a long | `"symbol":"BTC","type":"ORDER_TYPE_TAKE_PROFIT","side":"ORDER_SIDE_SELL","quantity":"0.01","positionId":"…","triggerPrice":"110000"` |
| Stop-loss on a long | `"symbol":"BTC","type":"ORDER_TYPE_STOP_LOSS","side":"ORDER_SIDE_SELL","quantity":"0.01","positionId":"…","triggerPrice":"90000"` |
| Close part of a long, capped at 0.5% | `"symbol":"BTC","type":"ORDER_TYPE_MARKET","side":"ORDER_SIDE_SELL","quantity":"0.01","reduceOnly":true,"positionId":"…","maxSlippageBps":"50"` |
| Close all of a long without reading its size | Call [ClosePosition](https://hypernova.xyz/docs/api/cancel-orders.md#closeposition), which takes no quantity. A reduce-only MARKET closes at most the `quantity` it names, so a large guess can still leave part of a position open. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.