> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pacifica.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel TWAP Order

> This endpoint allows users to cancel an open TWAP order.

```http theme={null}
POST /api/v1/orders/twap/cancel
```

Cancelling stops further sub-orders. Fills that already happened stay. The order's status becomes `cancelled`.

[Cancel all orders](https://docs.pacifica.fi/api-documentation/api/rest-api/orders/cancel-all-orders.md) also cancels TWAP orders in the markets it covers.

This endpoint cancels TWAP orders only. To cancel a TWAP order strategy, use [Cancel order strategy](https://docs.pacifica.fi/api-documentation/api/rest-api/order-strategies/cancel-order-strategy.md).

#### Operation Type (for Signing)

| Header Field | Type | Content |
| - | - | - |
| `"type"` | string | `"cancel_twap_order"` |

#### Request Body

<table><thead><tr><th width="188">Field</th><th width="98">Type</th><th width="95">Need</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>`"account"`</td><td>string</td><td>required</td><td>User's wallet address</td><td>`42trU9A5...`</td></tr><tr><td>`"signature"`</td><td>string</td><td>required</td><td>Cryptographic signature</td><td>`5j1Vy9Uq...`</td></tr><tr><td>`"timestamp"`</td><td>integer</td><td>required</td><td>Current timestamp in milliseconds</td><td>`1716200000000`</td></tr><tr><td>`"symbol"`</td><td>string</td><td>required</td><td>Trading pair symbol of the TWAP order</td><td>`BTC`</td></tr><tr><td>`"order_id"`</td><td>integer</td><td>required (if no CLOID)</td><td>TWAP order ID</td><td>`13753364`</td></tr><tr><td>`"client_order_id"`</td><td>Full UUID string</td><td>required (if no OID)</td><td>Client-defined order ID of the TWAP order</td><td>`f47ac10b-58cc-4372-a567-0e02b2c3d479`</td></tr><tr><td>`"agent_wallet"`</td><td>string</td><td>optional</td><td>Agent wallet address</td><td>`69trU9A5...`</td></tr><tr><td>`"expiry_window"`</td><td>integer</td><td>optional</td><td>Signature expiry in milliseconds</td><td>`30000`</td></tr></tbody></table>

If you send both `order_id` and `client_order_id`, Pacifica uses `client_order_id`.

```json theme={null}
{
  "account": "42trU9A5...",
  "signature": "5j1Vy9Uq...",
  "timestamp": 1716200000000,
  "symbol": "BTC",
  "order_id": 13753364,
  "agent_wallet": "69trU9A5...",
  "expiry_window": 30000
}
```

#### Response

* Status 200: Request accepted

```json theme={null}
  {
    "success": true,
    "data": null,
    "error": null,
    "code": null
  }
```

The response is the same when no open TWAP order has that `order_id`. To confirm the cancel, check `order_status` in [Get TWAP order history by ID](https://docs.pacifica.fi/api-documentation/api/rest-api/twap/get-twap-order-history-by-id.md).

* Status 400: Invalid request body
* Status 422: The engine rejected the request, for example because no open TWAP order has that `client_order_id`

```json theme={null}
  {
    "success": false,
    "data": null,
    "error": "TwapUnusedClientOrderId(f47ac10b-58cc-4372-a567-0e02b2c3d479)",
    "code": 0,
    "error_id": "unspecified"
  }
```

* Status 500: Internal server error

#### Code Example (Python)

```python theme={null}
import requests

payload = {
    "account": "42trU9A5...",
    "signature": "5j1Vy9Uq...",
    "timestamp": 1716200000000,
    "symbol": "BTC",
    "order_id": 13753364
}

response = requests.post(
    "/api/v1/orders/twap/cancel",
    json=payload,
    headers={"Content-Type": "application/json"}
)

data = response.json()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.