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

# Cancel order

> Cancel a pending order that has not been submitted to the broker



## OpenAPI

````yaml POST /investments/orders/{id}/cancel
openapi: 3.0.3
info:
  title: Wealthyhood Investments API
  version: 1.0.0
  description: >
    Portfolio and asset investment preview, execution, and order management
    endpoints for Wealthyhood portfolios.


    All requests use machine-to-machine (M2M) authentication. Each request
    requires:

    - A bearer access token (M2M token with required scopes)

    - An `x-user-id` header to specify which user's data to access
servers:
  - url: https://{host}
    variables:
      host:
        default: api.wealthyhood.com
        description: Wealthyhood API host name.
security:
  - bearerAuth: []
tags:
  - name: Investments
    description: >-
      Preview and execute portfolio and asset investment operations, and manage
      orders.
paths:
  /investments/orders/{id}/cancel:
    post:
      tags:
        - Investments
      summary: Cancel an order
      description: >
        Cancel a pending order that has not yet been submitted to the broker.
        Only orders with

        status `Pending` that have not been submitted to the broker can be
        cancelled.


        Orders cannot be cancelled if:

        - They have already been submitted to the broker

        - They have real-time execution

        - They are not in `Pending` status
      parameters:
        - $ref: '#/components/parameters/XUserId'
        - $ref: '#/components/parameters/OrderId'
      responses:
        '200':
          description: Order cancelled successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  status:
                    type: string
                    enum:
                      - Cancelled
              example:
                id: 64f5b3137fb3fc001234abce
                status: Cancelled
        '400':
          description: Order is not cancellable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
              example:
                status: 400
                error:
                  description: Order 64f5b3137fb3fc001234abce is not cancellable
                responseId: 3f0fd3bf-a2ff-4c0e-9b1d-5d7055dbf6cd
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '403':
          $ref: '#/components/responses/ForbiddenError'
        '404':
          $ref: '#/components/responses/NotFoundError'
components:
  parameters:
    XUserId:
      name: x-user-id
      in: header
      required: true
      description: >-
        User identifier for the M2M client to specify which user's data to
        access.
      schema:
        type: string
        pattern: ^[a-f0-9]{24}$
    OrderId:
      name: id
      in: path
      required: true
      description: Order identifier (MongoDB ObjectId)
      schema:
        type: string
        pattern: ^[a-f0-9]{24}$
  schemas:
    ApiErrorResponse:
      type: object
      properties:
        status:
          type: integer
        error:
          type: object
          properties:
            message:
              type: string
            description:
              type: string
              nullable: true
        responseId:
          type: string
          format: uuid
  responses:
    UnauthorizedError:
      description: Missing or invalid bearer token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            status: 401
            error:
              message: User not found
            responseId: 145f2b0d-1d5b-4e91-8d0d-7af0ae9ad13a
    ForbiddenError:
      description: >-
        Authenticated user cannot act on the requested portfolio or lacks
        scopes.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            status: 403
            error:
              message: Portfolio does not belong to user
            responseId: 5e467f79-c62c-4d83-9810-7a0f8529fd76
    NotFoundError:
      description: Portfolio or related resource was not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
          example:
            status: 404
            error:
              message: Portfolio not found
            responseId: 65c0b1f6-2a48-4c4f-a5aa-9b9c8c6f9b58
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Auth0-issued access token that includes the scopes listed for the
        endpoint.

````