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

# Cancel an order

> Permissions required: **Execute trades**

Requests cancellation of an order.

Cancellation is asynchronous: a successful response means the
cancel request was accepted, and only the order ID and external
ID are returned. The order moves to status `CANCELING`, and once
the cancellation is confirmed, to `CANCELED` (nothing was
executed) or `PARTIALLY_CANCELED` (partially executed before
cancellation; the filled portion stands). Use the order lookup
endpoint to observe the cancellation state.

Canceling an order that is already in `CANCELING` is
idempotent: the request succeeds again.

Orders that cannot be canceled are rejected with 409
`ORDER_NOT_CANCELABLE`. This includes orders already in a terminal
state (`FILLED`, `CANCELED`, `PARTIALLY_CANCELED`, `EXPIRED`,
`REJECTED`) and orders that execute immediately (`FOK` and `IOC`,
including all `MARKET` orders).

Rejections. A request that passes schema validation but breaks a
business rule returns the listed status with a `message` of the
form `<rejectCode>: <detail>`, where `<rejectCode>` is one of the
`rejectCode` values of the Order schema. A request that fails
schema validation, such as a malformed field, returns 400 with
the validator's message and no code.
An unknown order, or one not visible through the given
`accountId`, returns 404 with the message `order not found` and
no code.



## OpenAPI

````yaml /knowledge-base/openapi/v4.yaml post /accounts/{accountId}/orders/{orderId}/cancel
openapi: 3.1.0
info:
  title: Anchorage Digital Account APIs (v4)
  version: 4.0.0-beta
  description: >-
    Reference for the Anchorage Digital v4 API, the surface behind Crypto as a
    Service: account management (accounts and the account tree, beneficiaries,
    freeze/unfreeze/close), balances and transactions, trusted destinations,
    orders and allocations, withdrawals, deposit instructions, deposit
    attributions, the policy engine (policies, approval keys), and supported
    asset types. Approval groups, endorsements, compliance profiles, customers
    (onboarding), fee configuration updates, interest enrollment, funding
    allocations, and destination removal are under construction and return
    mocked data only.


    Status: BETA. The v4 API is available in the sandbox only
    (https://api.anchorage-staging.com/v4) and is not available in production
    yet. The contract may change until general availability. Which endpoints are
    live, in final testing, or under construction:
    https://docs.anchorage.com/platform/developers/caas/caas-overview


    Authentication: every request carries an `Api-Access-Key` header. Every
    POST, PATCH, and DELETE additionally requires an `Idempotency-Key`, and is
    signed with `Api-Signature` (hex-encoded Ed25519 over
    `timestamp_epoch_seconds + uppercase(http_method) + request_path +
    request_body`) plus `Api-Timestamp` (unix epoch seconds).


    Pagination: list endpoints accept `after` (cursor) and `limit` (page size, 1
    to 1000, default 100) and return a `page.endCursor` to continue from. Errors
    use a common envelope with a human-readable `message`; batch endpoints
    return a result per item instead.


    Guides: https://docs.anchorage.com/platform/developers/caas/caas-overview
servers:
  - url: https://api.anchorage-staging.com/v4
security:
  - Api-Access-Key: []
tags:
  - name: Accounts
  - name: Compliance Profiles
  - name: Balances
  - name: Transactions
  - name: Trusted Destinations
  - name: Orders & Allocations
  - name: Withdrawals
  - name: Deposit Instructions
  - name: Deposit Attributions
  - name: Policies
  - name: Approval Groups
  - name: Endorsements
  - name: Customers
  - name: Asset Types
paths:
  /accounts/{accountId}/orders/{orderId}/cancel:
    post:
      tags:
        - Orders & Allocations
      summary: Cancel an order
      description: |-
        Permissions required: **Execute trades**

        Requests cancellation of an order.

        Cancellation is asynchronous: a successful response means the
        cancel request was accepted, and only the order ID and external
        ID are returned. The order moves to status `CANCELING`, and once
        the cancellation is confirmed, to `CANCELED` (nothing was
        executed) or `PARTIALLY_CANCELED` (partially executed before
        cancellation; the filled portion stands). Use the order lookup
        endpoint to observe the cancellation state.

        Canceling an order that is already in `CANCELING` is
        idempotent: the request succeeds again.

        Orders that cannot be canceled are rejected with 409
        `ORDER_NOT_CANCELABLE`. This includes orders already in a terminal
        state (`FILLED`, `CANCELED`, `PARTIALLY_CANCELED`, `EXPIRED`,
        `REJECTED`) and orders that execute immediately (`FOK` and `IOC`,
        including all `MARKET` orders).

        Rejections. A request that passes schema validation but breaks a
        business rule returns the listed status with a `message` of the
        form `<rejectCode>: <detail>`, where `<rejectCode>` is one of the
        `rejectCode` values of the Order schema. A request that fails
        schema validation, such as a malformed field, returns 400 with
        the validator's message and no code.
        An unknown order, or one not visible through the given
        `accountId`, returns 404 with the message `order not found` and
        no code.
      operationId: cancelOrder
      parameters:
        - name: accountId
          in: path
          schema:
            type: string
            format: uuid
            example: 3486b413-93d3-4447-afce-2b9c9dc34a32
          required: true
          description: >-
            Account ID or subaccount ID (a UUID) the order was placed with.
            Unlike lookup, cancellation is not available through a subaccount
            the order was merely allocated to, since canceling affects the
            entire order.
        - name: orderId
          in: path
          schema:
            type: string
            format: uuid
            example: 3486b413-93d3-4447-afce-2b9c9dc34a32
          required: true
          description: The order ID (a UUID) returned when the order was placed.
        - name: Idempotency-Key
          in: header
          schema:
            type: string
          required: true
          description: >-
            Client-supplied key that deduplicates retried requests. Reusing a
            key returns the original result instead of repeating the action.
        - name: Api-Signature
          in: header
          required: true
          schema:
            type: string
            pattern: ^[0-9A-Fa-f]{128,160}$
          description: >-
            A hex-encoded Ed25519 signature of `timestamp_epoch_seconds +
            uppercase(http_method) + request_path + request_body`.
        - name: Api-Timestamp
          in: header
          required: true
          schema:
            type: integer
            format: int64
          description: Current timestamp, represented as unix epoch seconds
      responses:
        '200':
          description: >-
            Cancel request accepted. Only the order ID and external ID are
            returned; the client is expected to look up the order's cancellation
            state via the order lookup endpoint.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelOrderResponse'
              examples:
                cancelAccepted:
                  summary: Cancel request accepted
                  value:
                    data:
                      id: f47ac10b-58cc-4372-a567-0e02b2c3d479
                      externalId: 9d2c6a1e-4f7b-4c3d-8e5a-1b2c3d4e5f6a
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
        '401':
          description: Unauthenticated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetails'
components:
  schemas:
    CancelOrderResponse:
      title: Cancel Order Response
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/CancelOrderResult'
    ErrorDetails:
      title: ErrorDetails
      type: object
      properties:
        message:
          description: A human-readable message providing more details about the error.
          example: Missing required field 'amount'.
          type: string
      required:
        - message
    CancelOrderResult:
      title: Cancel Order Result
      type: object
      required:
        - id
      properties:
        id:
          description: >-
            Order ID of the order the cancel request applies to. Use this to
            look up the order's cancellation state via the order lookup
            endpoint.
          type: string
          format: uuid
          example: 3486b413-93d3-4447-afce-2b9c9dc34a32
        externalId:
          type: string
          description: External ID the order was placed with.
  securitySchemes:
    Api-Access-Key:
      type: apiKey
      name: Api-Access-Key
      in: header
      description: An API key associated with a security role

````

## Related topics

- [Orders](https://docs.anchorage.com/knowledge-base/platform/developers/caas/caas-orders.md)
- [Submitting orders](https://docs.anchorage.com/knowledge-base/platform/developers/trading/websocket-submit-order.md)
- [Cancel an async order](https://docs.anchorage.com/knowledge-base/porto/api-reference/v2/trading/cancel-an-async-order.md)
- [Place an async order](https://docs.anchorage.com/knowledge-base/porto/api-reference/v2/trading/place-an-async-order.md)
