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

# Order Cancellation

> Understanding order cancellation strategies and best practices

## Cancel Order via WebSocket

To cancel orders on Rails platform, use the [WebSocket](/latest/perps/websocket-api/overview) API and subscribe to the [Order Creation Stream](/latest/perps/websocket-api/order-creation-stream).
The specifications and behavior remain the same.

## Order Cancellation Workflow

Order cancellation is done by submitting a [Cancel Order By ID](/latest/perps/websocket-api/order-creation-stream/cancel-order-by-id) request. You will receive two responses in sequence:

* **Acknowledgment**: Confirms the request was received and processing started
* **Confirmation**: Confirms the order was successfully cancelled

Key differences:

|                | Acknowledgment     | Confirmation      |
| -------------- | ------------------ | ----------------- |
| Body           | `cancelling order` | `order cancelled` |
| Order Status   | `cancelling`       | `cancelled`       |
| Status Code    | `202`              | `200`             |
| API Quota Used | Included           | Not included      |

Note that a unique `clientRequestId` can be used to correlate acknowledgment, confirmation, and any error responses.

## Order Status During Cancellation

Once the request is submitted, you will first receive a `cancelling` status, followed by a `cancelled` status. The key points are:

* `cancelling` means the cancel request has been accepted and the order is entering cancellation processing.
* Once an order is `cancelling`, it is excluded from future matching cycles.
* You can still receive fills after `cancelling` if they came from an in-progress matching cycle that started before the status changed.
* `cancelled` means cancellation is fully completed and the order is removed from the system.

## Cancellation via REST

While we recommend using the [Cancel Order By ID](/latest/perps/websocket-api/order-creation-stream/cancel-order-by-id) WebSocket request for faster, prioritized processing and clearer confirmations,
you can also use the [Cancel Orders](/latest/perps/rest-api/cancel-orders) REST endpoint to cancel orders in bulk.

A `200` response indicates your cancellation request was received and processing has begun; it does not guarantee that all targeted orders have been cancelled.

If you prefer the REST endpoint for convenience, here are reliable ways to verify that all orders were cancelled:

1. Call the endpoint again and confirm the response body includes `Cancelling 0 orders`.
2. Use [Get Open Orders](/latest/perps/rest-api/get-account-open-orders) to verify the orders are gone.
3. Include an optional `clientRequestId` query parameter in the REST call and subscribe to the [Order Creation](/latest/perps/websocket-api/order-creation-stream/overview) WebSocket for notifications (one per order). Each notification will include the same `clientRequestId` plus a suffix — for example, `0835bf3e-4a20-41f0-908d-8213f2b7a285#0` and `0835bf3e-4a20-41f0-908d-8213f2b7a285#1` for two orders, in no particular order.

## Priority of Cancellations

Order cancellations receive the highest priority in our system processing queue:

* Skip margin checks
* Bypass the standard queue to go directly to the matching engine
* Are prioritized over all other requests to ensure fast execution

This provides strong cancellation guarantees: if an order exists and can be cancelled, it will be cancelled as fast as possible regardless of system load. You may receive `404` responses if the order no longer exists (for example, already fully filled or previously cancelled).

## Status Transitions & Partial Fills

* Typical flow: `active` → `cancelling` → `cancelled`
* If the order had fills, `filledQuantity` and `avgFillPrice` may be present in confirmation responses
* Concurrent fills during cancellation are reflected in the final `filledQuantity`

## Conflict And Retry

If you receive a `409 Conflict` during cancellation, it indicates the order is in the process of being filled or cancelled at the time of the cancel request.
This is a transient state — implement a short backoff and retry the request until you receive either confirmation or a definitive error.
