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

# Close all positions on an account

> Closes every open position at market and cancels every working order on one account, immediately. The account keeps its status and is **not** locked out — the trader can trade again straight away; combine with `POST /organization/lockouts` if you also want to stop further trading.

The resulting orders carry reason `Admin flatten: <who> — <your reason>` (trigger `admin_flatten`), and an `ACCOUNT_UPDATED` event with the counts lands on the account's event log.

Requires **manage** permission on traders. If the trading engine cannot be reached the call fails with 502 and nothing is closed.

```bash
curl -X POST "https://api.hyperprop.com/platform/v1/organization/trading-accounts/7c9e6679-7425-40de-944b-e07fc1f90ae7/flatten" \
  -H "X-API-Key: hp_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"reason": "Hedging review"}'
```



## OpenAPI

````yaml /api-reference/openapi.json post /v1/organization/trading-accounts/{accountId}/flatten
openapi: 3.0.0
info:
  title: Hyperprop Platform API
  version: 1.0.0
  description: >-
    REST API for the Hyperprop Trading Platform — provision evaluation and
    funded trading accounts, manage traders and plans, react to account
    lifecycle events via signed webhooks, and reconcile billing. Built for prop
    firms integrating from their own backend.


    Authentication, quick start, error handling, idempotency, pagination, custom
    metadata, webhooks, and the MCP connector are documented at
    https://docs.hyperprop.com.
  x-logo:
    url: https://app.hyperprop.com/logo-icon.svg
    altText: Hyperprop
    href: https://hyperprop.com
servers:
  - url: https://api.hyperprop.com/platform
    description: Production
security: []
tags:
  - name: Authentication
    description: >-
      User authentication - signup, signin, signout, password reset, email
      verification, OAuth, and MFA
  - name: User
    description: >-
      User account management - profile, notifications, agreements, dismissals,
      and audit logs. Requires Bearer token.
  - name: Organization
    description: >-
      Organization management - profile, team, trading accounts, plans, and
      rules. Supports **dual authentication**: Bearer JWT token (dashboard
      users) OR X-API-Key (programmatic access).
  - name: Market Data
    description: CME futures contracts and market data. Requires Bearer token.
  - name: Indicator Builder
    description: >-
      AI-assisted authoring of custom Hyperprop Script indicators for the web
      terminal. Requires Bearer token.
  - name: System
    description: System endpoints - health checks and connectivity
paths:
  /v1/organization/trading-accounts/{accountId}/flatten:
    post:
      tags:
        - Organization
      summary: Close all positions on an account
      description: >-
        Closes every open position at market and cancels every working order on
        one account, immediately. The account keeps its status and is **not**
        locked out — the trader can trade again straight away; combine with
        `POST /organization/lockouts` if you also want to stop further trading.


        The resulting orders carry reason `Admin flatten: <who> — <your reason>`
        (trigger `admin_flatten`), and an `ACCOUNT_UPDATED` event with the
        counts lands on the account's event log.


        Requires **manage** permission on traders. If the trading engine cannot
        be reached the call fails with 502 and nothing is closed.


        ```bash

        curl -X POST
        "https://api.hyperprop.com/platform/v1/organization/trading-accounts/7c9e6679-7425-40de-944b-e07fc1f90ae7/flatten"
        \
          -H "X-API-Key: hp_live_your_key_here" \
          -H "Content-Type: application/json" \
          -d '{"reason": "Hedging review"}'
        ```
      operationId: postV1OrganizationTradingaccountsAccountidFlatten
      parameters:
        - x-format:
            guid: true
          name: accountId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Model719'
      responses:
        '200':
          description: Success - Positions closed and orders cancelled
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model721'
        '401':
          description: Authentication required
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model9'
        '403':
          description: >-
            Forbidden - This account belongs to a different organization, or the
            caller lacks traders:manage
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model722'
        '404':
          description: Not Found - No account exists with this ID
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model723'
        '500':
          description: An unexpected error occurred
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model5'
        '502':
          description: The trading engine did not accept the request; nothing was closed
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model724'
      security:
        - Bearer: []
        - X-API-Key: []
components:
  schemas:
    Model719:
      type: object
      properties:
        reason:
          type: string
          description: >-
            Why the positions are being closed. Recorded on every resulting
            order and on the account's event log.
          example: Hedging review — positions closed pending clarification
          minLength: 3
          maxLength: 200
          x-convert:
            trim: true
      required:
        - reason
    Model721:
      type: object
      properties:
        success:
          type: boolean
          example: true
        data:
          $ref: '#/components/schemas/Model720'
    Model9:
      type: object
      properties:
        success:
          type: boolean
          description: Always false on errors
          example: false
        statusCode:
          type: number
          example: 401
        error:
          type: string
          example: Unauthorized
        message:
          type: string
          example: Authentication required
        code:
          type: string
          description: Machine-readable error code — switch on this, not on message text
          example: UNAUTHORIZED
    Model722:
      type: object
      properties:
        statusCode:
          type: number
          example: 403
        error:
          type: string
          example: Forbidden
        message:
          type: string
          example: This account does not belong to your organization
        code:
          type: string
          example: ACCOUNT_NOT_IN_ORG
    Model723:
      type: object
      properties:
        statusCode:
          type: number
          example: 404
        error:
          type: string
          example: Not Found
        message:
          type: string
          example: Trading account not found
        code:
          type: string
          example: ACCOUNT_NOT_FOUND
    Model5:
      type: object
      properties:
        success:
          type: boolean
          description: Always false on errors
          example: false
        statusCode:
          type: number
          example: 500
        error:
          type: string
          example: Internal Server Error
        message:
          type: string
          example: An unexpected error occurred
        code:
          type: string
          description: Machine-readable error code — switch on this, not on message text
          example: INTERNAL_ERROR
    Model724:
      type: object
      properties:
        statusCode:
          type: number
          example: 502
        error:
          type: string
          example: Bad Gateway
        message:
          type: string
          example: >-
            The trading engine did not accept the flatten request; nothing was
            closed
        code:
          type: string
          example: ENGINE_UNAVAILABLE
    Model720:
      type: object
      properties:
        accountId:
          type: string
          x-format:
            guid: true
        accountNumber:
          type: string
          example: MFFU-50K-000123
        ordersCancelled:
          type: number
          example: 1
        positionsClosed:
          type: number
          example: 1
        reason:
          type: string
          example: 'Admin flatten: ops@firm.com — Hedging review'
  securitySchemes:
    Bearer:
      type: apiKey
      name: Authorization
      in: header
      description: >-
        JWT Bearer token for user session auth. Format: "Bearer {token}". Used
        by User and Organization endpoints.
    X-API-Key:
      type: apiKey
      name: X-API-Key
      in: header
      description: >-
        Organization API key for programmatic access. Format: "hp_live_{key}".
        Used by Organization endpoints as an alternative to Bearer token. Keys
        are managed in the dashboard.

````

## Related topics

- [Close all open positions for an account](/trade-api/positions/close-all-open-positions-for-an-account.md)
- [Flatten account: close positions and cancel orders](/trade-api/positions/flatten-account:-close-positions-and-cancel-orders.md)
- [Cancel all pending orders for an account (keeps live position protection)](/trade-api/orders/cancel-all-pending-orders-for-an-account-keeps-live-position-protection.md)
- [Close a specific position by contract](/trade-api/positions/close-a-specific-position-by-contract.md)
- [Create or update account lockout](/trade-api/account/create-or-update-account-lockout.md)
