# Limit orders

Create, list, get, replace, and cancel off-chain limit orders. Public create and replace requests mirror the quote shape and add `minAmountOut` plus expiry controls.

## Prerequisites

* API key (header `Authorization: Bearer YOUR_API_KEY`)
* Base URL: `https://api.gateway.zert.com/api/v1`

## Step 1: Create a limit order

Call `POST /limit-orders/limit` with the quote-style fields `fromChain`, `toChain`, `tokenIn`, `tokenOut`, and `amount`, plus `minAmountOut`. Create requests require an `Idempotency-Key`.

```bash
curl -X POST 'https://api.gateway.zert.com/api/v1/limit-orders/limit' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Idempotency-Key: limit-create-001' \
  -d '{
    "timeInForce": "GTC",
    "minAmountOut": "1",
    "fromChain": "arbitrum",
    "toChain": "avax",
    "tokenIn": "TBTC",
    "tokenOut": "WETH",
    "network": "mainnet",
    "amount": "100.00",
    "slippageBps": 75,
    "recipient": "0x1234567890123456789012345678901234567890"
  }'
```

Response includes `data.limitOrderId`, `data.status`, `data.expiresAtMs`, and `data.minAmountOut`.

## Step 2: List your limit orders

Call `GET /limit-orders/limits` to list orders for the authenticated owner. Use query `limit` (1–200) and optional `status` (e.g. `open`, `canceled`).

```bash
curl -X GET 'https://api.gateway.zert.com/api/v1/limit-orders/limits?limit=20&status=open' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

## Step 3: Get or cancel a single order

* **Get:** `GET /limit-orders/limit/{limitOrderId}` — returns full order details.
* **Cancel:** `DELETE /limit-orders/limit/{limitOrderId}` — requires `Idempotency-Key`; optional body `{"reason": "..."}`.

```bash
# Get
curl -X GET 'https://api.gateway.zert.com/api/v1/limit-orders/limit/lim_abc123' \
  -H 'Authorization: Bearer YOUR_API_KEY'

# Cancel
curl -X DELETE 'https://api.gateway.zert.com/api/v1/limit-orders/limit/lim_abc123' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Idempotency-Key: limit-cancel-001' \
  -H 'Content-Type: application/json' \
  -d '{"reason": "user_request"}'
```

## Step 4: Replace an open order

Call `POST /limit-orders/limit/{limitOrderId}/replace` with the same request shape as create. Replacement requests also require `Idempotency-Key`.

```bash
curl -X POST 'https://api.gateway.zert.com/api/v1/limit-orders/limit/lim_abc123/replace' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Idempotency-Key: limit-replace-001' \
  -d '{
    "timeInForce": "GTC",
    "minAmountOut": "2",
    "fromChain": "arbitrum",
    "toChain": "avax",
    "tokenIn": "TBTC",
    "tokenOut": "WETH",
    "network": "mainnet",
    "amount": "100.00"
  }'
```

## Summary

| Step | Endpoint                                | Purpose                   |
| ---- | --------------------------------------- | ------------------------- |
| 1    | `POST /limit-orders/limit`              | Create limit order        |
| 2    | `GET /limit-orders/limits`              | List owner's limit orders |
| 3    | `GET /limit-orders/limit/{id}`          | Get one order             |
| 3    | `DELETE /limit-orders/limit/{id}`       | Cancel one order          |
| 4    | `POST /limit-orders/limit/{id}/replace` | Replace an open order     |

See [Create Limit Order](/api-reference/limit-orders/limit-order-create.md), [List Limit Orders](/api-reference/limit-orders/limit-orders-list.md), [Get or Cancel Limit Order](/api-reference/limit-orders/limit-order-get-cancel.md), and [Replace Limit Order](/api-reference/limit-orders/limit-order-replace.md) for full parameters and responses.


---

# 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.zert.com/integration-example/limit-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.
