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

# Replace order



## OpenAPI

````yaml openapi/order-gateway.json POST /replace-order
openapi: 3.1.0
info:
  title: ax-order-gateway
  description: ''
  license:
    name: ''
  version: 17.9.1
servers:
  - url: https://gateway.ai.exchange/orders
    description: Production
  - url: https://gateway.sandbox.ai.exchange/orders
    description: Sandbox
security: []
tags:
  - name: order-gateway
    description: Order gateway
paths:
  /replace-order:
    post:
      tags:
        - order-gateway
      operationId: replace_order
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplaceOrderRequest'
        required: true
      responses:
        '200':
          description: Order replaced successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReplaceOrderResponse'
        '400':
          description: Bad request
      security:
        - session_token: []
components:
  schemas:
    ReplaceOrderRequest:
      allOf:
        - $ref: '#/components/schemas/OrderReference'
          description: >-
            Identifier of the order to replace; either `oid` (server order id)
            or

            `cid` (client order id).
        - type: object
          properties:
            aid:
              type:
                - string
                - 'null'
              description: >-
                Optional account ID, selecting which account's `cid` namespace
                the

                reference resolves against. Only meaningful when the order is
                given by

                `cid` — a `cid` is unique per account, not globally — and
                superfluous

                when `oid` is supplied (server order ids are globally unique).
                If

                omitted, the account is inferred from the connection: the user's
                default

                account, or the session account for an account-scoped session.
            p:
              type:
                - string
                - 'null'
              description: >-
                New price for the replacement order (optional, inherits from
                original if not provided)
            po:
              type:
                - boolean
                - 'null'
              description: >-
                Post-only flag for the replacement order (optional, inherits
                from

                original if not provided). When set, `reprice_behavior` selects
                the

                cross-on-entry behavior just as on a place.
            q:
              type:
                - integer
                - 'null'
              format: int64
              description: >-
                New quantity for the replacement order (optional, inherits from
                original if not provided)
              minimum: 0
            rb:
              $ref: '#/components/schemas/RepriceBehavior'
              description: >-
                Reprice behavior for the replacement when it enters the book.


                This field applies to this request only. Unlike `post_only`, it
                does not

                carry over from the original order. The original order used its
                reprice

                behavior once, when it first entered the book.


                The gateway uses this field only when `post_only` is `true` on
                this

                request. Otherwise the gateway ignores it. The default is
                `Reject`.


                Example: a replace that sends neither `po` nor `rb` enters the
                book with

                reject-on-cross and reports `rb: "rej"`. This is true even if
                the

                original order was placed with `bo` or `tbl`.
            tif:
              oneOf:
                - $ref: '#/components/schemas/TimeInForce'
                  description: >-
                    New time in force for the replacement order (optional,
                    inherits from original if not provided)
                - type: 'null'
      description: >-
        Request to amend a resting order's price, quantity, or time in force.


        The amended order keeps the `self_trade_prevention` it was placed with.
        If

        the amendment would trade against the same account's resting orders:


        - `CancelIncoming` (the default) rejects the amendment.

        - `CancelResting` cancels the account's resting orders and applies the
          amendment.
        - `CancelBoth` cancels the account's resting orders and rejects the
          amendment.

        A rejected amendment leaves the order resting unchanged, at its previous

        price and quantity, and is reported with a `CancelRejected` (`t = "e"`)

        event.
    ReplaceOrderResponse:
      type: object
      required:
        - oid
      properties:
        oid:
          $ref: '#/components/schemas/OrderId'
          description: |-
            Order ID of the new replacement order; e.g. "ORD-1234567890". The
            exchange can still reject the amendment after this response; a
            `CancelRejected` (`t = "e"`) event then reports it, and the original
            order ID stays live.
    OrderReference:
      oneOf:
        - type: object
          required:
            - oid
          properties:
            oid:
              $ref: '#/components/schemas/OrderId'
        - type: object
          required:
            - cid
          properties:
            cid:
              $ref: '#/components/schemas/ClientOrderId'
    RepriceBehavior:
      type: string
      description: >-
        Reprice behavior for an aggressive post-only order — the wire `rb`
        field,

        meaningful only alongside `po = true`. Defaults to `Reject`.
      enum:
        - rej
        - bo
        - tbl
    TimeInForce:
      type: string
      description: >-
        Order time-in-force: how long an order stays active before it is
        cancelled.
      enum:
        - GTC
        - IOC
        - DAY
    OrderId:
      type: string
      description: |-
        Strong type for Order IDs to prevent mixing with other string values

        Order IDs are ULIDs with a prefix:

        - Regular orders: O-<ULID>
        - Liquidation orders: L-<ULID>
    ClientOrderId:
      type: integer
      format: int64
      minimum: 0
  securitySchemes:
    session_token:
      type: http
      scheme: bearer
      description: User session token

````

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