# Cancel an Order — Gasless

## Cancel an Order — Gasless

Gasless cancellation works by revoking the Operator's willingness to co-sign a specific order. Because every fill requires a fresh Operator signature, stopping that signature effectively blocks the order from being filled — no on-chain transaction needed.

**Wait time:** Up to 5 minutes if the Operator recently signed the order for an in-flight fill. If the order is far from market price, cancellation is near-instant.

{% hint style="info" %}
For immediate cancellation without any wait, use Hard Cancel and pay a small gas fee.
{% endhint %}

{% hint style="success" %}
**Full demo:** [github.com/KyberNetwork/ks-limit-order-API-demo](https://github.com/KyberNetwork/ks-limit-order-API-demo)
{% endhint %}

### Flow

```
GET /orders  →  POST /cancel-sign  →  sign EIP-712  →  POST /cancel
```

### Step 1 — Get Active Orders

Query your active orders to find the `orderId` to cancel:

```typescript
const { data } = await axios.get(
    "https://limit-order.kyberswap.com/read-ks/api/v1/orders",
    { params: { chainId: 137, maker: signerAddress, status: "active" } }
);

const targetOrderId = data.data[0].id;
```

### Step 2 — Get the Unsigned EIP-712 Cancel Message

Pass one or more `orderIds` to cancel in a single signature:

```typescript
const requestBody = {
    chainId: "137",
    maker: signerAddress,
    orderIds: [targetOrderId]   // can include multiple IDs
};

const { data: cancelData } = await axios.post(
    "https://limit-order.kyberswap.com/write/api/v1/orders/cancel-sign",
    requestBody
);
// cancelData contains: domain, types, message
```

### Step 3 — Sign the Cancel Message

```typescript
const signature = await signer.signTypedData(
    cancelData.domain,
    { CancelOrder: cancelData.types.CancelOrder },
    cancelData.message
);
```

### Step 4 — Submit the Gasless Cancel

```typescript
const signedBody = {
    ...requestBody,
    signature: signature
};

const { data: result } = await axios.post(
    "https://limit-order.kyberswap.com/write/api/v1/orders/cancel",
    signedBody,
    { headers: { Origin: "https://kyberswap.com" } }
);

// result contains: cancelledOrderIds, operatorSignatureExpiry (if recently signed)
console.log("Cancelled:", result.data);
```

The response includes an `operatorSignatureExpiry` timestamp if the Operator had recently signed the order. The order will be fully cancelled once that timestamp passes (max 5 minutes).

### Related

* [Cancel an Order — Hard Cancel](/developer-guide/limit-order-api/how-to-guides/cancel-an-order-hard-cancel.md)
* [POST /write/api/v1/orders/cancel-sign](/developer-guide/limit-order-api/api-reference/maker-api.md#post-write-api-v1-orders-cancel-sign)
* [POST /write/api/v1/orders/cancel](/developer-guide/limit-order-api/api-reference/maker-api.md#post-write-api-v1-orders-cancel)


---

# 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.kyberswap.com/developer-guide/limit-order-api/how-to-guides/cancel-an-order-gasless.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.
