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

# Cancel several orders

> Cancels each named order of this key's trading account in this key's mode, the same way canceling each order would. Name orders by id, by client_order_id or both, up to 50 in one call. One failed cancel does not stop the rest; each result says what happened, and an order that matches nothing fails with NOT_FOUND. Works while trading is paused.



## OpenAPI

````yaml api-reference/openapi.json POST /orders/cancel-batch
openapi: 3.0.0
info:
  title: Lean API
  version: 0.1.0
  description: >-
    Programmatic access to Lean: canonical sports markets, quotes, orders,
    positions and balances.
servers:
  - url: '{baseUrl}/v1'
    description: Lean API
    variables:
      baseUrl:
        default: https://api.lean.xyz
        description: >-
          The Lean API base URL, without /v1. Same value as LEAN_API_URL in the
          guides.
security:
  - apiKey: []
paths:
  /orders/cancel-batch:
    post:
      tags:
        - Orders
      summary: Cancel several orders
      description: >-
        Cancels each named order of this key's trading account in this key's
        mode, the same way canceling each order would. Name orders by id, by
        client_order_id or both, up to 50 in one call. One failed cancel does
        not stop the rest; each result says what happened, and an order that
        matches nothing fails with NOT_FOUND. Works while trading is paused.
      operationId: cancelOrdersBatch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                order_ids:
                  type: array
                  items:
                    type: string
                    format: uuid
                  description: Orders to cancel by the id Lean gave them.
                client_order_ids:
                  type: array
                  items:
                    type: string
                    pattern: ^[A-Za-z0-9_-]{1,64}$
                  description: >-
                    Orders to cancel by the client_order_id they were placed
                    with.
              additionalProperties: false
            example:
              order_ids:
                - 8a1e5c07-4b3f-4d62-9f18-2c7e0a95d4b1
              client_order_ids:
                - bot-0002
      responses:
        '200':
          description: One result per order named
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      success:
                        type: boolean
                        enum:
                          - true
                      data:
                        type: object
                        properties:
                          results:
                            type: array
                            items:
                              type: object
                              properties:
                                order_id:
                                  type: string
                                  nullable: true
                                  format: uuid
                                client_order_id:
                                  type: string
                                  nullable: true
                                  minLength: 1
                                status:
                                  type: string
                                  enum:
                                    - canceled
                                    - finished
                                    - failed
                                order:
                                  type: object
                                  nullable: true
                                  properties:
                                    id:
                                      type: string
                                      format: uuid
                                    client_order_id:
                                      type: string
                                      minLength: 1
                                    market_id:
                                      type: string
                                      minLength: 1
                                      description: >-
                                        The market id from GET /markets, however
                                        the request named the market.
                                    title:
                                      type: string
                                      nullable: true
                                      minLength: 1
                                    outcome:
                                      type: string
                                      nullable: true
                                      minLength: 1
                                    venue:
                                      type: string
                                      nullable: true
                                      enum:
                                        - kalshi
                                        - polymarket
                                        - polymarket_us
                                        - hyperliquid
                                    ticker:
                                      type: string
                                      nullable: true
                                      minLength: 1
                                    side:
                                      type: string
                                      nullable: true
                                      enum:
                                        - 'yes'
                                        - 'no'
                                    action:
                                      type: string
                                      enum:
                                        - buy
                                        - sell
                                    type:
                                      type: string
                                      enum:
                                        - limit
                                        - market
                                    time_in_force:
                                      type: string
                                      enum:
                                        - gtc
                                        - ioc
                                        - fok
                                        - gtd
                                    expires_at:
                                      type: string
                                      nullable: true
                                      format: date-time
                                    quantity:
                                      type: string
                                      pattern: ^\d+(?:\.\d+)?$
                                    filled_quantity:
                                      type: string
                                      pattern: ^\d+(?:\.\d+)?$
                                    remaining_quantity:
                                      type: string
                                      pattern: ^\d+(?:\.\d+)?$
                                      description: >-
                                        Shares still working on the venues: the
                                        unfilled size of each live venue order.
                                        Zero once the order is final, since a
                                        canceled, expired or rejected remainder
                                        no longer works.
                                    limit_price:
                                      type: string
                                    avg_fill_price:
                                      type: string
                                      nullable: true
                                      description: >-
                                        Average price per share filled,
                                        size-weighted across the venue orders
                                        that filled, excluding fees. Null until
                                        every filled venue order has a price.
                                    notional_usd:
                                      type: string
                                      pattern: ^\d+(?:\.\d+)?$
                                    filled_notional_usd:
                                      type: string
                                      nullable: true
                                      pattern: ^\d+(?:\.\d+)?$
                                    status:
                                      type: string
                                      enum:
                                        - pending
                                        - open
                                        - partially_filled
                                        - filled
                                        - canceled
                                        - rejected
                                        - expired
                                        - unconfirmed
                                        - needs_attention
                                        - cancel_requested
                                    venue_status:
                                      type: string
                                      nullable: true
                                    venue_order_id:
                                      type: string
                                      nullable: true
                                    status_reason:
                                      type: object
                                      nullable: true
                                      properties:
                                        code:
                                          type: string
                                          minLength: 1
                                        message:
                                          type: string
                                          minLength: 1
                                      required:
                                        - code
                                        - message
                                    legs:
                                      type: array
                                      items:
                                        type: object
                                        properties:
                                          venue:
                                            type: string
                                            enum:
                                              - kalshi
                                              - polymarket
                                              - polymarket_us
                                              - hyperliquid
                                          ticker:
                                            type: string
                                            minLength: 1
                                          side:
                                            type: string
                                            enum:
                                              - 'yes'
                                              - 'no'
                                          quantity:
                                            type: string
                                            pattern: ^\d+(?:\.\d+)?$
                                          filled_quantity:
                                            type: string
                                            pattern: ^\d+(?:\.\d+)?$
                                          limit_price:
                                            type: string
                                          avg_fill_price:
                                            type: string
                                            nullable: true
                                          status:
                                            type: string
                                            enum:
                                              - pending
                                              - open
                                              - partially_filled
                                              - filled
                                              - canceled
                                              - rejected
                                              - expired
                                              - unconfirmed
                                              - needs_attention
                                              - cancel_requested
                                          venue_status:
                                            type: string
                                            nullable: true
                                          venue_order_id:
                                            type: string
                                            nullable: true
                                          cancel_requested_at:
                                            type: string
                                            nullable: true
                                            format: date-time
                                          status_reason:
                                            type: object
                                            nullable: true
                                            properties:
                                              code:
                                                type: string
                                                minLength: 1
                                              message:
                                                type: string
                                                minLength: 1
                                            required:
                                              - code
                                              - message
                                        required:
                                          - venue
                                          - ticker
                                          - side
                                          - quantity
                                          - filled_quantity
                                          - limit_price
                                          - avg_fill_price
                                          - status
                                          - venue_status
                                          - venue_order_id
                                          - cancel_requested_at
                                          - status_reason
                                    post_only:
                                      type: boolean
                                    replaces_order_id:
                                      type: string
                                      nullable: true
                                      format: uuid
                                    replaced_by_order_id:
                                      type: string
                                      nullable: true
                                      format: uuid
                                    created_at:
                                      type: string
                                      format: date-time
                                    updated_at:
                                      type: string
                                      format: date-time
                                    livemode:
                                      type: boolean
                                  required:
                                    - id
                                    - client_order_id
                                    - market_id
                                    - title
                                    - outcome
                                    - venue
                                    - ticker
                                    - side
                                    - action
                                    - type
                                    - time_in_force
                                    - expires_at
                                    - quantity
                                    - filled_quantity
                                    - remaining_quantity
                                    - limit_price
                                    - avg_fill_price
                                    - notional_usd
                                    - filled_notional_usd
                                    - status
                                    - venue_status
                                    - venue_order_id
                                    - status_reason
                                    - legs
                                    - post_only
                                    - replaces_order_id
                                    - replaced_by_order_id
                                    - created_at
                                    - updated_at
                                    - livemode
                                error:
                                  type: object
                                  nullable: true
                                  properties:
                                    code:
                                      type: string
                                      minLength: 1
                                    message:
                                      type: string
                                      minLength: 1
                                    details:
                                      nullable: true
                                  required:
                                    - code
                                    - message
                              required:
                                - order_id
                                - client_order_id
                                - status
                                - order
                                - error
                          livemode:
                            type: boolean
                        required:
                          - results
                          - livemode
                      meta:
                        type: object
                        properties:
                          timestampMs:
                            type: integer
                            minimum: 0
                          requestId:
                            type: string
                            minLength: 1
                          traceId:
                            type: string
                            minLength: 1
                          cachedAtMs:
                            type: integer
                            minimum: 0
                          source:
                            type: string
                            enum:
                              - cache
                              - database
                              - clickhouse
                              - upstream
                              - fallback
                              - internal
                        required:
                          - timestampMs
                          - requestId
                    required:
                      - success
                      - data
                      - meta
                  - $ref: '#/components/schemas/ApiError'
              example:
                success: true
                data:
                  results:
                    - order_id: 8a1e5c07-4b3f-4d62-9f18-2c7e0a95d4b1
                      client_order_id: bot-0001
                      status: canceled
                      order:
                        id: 8a1e5c07-4b3f-4d62-9f18-2c7e0a95d4b1
                        client_order_id: bot-0001
                        market_id: >-
                          mkt_bmZsOjIwMjYtMTAtMTE6REVOLUxBQwpzcHJlYWQ6Z2FtZTpERU46LTMuNQpERU4
                        title: >-
                          Denver Broncos at Los Angeles Chargers: DEN -3.5,
                          Denver Broncos -3.5
                        outcome: DEN
                        venue: null
                        ticker: null
                        side: null
                        action: buy
                        type: limit
                        time_in_force: gtc
                        expires_at: null
                        quantity: '10'
                        filled_quantity: '4'
                        remaining_quantity: '0'
                        limit_price: '0.55'
                        avg_fill_price: '0.55'
                        notional_usd: '2.2'
                        filled_notional_usd: '2.2'
                        status: canceled
                        venue_status: null
                        venue_order_id: null
                        status_reason: null
                        legs: []
                        post_only: false
                        replaces_order_id: null
                        replaced_by_order_id: null
                        created_at: '2026-10-29T18:00:00.000Z'
                        updated_at: '2026-10-29T18:00:00.000Z'
                        livemode: false
                      error: null
                    - order_id: null
                      client_order_id: bot-0002
                      status: failed
                      order: null
                      error:
                        code: NOT_FOUND
                        message: Order not found
                  livemode: false
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '400':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Invalid request
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '401':
          description: Missing, invalid, expired or revoked API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid, expired or revoked API key
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '403':
          description: The key lacks the scope this route needs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: This API key lacks the scope this route needs
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '429':
          description: API error
          headers:
            Retry-After:
              description: Seconds remaining in the upstream read cooldown, when available
              schema:
                type: integer
                minimum: 0
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: RATE_LIMITED
                  message: Too many requests for this API key
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
        '500':
          description: API error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
              example:
                success: false
                error:
                  code: INTERNAL_ERROR
                  message: An internal error occurred.
                meta:
                  timestampMs: 1792771200000
                  requestId: 7d2c9f4e-1b3a-4e8d-9c6f-2a5b8e0d4f17
components:
  schemas:
    ApiError:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - false
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - VALIDATION_ERROR
                - NOT_FOUND
                - UNAUTHORIZED
                - FORBIDDEN
                - CONFLICT
                - UPSTREAM_ERROR
                - RATE_LIMITED
                - INTERNAL_ERROR
                - FEATURE_DISABLED
                - CONDITIONAL_SELL_REJECTED
                - CONDITIONAL_SELL_ACTIVE
            message:
              type: string
              minLength: 1
            details:
              nullable: true
          required:
            - code
            - message
        meta:
          type: object
          properties:
            timestampMs:
              type: integer
              minimum: 0
            requestId:
              type: string
              minLength: 1
            traceId:
              type: string
              minLength: 1
            cachedAtMs:
              type: integer
              minimum: 0
            source:
              type: string
              enum:
                - cache
                - database
                - clickhouse
                - upstream
                - fallback
                - internal
          required:
            - timestampMs
            - requestId
      required:
        - success
        - error
        - meta
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        A Lean API key, sent as `Authorization: Bearer <key>`. A test key
        (`lean_sk_test_...`) simulates orders and fills with no money; a live
        key (`lean_sk_live_...`) trades for real within the key's limits. Every
        successful response says which mode answered in `data.livemode`.

````

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