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

# Reverse a trade

> Reverses an existing trade using an approved reverse quote.

Reverses an existing trade using an approved quote from [Generate a reverse quote](/v2/api-reference/trade/generate-reverse-quote).

Use this endpoint to:

* Unwind a trade executed in error
* Refund a customer at the quoted reversal rate
* Correct a duplicate or mis-keyed execution

<Note>**Idempotency required.** This POST requires an `Idempotency-Key` header. Keys are cached for 24 hours. Reusing the same key with the same body returns the cached response; reusing it with different parameters returns a 422 error.</Note>

## Errors

| Status | Message                                                                         | Notes                                                                          |
| ------ | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| 400    | `Query validation failed`                                                       | Request didn't match schema (bad trade ID, bad quote ID, missing fields, etc.) |
| 401    | `The authorization key provided is either invalid or expired, please try again` | Mint a fresh JWT — see [Authentication](/v2/authentication)                    |
| 404    | `Trade not found`                                                               | `tradeId` or `quoteId` doesn't resolve to a record on this org                 |
| 409    | `The trade cannot be reversed`                                                  | The trade is outside its reversal window or already reversed/settled           |
| 409    | `Request with this idempotency key is currently processing`                     | See [Errors → Idempotency](/v2/errors#idempotency-errors)                      |
| 422    | `Idempotency key reused with different parameters`                              | New body → new key                                                             |
| 500    | `An internal error has occurred`                                                | Trade may or may not have reversed — GET the trade by ID before retrying       |

See the full [v2 error reference](/v2/errors) for retry semantics and idempotency-specific codes.


## OpenAPI

````yaml POST /v2/brokerage/{orgId}/trade/reverse
openapi: 3.1.0
info:
  title: Overview of OpenFX APIs
  description: >-
    OpenFX provides a robust and secure API suite engineered for high
    performance and reliability, enabling programmatic access to real-time
    market data, trade execution, and money movement functionalities. This guide
    will walk through the step-by-step process of deposits, quoting, trading,
    settlements and monitoring using OpenFX APIs.
  version: v2.0.0
  termsOfService: https://www.openfx.com/terms
  contact:
    name: OpenFX Support
    email: support@openfx.com
    url: https://www.openfx.com
servers:
  - url: https://api.openfx.com
    description: OpenFX API Server
security:
  - bearerAuth: []
tags:
  - name: MarketData
    description: >-
      This endpoint retrieves a complete list of all tradable fiat and
      stablecoin currency pairs on the OpenFX platform.
  - name: Balances
    description: >-
      The Balance endpoints enable real-time tracking and management of currency
      holdings within an account.
  - name: Trade
    description: >-
      The Trade APIs facilitate programmatic currency exchange through a
      quote-then-trade workflow, ensuring price transparency and guaranteed
      execution at quoted rates.
  - name: Deposits
    description: >-
      Deposit endpoints enable secure funding of trading accounts across
      multiple supported currencies and methods.
  - name: Withdrawals
    description: >-
      The Withdrawal API facilitates secure fund withdrawals for both fiat and
      stablecoins.
paths:
  /v2/brokerage/{orgId}/trade/reverse:
    post:
      tags:
        - Trade
      summary: Reverse a trade
      description: >-
        Reverses an existing trade using an approved reverse quote.


        **Idempotency (V2 only):** This endpoint requires an `Idempotency-Key`
        header. Keys are cached for 24 hours. Reusing a key with the same
        parameters returns the cached response; different parameters return a
        422 error.
      operationId: reverseTrade
      parameters:
        - name: Idempotency-Key
          in: header
          required: true
          schema:
            type: string
            format: uuid
            example: 523e4567-e89b-42d3-a456-426614174000
          description: >-
            V2 only. Unique key for an idempotent reverse trade request. Valid
            for 24 hours.
        - schema:
            type: string
          in: path
          name: orgId
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                tradeId:
                  type: string
                  format: uuid
                  example: 123e4567-e89b-42d3-a456-426614174000
                  description: Unique identifier of the trade being reversed
                quoteId:
                  type: string
                  format: uuid
                  example: 223e4567-e89b-42d3-a456-426614174000
                  description: Unique identifier of the approved reverse quote
                clientReferenceId:
                  type: string
                  example: customer-reversal-20260713-001
                  description: Optional client-supplied reference for the reversed trade
              required:
                - tradeId
                - quoteId
      responses:
        '200':
          description: Trade reversed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - success
                      - error
                    example: success
                  data:
                    type: object
                    properties:
                      trade:
                        type: object
                        properties:
                          id:
                            type: string
                            format: uuid
                            example: 423e4567-e89b-42d3-a456-426614174000
                          buy:
                            type: string
                            example: USD
                          sell:
                            type: string
                            example: USDC
                          referencedUnit:
                            type: string
                            example: USD
                          referencedAmount:
                            type: number
                            example: 1000
                          amount:
                            type: number
                            example: 999.25
                          status:
                            type: string
                            example: REVERSED
                          transactedAt:
                            type: string
                            example: '2026-07-13T10:00:00.000Z'
                          quoteId:
                            type: string
                            format: uuid
                            example: 223e4567-e89b-42d3-a456-426614174000
                          clientReferenceId:
                            type:
                              - string
                              - 'null'
                            example: customer-reversal-20260713-001
                          originalTradeId:
                            type: string
                            format: uuid
                            example: 123e4567-e89b-42d3-a456-426614174000
                        required:
                          - id
                          - buy
                          - sell
                          - referencedUnit
                          - referencedAmount
                          - amount
                          - status
                          - transactedAt
                          - quoteId
                          - clientReferenceId
                          - originalTradeId
                      reversalDetails:
                        type: object
                        properties:
                          direction:
                            type: string
                            enum:
                              - DEBIT
                              - CREDIT
                            example: CREDIT
                          differentialAmount:
                            type: number
                            example: 0.75
                          currency:
                            type: string
                            example: USD
                        required:
                          - direction
                          - differentialAmount
                          - currency
                    required:
                      - trade
                      - reversalDetails
                  message:
                    type: string
                    example: Data fetched successfully
                required:
                  - data
              examples:
                default_example:
                  value:
                    status: success
                    message: Trade reversed successfully
                    data:
                      trade:
                        id: 423e4567-e89b-42d3-a456-426614174000
                        buy: USD
                        sell: USDC
                        referencedUnit: USD
                        referencedAmount: 1000
                        amount: 999.25
                        status: REVERSED
                        transactedAt: '2026-07-13T10:00:00.000Z'
                        quoteId: 223e4567-e89b-42d3-a456-426614174000
                        clientReferenceId: customer-reversal-20260713-001
                        originalTradeId: 123e4567-e89b-42d3-a456-426614174000
                      reversalDetails:
                        direction: CREDIT
                        differentialAmount: 0.75
                        currency: USD
        '400':
          description: Bad Request
          content:
            application/json:
              examples:
                default_example:
                  value:
                    status: error
                    message: Query validation failed
        '401':
          description: Unauthorized
          content:
            application/json:
              examples:
                default_example:
                  value:
                    status: error
                    message: >-
                      The authorization key provided is either invalid or
                      expired, please try again
        '404':
          description: Trade or reverse quote not found
          content:
            application/json:
              examples:
                default_example:
                  value:
                    status: error
                    message: Trade not found
                    error:
                      code: TRADE_NOT_FOUND
        '409':
          description: Trade cannot be reversed
          content:
            application/json:
              examples:
                default_example:
                  value:
                    status: error
                    message: The trade cannot be reversed
                    error:
                      code: TRADE_NOT_REVERSIBLE
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              examples:
                default_example:
                  value:
                    status: error
                    message: Idempotency key reused with different parameters
                    error:
                      code: IDEMPOTENCY_MISMATCH
                      details: >-
                        This idempotency key was already used with different
                        request parameters
        '500':
          description: Internal Server Error
          content:
            application/json:
              examples:
                default_example:
                  value:
                    status: error
                    message: An internal error has occurred
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````