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

# Cancel Order

> [!NOTE]
>
> Mainnet currently supports Spot DEX only. Perpetuals, Oracle, Margin Trading, Lending, and Vaults are **Testnet-Only**. Use Testnet endpoints and assets for those products.

Canceling an ordinary Spot order releases its unused token escrow, reflected as lower `used` and
higher `free` on [Balances](https://docs.aultblockchain.com/dex-api/rest/balances.md) after processing. Perpetual cancellation releases
order-margin reservations. Margin Trading releases Lending collateral reservations and can apply
its configured cancel repayment; it does not necessarily return wallet funds or clear debt.

Cancellation is a signed transaction, like placement, using
`/ault.clob.v1.MsgCancelOrders`. The message is plural, so one transaction can cancel several orders
at once. See [Place or Modify Order](https://docs.aultblockchain.com/dex-api/trading/place-or-modify-order.md) for how orders reach the
chain.

## Identifying the Order

Cancel by the chain order id, or by the client order id if the order carried one. Both are available
from [Orders](https://docs.aultblockchain.com/dex-api/rest/orders.md) as `id` and `clientOrderId`, and from `orderUpdates` on
[Subscriptions](https://docs.aultblockchain.com/dex-api/websocket/subscriptions.md) as `oidHex` and `cloid`.

To list what is currently resting for one account before a bulk cancel:

```bash theme={null}
curl "https://am-api.cloud.aultblockchain.xyz/api/v1/orders?address=ault1...&status=open"
```

Follow every pagination page. This Spot read is not an inventory of all native Perpetual,
conditional (Testnet-Only), or TWAP state. Use [native order queries](https://docs.aultblockchain.com/dex-api/advanced/chain-queries.md#orders-and-order-book)
and [TWAP queries](https://docs.aultblockchain.com/dex-api/advanced/chain-queries.md#twap-parents) for those scopes.

## Batch Results

`MsgCancelOrders` takes explicit order IDs or client IDs and returns `succeeded` and `failed`
lists. A missing order can be reported as a failed item while other IDs succeed. Other validation
errors can reject the transaction, so inspect its committed code before interpreting the lists.
A successful transaction is not proof that every requested ID was canceled.

Cancellation and modification reject an order created in the current block. A quote just accepted
may need to reach the next block before it can be canceled. Reconcile the failure and current state
before retrying. Use [Trading Operations](https://docs.aultblockchain.com/dex-api/advanced/trading-operations.md#stop-quoting-and-remove-orders)
for a shutdown across several accounts and order families.

## Cancelling a TWAP Schedule

Cancel the **parent TWAP ID**, not merely a slice ID, through the native
`/ault.clob.v1.MsgCancelOrders` transaction. Python SDK 0.9 exposes the same route:

```python theme={null}
await client.clob_tx.cancel_orders(order_ids=[twap_id], wait=True)
```

`twap_id` is the parent's byte ID returned at placement. A committed parent cancellation removes
the parent and its schedule, stopping new slices. It does not cancel or reverse an already-created
slice or its fills; those follow their own order lifecycle. Slice IDs are not valid targets for
user cancellation or modification and can be reported as not found. Use the parent ID to stop the
schedule, then reconcile the slices already created.

Confirm the parent cancellation result and `TwapOrderClosed` event, then check the native
[TWAP queries](https://docs.aultblockchain.com/dex-api/advanced/chain-queries.md#twap-parents) and any already-created child orders.
A missing parent alone can also mean completion or expiry, so reconcile the close reason and fills.

## Racing a Fill

A cancellation is a transaction, ordered against every other transaction by the chain.

* If a match is processed first, the fill stands. An execution cannot be cancelled.
* A partially filled order cancels only its remaining quantity.
* An order that has already fully filled cannot be found to cancel.

> [!WARNING]
>
> An order-not-found error does not tell you why: the order may have filled, expired, been replaced,
> or already been canceled, or the query may address the wrong account. Reconcile it before retrying. Check
> [User Fills](https://docs.aultblockchain.com/dex-api/rest/user-fills.md) before assuming the exposure is gone.

## Cancels You Did Not Send

An order can leave the book without a cancellation from the account:

| Cause | Result |
| - | - |
| The order's deadline passed | The order expires |
| A modify reduces quantity to at or below the filled amount | The order is cancelled rather than resized |

Expiry arrives on the `user` channel as a `nonUserCancel` entry, which is currently emitted only for
expired orders. See [Subscriptions](https://docs.aultblockchain.com/dex-api/websocket/subscriptions.md).

> [!NOTE]
>
> Halting a market does not cancel anything. A halt rejects new orders, while resting orders keep
> their escrow until they fill, expire, or are cancelled by the account. Do not count on a halt to
> flatten exposure.

## Confirming

Check the released escrow on [Balances](https://docs.aultblockchain.com/dex-api/rest/balances.md) and the terminal state on
[Orders](https://docs.aultblockchain.com/dex-api/rest/orders.md). A cancelled order reports `status` as `canceled`, the same value an
expired order reports, so read `info.chain_status` to tell the two apart.


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