> ## 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.

# Cancel All Orders

> Queue a cancel for every open order, or every open order in one contract.

The same sweep is available over WebSocket as `cancelAllOrders` on the [Order Management Stream](/latest/options/websocket-api/order-management-stream), so capital can be released from whichever connection is still up. See [Releasing Capital on Disconnect](/latest/websocket-session#releasing-capital-on-disconnect) for when to use which.


## OpenAPI

````yaml POST /v1/matching/orders/cancel-all
openapi: 3.1.0
info:
  title: Options Matching API
  version: 1.0.0
  description: >-
    Order management endpoints for Rails Options. Base URLs vary by environment
    — see the Environments page. Authorize with the access token obtained from
    the Auth API.
servers:
  - url: https://api-options.sandbox.rails.xyz
security:
  - bearerAuth: []
paths:
  /v1/matching/orders/cancel-all:
    post:
      summary: Cancel All Orders
      description: >-
        Cancels every open order of the caller, or only those in one contract.
        Each queued cancel settles on its own. See [Order
        Lifecycle](/latest/options/guides/order-lifecycle#placing-orders-over-http).
      operationId: cancelAllOptionsOrders
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelAllOrdersRequest'
            example:
              clientRequestId: c0a0d2d0-6b1e-4f3a-8d2b-5e7f9a1b2c3d
              contract: BTC-7FEB26-100000-C
      responses:
        '202':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelAllOrdersQueued'
              example:
                action: cancelAll
                clientRequestId: c0a0d2d0-6b1e-4f3a-8d2b-5e7f9a1b2c3d
                contract: BTC-7FEB26-100000-C
                count: 2
                cancels:
                  - queued: true
                    accepted: false
                    body: order queued, pending acceptance
                    action: cancel
                    messageId: 1770000000000-0
                    clientRequestId: 2b6c8e1a-0d4f-4e7b-9c3a-1f5d7e9b0a2c
                    contract: BTC-7FEB26-100000-C
                    orderId: 01JRQM8H5XYZABCDEFGHJKMNPQ
                  - queued: true
                    accepted: false
                    body: order queued, pending acceptance
                    action: cancel
                    messageId: 1770000000000-1
                    clientRequestId: 7d3e5f1b-2a4c-4b6d-8e0f-9a1b3c5d7e9f
                    contract: BTC-7FEB26-100000-C
                    orderId: 01JRQM8H5XYZABCDEFGHJKMNPR
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  slug: BAD_REQUEST
                  code: '0006'
                message: clientRequestId must be a UUID
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '502':
          $ref: '#/components/responses/MatchingUnavailableOnSubmit'
        '504':
          $ref: '#/components/responses/MatchingTimeoutOnSubmit'
components:
  schemas:
    CancelAllOrdersRequest:
      type: object
      properties:
        clientRequestId:
          type: string
          format: uuid
          x-go-type: string
          description: Client-generated UUID for correlation.
        contract:
          type: string
          description: Contract name. Omit to cancel every open order.
    CancelAllOrdersQueued:
      type: object
      properties:
        action:
          type: string
          description: Always `cancelAll`.
        clientRequestId:
          type: string
          format: uuid
          x-go-type: string
          description: Client-generated UUID for correlation.
        contract:
          type: string
          description: Contract name. Absent when every contract was swept.
        count:
          type: integer
          description: Number of cancels queued.
        cancels:
          type: array
          description: One entry per queued cancel, newest first.
          items:
            $ref: '#/components/schemas/CancelOrderQueued'
        unqueued:
          type: array
          description: >-
            Open orders the sweep did not queue a cancel for. Present only when
            the queue refused part-way.
          items:
            $ref: '#/components/schemas/UnqueuedCancel'
      required:
        - action
        - clientRequestId
        - count
        - cancels
    Error:
      type: object
      properties:
        error:
          type: object
          description: An object containing error details.
          properties:
            slug:
              type: string
              description: A short string identifier for the error type.
            code:
              type: string
              description: A string code representing the error.
          required:
            - slug
            - code
        message:
          type: string
          description: A human-readable message describing the error.
      required:
        - error
        - message
    CancelOrderQueued:
      type: object
      properties:
        queued:
          type: boolean
          description: Always `true`.
        accepted:
          type: boolean
          description: Always `false`.
        body:
          type: string
          description: Always `order queued, pending acceptance`.
        action:
          type: string
          description: Always `cancel`.
        messageId:
          type: string
          description: Identifier assigned to the queued request.
        clientRequestId:
          type: string
          description: Client-generated UUID for correlation.
        contract:
          type: string
          description: Contract name.
        orderId:
          type: string
          description: Unique identifier for the order.
      required:
        - queued
        - accepted
        - action
        - contract
        - orderId
    UnqueuedCancel:
      type: object
      properties:
        orderId:
          type: string
          description: Unique identifier for the order.
        contract:
          type: string
          description: Contract name.
      required:
        - orderId
        - contract
  responses:
    Unauthorized:
      description: ''
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              slug: UNAUTHORIZED
              code: '0001'
            message: unauthorized
    Forbidden:
      description: ''
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              slug: FORBIDDEN
              code: '0008'
            message: read-only token cannot create orders
    MatchingUnavailableOnSubmit:
      description: ''
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              slug: SERVICE_UNAVAILABLE
              code: '0004'
            message: matching service unavailable
    MatchingTimeoutOnSubmit:
      description: ''
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              slug: SERVICE_UNAVAILABLE
              code: '0004'
            message: matching service timed out
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````