# Orders

## Build Order Calldata

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

### Request Body

| Field          | Type            | Required    | Description                                                                              |
| -------------- | --------------- | ----------- | ---------------------------------------------------------------------------------------- |
| `stockAddress` | string          | Yes         | Stock token contract address. Must be a valid EVM address.                               |
| `side`         | string          | Yes         | Order side. Enum: `Buy`, `Sell`.                                                         |
| `type`         | string          | Yes         | Order type. Enum: `Market`, `Limit`.                                                     |
| `quantity`     | string / number | Conditional | Quantity. Required for limit orders and market sell orders.                              |
| `notional`     | string / number | Conditional | Notional amount. Required for market buy orders.                                         |
| `price`        | string / number | Conditional | Limit price. Required for limit orders.                                                  |
| `timeInForce`  | string          | Conditional | Required for limit orders. Enum: `DAY`, `GTC`, `OPG`, `IOC`, `FOK`, `GTX`, `GTD`, `CLS`. |
| `deadline`     | number          | Yes         | Transaction deadline (Unix seconds). ≤ `4294967295`.                                     |

{% hint style="info" %}
Amount and quantity fields should use **strings** to avoid JavaScript number precision loss.
{% endhint %}

### Market Buy Example

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

### Limit Sell Example

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

### Response `data`

| Field         | Type   | Description                                   |
| ------------- | ------ | --------------------------------------------- |
| `chainId`     | number | Chain ID.                                     |
| `productType` | string | Product type.                                 |
| `toAddress`   | string | Router contract address.                      |
| `value`       | string | Native token amount. Currently returns `"0"`. |
| `callData`    | string | ABI-encoded calldata.                         |
| `method`      | string | `placeMarketOrder` or `placeLimitOrder`.      |

***

## One Click Delegated Order

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

Same body as `/orders/calldata`, plus:

| Field      | Type   | Required | Description                                            |
| ---------- | ------ | -------- | ------------------------------------------------------ |
| `gasLimit` | number | No       | Specified gas limit. Server estimates if empty or ≤ 0. |

**Prerequisites:** API Key must have `userAddress` configured. One Click must be enabled.

***

## Record Order TxHash

```
POST /api/v1/orders/tx
```

| Field    | Type   | Required | Description                              |
| -------- | ------ | -------- | ---------------------------------------- |
| `txHash` | string | Yes      | Transaction hash submitted to the chain. |

***

## Query Orders

### Order Mapping List

```
GET /api/v1/orders?page=1&limit=10
```

### Query by TxHash

```
GET /api/v1/orders/tx/{txHash}
```

### Query by Order ID

```
GET /api/v1/orders/{orderId}
```

`orderId` must belong to a transaction mapping recorded by the current API Key.

### Order Detail Fields

**openOrder:**

| Field           | Type   | Description               |
| --------------- | ------ | ------------------------- |
| `orderId`       | string | On-chain order ID.        |
| `userAddress`   | string | User address.             |
| `side`          | string | `Buy` or `Sell`.          |
| `type`          | string | `Market` or `Limit`.      |
| `tif`           | string | Time in force.            |
| `symbol`        | string | Symbol.                   |
| `placeNotional` | string | Order notional.           |
| `placeQuantity` | string | Order quantity.           |
| `pay`           | string | Payment amount.           |
| `placePrice`    | string | Order price.              |
| `status`        | string | `placing` or `canceling`. |

**historyOrder additional fields:**

| Field           | Type          | Description         |
| --------------- | ------------- | ------------------- |
| `settleTxHash`  | string / null | Settlement tx hash. |
| `settlePrice`   | string        | Execution price.    |
| `settlePay`     | string / null | Actual payment.     |
| `settleReceive` | string / null | Actual received.    |
| `mintFee`       | string        | Mint fee.           |
| `protocolFee`   | string        | Protocol fee.       |

***

## Cancel Limit Order

### Build Cancel Calldata

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

{% hint style="warning" %}
Path parameter `orderId` must be bytes32 hex (64 characters).
{% endhint %}

### One Click Delegated Cancel

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

Returns `uuid` and `txHash`.

### Cancel Prerequisites

* Order must belong to the current API Key
* Order must be in open status
* Only limit orders can be cancelled
* Order must not have a pending cancel request
* API Key's `userAddress` must match the order's user address


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anchored.finance/trading-api-docs-en/api-reference/orders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
