> For the complete documentation index, see [llms.txt](https://docs.anchored.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anchored.finance/trading-api/trading/place-and-cancel-orders.md).

# Place & Cancel Orders

## Build order calldata

```
POST /api/v1/orders/calldata
```

| Field          | Type            | Required    | Description                                                                                                                                                                                                                                                  |
| -------------- | --------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `stockAddress` | string          | Yes         | Stock token address (EVM).                                                                                                                                                                                                                                   |
| `side`         | string          | Yes         | `Buy` or `Sell`.                                                                                                                                                                                                                                             |
| `type`         | string          | Yes         | `Market` or `Limit`.                                                                                                                                                                                                                                         |
| `quantity`     | string / number | Conditional | Limit orders; market sells.                                                                                                                                                                                                                                  |
| `notional`     | string / number | Conditional | Market buys.                                                                                                                                                                                                                                                 |
| `price`        | string / number | Conditional | Limit orders.                                                                                                                                                                                                                                                |
| `timeInForce`  | string          | Conditional | Limit orders. See [enums](/trading-api/reference/enums.md).                                                                                                                                                                                                  |
| `deadline`     | number          | Yes         | Tx deadline (Unix seconds).                                                                                                                                                                                                                                  |
| `deferred`     | boolean         | No          | Deferred sell (sell-before-holding, debt-creating). Only valid with `side: Sell` and requires a whitelisted address. Routes to `deferredLimitSell`/`deferredMarketSell`. See [deferred-sell.md](/trading-api/trading/deferred-sell.md). Defaults to `false`. |

### Market buy

```json
{
  "stockAddress": "0x0000000000000000000000000000000000000001",
  "side": "Buy",
  "type": "Market",
  "notional": "10",
  "deadline": 1893456000
}
```

### Limit sell

```json
{
  "stockAddress": "0x0000000000000000000000000000000000000001",
  "side": "Sell",
  "type": "Limit",
  "quantity": "1.25",
  "price": "180.50",
  "timeInForce": "DAY",
  "deadline": 1893456000
}
```

### Limit buy

```json
{
  "stockAddress": "0x0000000000000000000000000000000000000001",
  "side": "Buy",
  "type": "Limit",
  "quantity": "0.05",
  "price": "180.50",
  "timeInForce": "DAY",
  "deadline": 1893456000
}
```

> Limit orders (**buy and sell**) use `quantity` + `price`; `notional` is only for **market buys**. Production limit orders accept only `timeInForce: "DAY"` — other values revert on-chain. **Market orders are accepted only during the regular US trading session.** Pre-market, after-hours, overnight and closed sessions reject with `market order is only supported during the regular trading session (current: <session>)`. This is enforced when building calldata, so it applies to both `/calldata` (self-submit) and `/send` (One Click). Use limit orders outside regular hours.

Response `data`:

| Field         | Type   | Description                              |
| ------------- | ------ | ---------------------------------------- |
| `chainId`     | number | Chain ID.                                |
| `productType` | string | Product type.                            |
| `toAddress`   | string | Router address.                          |
| `value`       | string | Native value (`"0"`).                    |
| `callData`    | string | Encoded calldata.                        |
| `method`      | string | `placeMarketOrder` or `placeLimitOrder`. |

Submit `toAddress` + `callData` on-chain, then record via [order-status-and-history.md](/trading-api/trading/order-status-and-history.md).

## One Click place order

```
POST /api/v1/orders/send
```

Same body as `/calldata`, plus optional `gasLimit` (set a buffer — the API broadcasts through `OneClickRouter` and pays gas). Requires One Click enabled and API key `userAddress` configured.

The response is the **order-tx mapping**, not calldata: `{ id, chainId, productType, operationType, orderId, txHash, status, ... }`. `orderId` is `null` until the indexer backfills it — poll `GET /orders/tx/{txHash}` or `GET /orders/{orderId}` (once populated).

## Build Order-With-Deposit Calldata

```
POST /api/v1/orders/with-deposit/calldata
```

Use this endpoint when the order transaction should also use `StockRouter` as the approved spender before placing the order. For buys, `StockRouter` transfers the cash token to `Cashier`; for sells, it transfers the stock token to `Stock`.

| Field                 | Type            | Required    | Description                                                                                                |
| --------------------- | --------------- | ----------- | ---------------------------------------------------------------------------------------------------------- |
| `stockAddress`        | string          | Yes         | Stock token address.                                                                                       |
| `depositAmount`       | string / number | Yes         | Human-readable deposit amount. For buys, this is cash token amount. For sells, this is stock token amount. |
| `depositTokenAddress` | string          | Conditional | Cash token address. Required for buy orders.                                                               |
| `side`                | string          | Yes         | `Buy` or `Sell`.                                                                                           |
| `type`                | string          | Yes         | `Market` or `Limit`.                                                                                       |
| `quantity`            | string / number | Conditional | Limit orders; market sells.                                                                                |
| `notional`            | string / number | Conditional | Market buys.                                                                                               |
| `price`               | string / number | Conditional | Limit orders.                                                                                              |
| `timeInForce`         | string          | Conditional | Limit orders.                                                                                              |
| `deadline`            | number          | Yes         | Tx deadline (Unix seconds).                                                                                |

For buy orders, the cash token must be approved for `StockRouter`, and the cash deposit must be eligible for instant deposit; otherwise the combined transaction reverts. For sell orders, the wallet stock token must be approved for `StockRouter`.

### Market buy with deposit

```json
{
  "stockAddress": "0x0000000000000000000000000000000000000001",
  "depositTokenAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "depositAmount": "100",
  "side": "Buy",
  "type": "Market",
  "notional": "10",
  "deadline": 1893456000
}
```

### Market sell with stock deposit

```json
{
  "stockAddress": "0x0000000000000000000000000000000000000001",
  "depositAmount": "1.25",
  "side": "Sell",
  "type": "Market",
  "quantity": "1.25",
  "deadline": 1893456000
}
```

## One Click Order With Deposit

```
POST /api/v1/orders/with-deposit/send
```

Same body as `/with-deposit/calldata`, plus optional `gasLimit`. Requires One Click enabled and API key `userAddress` configured.

## Cancel limit order

### Self-submit cancel calldata

```
DELETE /api/v1/orders/{orderId}/calldata?deadline=1893456000
```

> Use the `orderId` **exactly as returned by the API** — a `0x`-prefixed 32-byte hex string (66 characters), e.g. `0x00000000000049fb0001000049d0d92daa26b7f121276e7034af17aed9e4c71e`. Put it in the path as-is: `DELETE /api/v1/orders/0x00000000000049fb0001000049d0d92daa26b7f121276e7034af17aed9e4c71e/calldata?deadline=1893456000`

### One Click cancel

```
DELETE /api/v1/orders/{orderId}/send?deadline=1893456000
```

Returns `uuid` and `txHash`.

### Cancel rules

* Order belongs to current API key
* Order is open
* Limit orders only
* No pending cancel in flight
* API key `userAddress` matches order user
