> For the complete documentation index, see [llms.txt](https://docs.zert.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zert.com/routing-engine-sdk/limit-orders.md).

# Limit Orders

Create, fetch, cancel, and list limit orders.

The Limit layer exposes:

* `POST /limit-orders/limit`
* `GET /limit-orders/limit/{limitOrderId}`
* `DELETE /limit-orders/limit/{limitOrderId}`
* `POST /limit-orders/limit/{limitOrderId}/replace`
* `GET /limit-orders/limits`

***

### Create limit order

#### `create`

Creates a limit order. You can pass an idempotency key via `requestConfig.headers` to make the request idempotent.

**Parameters**

* `body` (LimitOrderRequest, required): Limit order payload.
  * `timeInForce` (string, required): e.g. `GTC`
  * `minAmountOut` (string, required)
  * `fromChain` (string, required)
  * `toChain` (string, required)
  * `tokenIn` (string, required)
  * `tokenOut` (string, required)
  * `network` (string, required)
  * `amount` (string, required)
  * `slippageBps` (number, required)
  * `recipient` (string, required)
* `requestConfig` (object, optional): Request options.
  * `headers` (Record\<string, string>, optional): e.g. `{ 'Idempotency-Key': 'unique-key' }`.

**Returns**

A Promise that resolves to `LimitOrderCreateResponse`.

* `data.limitOrderId` (string): Limit order identifier.
* `data.status` (string): Order status.
* `data.expiresAtMs` (number): Expiry timestamp.
* `data.minAmountOut` (string): Minimum amount out.
* `meta.requestId` (string): Request identifier.
* `meta.timestamp` (string): Response timestamp.

```typescript
import { RoutingEngineSDK } from 'routing-engine-sdk';

const sdk = new RoutingEngineSDK({
  api: { apiKey: 'your-api-key' },
});

try {
  const response = await sdk.limit.create(
    {
      timeInForce: 'GTC',
      minAmountOut: '1',
      fromChain: 'arbitrum',
      toChain: 'avax',
      tokenIn: 'TBTC',
      tokenOut: 'WETH',
      network: 'mainnet',
      amount: '100.00',
      slippageBps: 75,
      recipient: '0x1234567890123456789012345678901234567890',
    },
    { headers: { 'Idempotency-Key': 'my-unique-key-123' } }
  );
  console.log('Limit order ID:', response.data.limitOrderId);
  console.log('Status:', response.data.status);
} catch (error) {
  console.error(error);
}
```

***

### Get limit order

#### `get`

Fetches a single limit order by ID.

**Parameters**

* `limitOrderId` (string, required): Limit order identifier.

**Returns**

A Promise that resolves to `LimitOrderResponse`.

* `data.limitOrderId` (string): Limit order ID.
* `data.status` (string): Order status.
* `data.timeInForce` (string): Time in force.
* `data.createdAtMs`, `data.updatedAtMs`, `data.expiresAtMs` (number): Timestamps.
* `data.minAmountOut` (string): Minimum amount out.
* `meta.requestId` (string): Request identifier.
* `meta.timestamp` (string): Response timestamp.

```typescript
const order = await sdk.limit.get('limit-order-123');
console.log(order.data.status, order.data.minAmountOut);
```

***

### Cancel limit order

#### `cancel`

Cancels a limit order. Optionally send a body with a cancellation reason.

**Parameters**

* `limitOrderId` (string, required): Limit order identifier.
* `body` (LimitOrderCancelBody, optional): Optional payload.
  * `reason` (string, optional): Cancellation reason.
* Note: Idempotency is handled via headers on the HTTP request path in the API spec.

**Returns**

A Promise that resolves to `LimitOrderCancelResponse`.

* `data.limitOrderId` (string): Limit order ID.
* `data.status` (string): `"canceled"`.
* `meta.requestId` (string): Request identifier.
* `meta.timestamp` (string): Response timestamp.

```typescript
await sdk.limit.cancel('limit-order-123');
// With reason:
await sdk.limit.cancel('limit-order-123', { reason: 'User requested cancel' });
```

***

### Replace limit order

#### `replace`

Replaces an open order (`POST /limit-orders/limit/{limitOrderId}/replace`).

**Parameters**

* `limitOrderId` (string, required)
* `body` (LimitOrderReplaceRequest, required): Same shape as `LimitOrderRequest`.
* `requestConfig` (object, optional): e.g. idempotency headers.

**Returns**

A Promise that resolves to `LimitOrderReplaceResponse`.

* `data.limitOrderId` (string): New order ID.
* `data.status` (string): Usually `open`.
* `data.expiresAtMs` (number)
* `data.minAmountOut` (string)
* `data.replacesLimitOrderId` (string): Original order ID.

```typescript
const replaced = await sdk.limit.replace(
  'limit-order-123',
  {
    timeInForce: 'GTC',
    minAmountOut: '1',
    fromChain: 'arbitrum',
    toChain: 'avax',
    tokenIn: 'TBTC',
    tokenOut: 'WETH',
    network: 'mainnet',
    amount: '100.00',
    slippageBps: 75,
    recipient: '0x1234567890123456789012345678901234567890',
  },
  { headers: { 'Idempotency-Key': 'replace-key-1' } }
);
console.log(replaced.data.replacesLimitOrderId, '->', replaced.data.limitOrderId);
```

***

### List limit orders

#### `list`

Lists limit orders for the authenticated owner with optional filters and pagination.

**Parameters**

* `params` (LimitOrdersListParams, optional): Query parameters.
  * `limit` (number, optional): Max number of orders to return.
  * `status` (string, optional): Filter by status.

**Returns**

A Promise that resolves to `LimitOrdersListResponse`.

* `data.limitOrders` (LimitOrderData\[]): Array of limit order objects (same shape as `get`).
* `meta.requestId` (string): Request identifier.
* `meta.timestamp` (string): Response timestamp.

```typescript
const list = await sdk.limit.list({ limit: 20, status: 'open' });
list.data.limitOrders.forEach((order) => {
  console.log(order.limitOrderId, order.status);
});
```

***

On HTTP or API-level errors (e.g. 400, 401), the client throws `RoutingEngineAPIError`. See Error Handling.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zert.com/routing-engine-sdk/limit-orders.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
