> ## 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 across accounts

> The kill switch for outages and incidents. Closes every open position at market and cancels every working order on every tradable account of your organization (`allAccounts: true`), or on the accounts you list (`accountIds`).

**This does not lock accounts.** Statuses do not change and traders can place new orders straight away. To stop trading as well, add a lockout with `POST /organization/lockouts` for the accounts concerned.

The run continues in the background and the call returns `202` with a `runId` at once. Follow it with `GET /organization/flatten-runs/{runId}` until `status` is `completed`: it reports accounts handled, positions closed, orders cancelled, and any account that could not be confirmed. Accounts that are already flat are left alone, so running it again is safe and covers anything that failed.

`allAccounts` covers accounts that are not started or in progress. Passed, failed, expired and turned-off accounts cannot trade; to close something left on one of them, list it in `accountIds`.

The resulting orders carry reason `Admin flatten: <who> — <your reason>` (trigger `admin_flatten`). Each account where something was closed or cancelled gets an `ACCOUNT_UPDATED` event with the counts; accounts with nothing to close get no event.

Send `preview: true` first to see how many accounts the run would cover. One run per organization at a time.

Requires **manage** permission on traders.

```bash
curl -X POST "https://api.hyperprop.com/platform/v1/organization/trading-accounts/flatten" \
  -H "X-API-Key: hp_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"allAccounts": true, "reason": "Market data outage"}'
```



## OpenAPI

````yaml https://api.hyperprop.com/platform/openapi.json post /v1/organization/trading-accounts/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: Trading accounts
    description: Create, update, and inspect trading accounts.
  - name: Traders
    description: Look up and update the traders in your organization.
  - name: Trading plans
    description: Define the plans you sell.
  - name: Trading rules
    description: Define how accounts are evaluated.
  - name: Lockouts
    description: Pause and resume trading on an account.
  - name: Payouts
    description: Check payout eligibility and record payouts.
  - name: Purchases
    description: Purchases recorded for your organization.
  - name: Time Machine
    description: Restore accounts to an earlier trading day or instant.
  - name: Webhooks
    description: Register webhook endpoints and inspect deliveries.
  - name: Events
    description: Your organization's event history and real-time event stream.
  - name: Reconciliation
    description: Balances, end-of-day snapshots, and fills for reconciliation.
  - name: Analytics
    description: Organization performance and plan economics.
  - name: Billing
    description: 'Your Hyperprop bill: activity, billing cycles, and forecasts.'
  - name: Team and roles
    description: Manage dashboard access for your staff.
  - name: API keys
    description: Manage your organization's API key.
  - name: Logs and health
    description: API request logs, the audit log, and integration health.
  - name: Organization profile
    description: Your organization's profile and logo.
  - name: Support
    description: Open and follow up on support tickets.
  - name: Partner access
    description: >-
      Read a trader's journal as an approved partner app, with the trader's own
      key.
paths:
  /v1/organization/trading-accounts/flatten:
    post:
      tags:
        - Trading accounts
      summary: Close all positions across accounts
      description: >-
        The kill switch for outages and incidents. Closes every open position at
        market and cancels every working order on every tradable account of your
        organization (`allAccounts: true`), or on the accounts you list
        (`accountIds`).


        **This does not lock accounts.** Statuses do not change and traders can
        place new orders straight away. To stop trading as well, add a lockout
        with `POST /organization/lockouts` for the accounts concerned.


        The run continues in the background and the call returns `202` with a
        `runId` at once. Follow it with `GET /organization/flatten-runs/{runId}`
        until `status` is `completed`: it reports accounts handled, positions
        closed, orders cancelled, and any account that could not be confirmed.
        Accounts that are already flat are left alone, so running it again is
        safe and covers anything that failed.


        `allAccounts` covers accounts that are not started or in progress.
        Passed, failed, expired and turned-off accounts cannot trade; to close
        something left on one of them, list it in `accountIds`.


        The resulting orders carry reason `Admin flatten: <who> — <your reason>`
        (trigger `admin_flatten`). Each account where something was closed or
        cancelled gets an `ACCOUNT_UPDATED` event with the counts; accounts with
        nothing to close get no event.


        Send `preview: true` first to see how many accounts the run would cover.
        One run per organization at a time.


        Requires **manage** permission on traders.


        ```bash

        curl -X POST
        "https://api.hyperprop.com/platform/v1/organization/trading-accounts/flatten"
        \
          -H "X-API-Key: hp_live_your_key_here" \
          -H "Content-Type: application/json" \
          -d '{"allAccounts": true, "reason": "Market data outage"}'
        ```
      operationId: postV1OrganizationTradingaccountsFlatten
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Model893'
      responses:
        '200':
          description: >-
            Preview - How many accounts the run would cover (only with `preview:
            true`)
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model896'
        '202':
          description: Accepted - The run has started
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model900'
        '400':
          description: >-
            Bad Request - Invalid payload (`VALIDATION_ERROR`), or some
            `accountIds` are not accounts of your organization
            (`ACCOUNTS_NOT_FOUND`; nothing is started)
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model902'
        '401':
          description: Authentication required
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model11'
        '403':
          description: Forbidden - The caller lacks traders:manage
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model903'
        '409':
          description: Conflict - A run is already in progress for your organization
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model904'
        '500':
          description: An unexpected error occurred
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Model6'
      security:
        - X-API-Key: []
components:
  schemas:
    Model893:
      type: object
      properties:
        allAccounts:
          type: boolean
          description: >-
            Close positions on every tradable account of your organization (not
            started or in progress). Send this or `accountIds`, not both.
          example: true
          enum:
            - true
        accountIds:
          $ref: '#/components/schemas/Model892'
        reason:
          type: string
          description: >-
            Why the positions are being closed. Recorded on every resulting
            order and on each affected account's event log.
          example: Market data outage — closing all exposure
          minLength: 3
          maxLength: 200
          x-convert:
            trim: true
        preview:
          type: boolean
          description: >-
            When true, only report how many accounts the run would cover.
            Nothing is closed.
          default: false
      required:
        - reason
    Model896:
      type: object
      properties:
        success:
          type: boolean
          example: true
        data:
          $ref: '#/components/schemas/Model895'
    Model900:
      type: object
      properties:
        success:
          type: boolean
          example: true
        data:
          $ref: '#/components/schemas/Model899'
    Model902:
      type: object
      properties:
        success:
          type: boolean
          example: false
        statusCode:
          type: number
          example: 400
        error:
          type: string
          example: Bad Request
        message:
          type: string
          example: >-
            2 of the account IDs are not accounts of your organization; nothing
            was started
        code:
          $ref: '#/components/schemas/Model901'
        unknownAccountIds:
          $ref: '#/components/schemas/unknownAccountIds'
        unknownCount:
          type: integer
          example: 2
    Model11:
      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
    Model903:
      type: object
      properties:
        statusCode:
          type: number
          example: 403
        error:
          type: string
          example: Forbidden
        message:
          type: string
          example: Your role does not have write access to "Traders & accounts"
        code:
          type: string
          example: INSUFFICIENT_PERMISSIONS
    Model904:
      type: object
      properties:
        success:
          type: boolean
          example: false
        statusCode:
          type: number
          example: 409
        error:
          type: string
          example: Conflict
        message:
          type: string
          example: >-
            A close-all run is already in progress for your organization; wait
            for it to finish
        code:
          type: string
          example: FLATTEN_RUN_IN_PROGRESS
        runId:
          type: string
          description: The run in progress
          example: 3f2a9c1e-8b7d-4e6f-a5c4-1d2e3f4a5b6c
          x-format:
            guid: true
    Model6:
      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
    Model892:
      type: array
      description: >-
        Close positions on these accounts of your organization, whatever their
        status (1 to 5,000; duplicates are ignored). Send this or `allAccounts`,
        not both.
      example:
        - 7c9e6679-7425-40de-944b-e07fc1f90ae7
      minItems: 1
      maxItems: 5000
      items:
        type: string
        x-format:
          guid: true
    Model895:
      type: object
      properties:
        preview:
          type: boolean
          example: true
        scope:
          $ref: '#/components/schemas/Model894'
        total:
          type: integer
          example: 7180
    Model899:
      type: object
      properties:
        runId:
          type: string
          example: 3f2a9c1e-8b7d-4e6f-a5c4-1d2e3f4a5b6c
          x-format:
            guid: true
        status:
          $ref: '#/components/schemas/Model897'
        total:
          type: integer
          example: 7180
        scope:
          $ref: '#/components/schemas/Model898'
    Model901:
      type: string
      example: ACCOUNTS_NOT_FOUND
      enum:
        - VALIDATION_ERROR
        - ACCOUNTS_NOT_FOUND
    unknownAccountIds:
      type: array
      description: 'With ACCOUNTS_NOT_FOUND: up to 50 of the IDs that were not found'
      example:
        - 9b2e1f4c-3d5a-4b6c-8e7f-0a1b2c3d4e5f
      items:
        type: string
    Model894:
      type: string
      example: all
      enum:
        - all
        - accounts
    Model897:
      type: string
      description: '`completed` straight away when there are no accounts to cover'
      example: running
      enum:
        - running
        - completed
    Model898:
      type: string
      example: all
      enum:
        - all
        - accounts
  securitySchemes:
    X-API-Key:
      type: apiKey
      name: X-API-Key
      in: header
      description: >-
        Organization API key. Format: "hp_live_{key}". Organization admins
        manage the key in the dashboard.

````

## Related topics

- [Close all positions on an account](/platform-api/trading-accounts/close-all-positions-on-an-account.md)
- [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)
- [Get a close-all run](/platform-api/trading-accounts/get-a-close-all-run.md)


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