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

# Replace existing order

> Replace existing order.

 Replaces an existing order with new parameters by canceling the original
 order and creating a new one with the updated price/quantity. Priority is
 lost in the order book.



## OpenAPI

````yaml /proto-openapi/api/openapi.yaml put /api/v1/orders/{orderId}
openapi: 3.0.3
info:
  title: Monaco Protocol API
  description: REST API for the Monaco Protocol hybrid CLOB exchange.
  version: 1.0.0
servers:
  - url: https://staging.apimonaco.xyz
    description: Staging server (Testnet)
security: []
tags:
  - name: AccountsService
  - name: ApplicationsService
  - name: AuthService
  - name: BuildercodeRewardsService
  - name: CopyTradingService
  - name: DelegatedAgentsService
  - name: FaucetService
  - name: FeesService
  - name: HealthService
  - name: ManagedMarketsService
    description: |-
      Wallet-authenticated maker assignments. The signed session must match both
       configured maker user and application. Owner IDs are process fences, never auth.
       Only wallet sessions are supported; delegated-agent sessions receive 403.
  - name: MarginAccountsService
    description: |-
      Current public isolated-margin semantics:
       - a user has one parent margin account per application scope
       - opening orders create or reuse isolated position buckets under that parent
       - parent account creation is handled internally by margin workflows
  - name: MarketService
  - name: OrderbookService
  - name: OrdersService
  - name: PositionsService
    description: |-
      Current public isolated-margin semantics:
       - positions link to a parent margin account and, when applicable, a bucket id
       - opening orders create or reuse isolated position buckets under the parent
       - users can open another isolated position by reusing the parent account with a different market bucket
  - name: PulseService
  - name: SweeperService
  - name: TraderCodeService
  - name: TradesService
  - name: WhitelistService
  - name: WithdrawalsService
paths:
  /api/v1/orders/{orderId}:
    put:
      tags:
        - OrdersService
        - Orders
      summary: Replace existing order
      description: |-
        Replace existing order.

         Replaces an existing order with new parameters by canceling the original
         order and creating a new one with the updated price/quantity. Priority is
         lost in the order book.
      operationId: replace_order
      parameters:
        - name: orderId
          in: path
          required: true
          schema:
            type: string
            default: 2b1a5f9c-0000-4000-8000-000000000003
          example: 2b1a5f9c-0000-4000-8000-000000000003
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplaceOrderRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReplaceOrderResponse'
        '400':
          description: Invalid order ID, order cannot be replaced, or insufficient balance
        '401':
          description: Authentication required or order doesn't belong to user
        '404':
          description: Order not found
        '429':
          description: >-
            Order rate limit exceeded — the per-account item-weighted budget, or
            the budget the account family (master and sub-accounts) shares, is
            spent; retry after the interval in details.retryAfter
        '500':
          description: Internal server error
      security:
        - monacoSignature: []
        - monacoHttpSignature: []
components:
  schemas:
    ReplaceOrderRequest:
      type: object
      properties:
        selfTradePreventionMode:
          example: CANCEL_TAKER
          enum:
            - CANCEL_MAKER
            - CANCEL_TAKER
            - CANCEL_BOTH
            - SKIP
          type: string
          description: >-
            Per-order self-trade-prevention override for the replacement:
            CANCEL_MAKER, CANCEL_TAKER, CANCEL_BOTH, or SKIP (see the
            create-order field for the full semantics). A replacement is a new
            order with a new id, so it carries its own value and inherits
            nothing from the original — restate it to keep the override.
            Omitted, your wallet's configured default applies, else the platform
            default CANCEL_MAKER. The requested value is echoed back as
            selfTradePreventionMode on order reads, absent when omitted here.
          nullable: true
        price:
          example: '35500.00'
          type: string
          description: New limit price (if changing)
          nullable: true
        quantity:
          example: '0.7'
          type: string
          description: >-
            New TOTAL quantity (if changing). On a partially filled order the
            replacement rests total minus filled, and collateral is locked for
            that remainder only (FIX cancel/replace convention: LeavesQty =
            OrderQty - CumQty). Must exceed the filled amount. Omitted, the
            replacement keeps the unfilled remainder. Margin reduce-only orders
            follow the same rule: the quantity is the order's total, and what
            the replacement rests (total minus filled) must not exceed the live
            position it reduces.
          nullable: true
        useMasterBalance:
          example: false
          type: boolean
          description: Use master account balance for sub-account orders
          nullable: true
        postOnly:
          example: false
          type: boolean
          description: >-
            Post-only: reject instead of matching if this limit order would
            cross the book — rejected with HTTP 400 / gRPC INVALID_ARGUMENT
            carrying the structured error code POST_ONLY_WOULD_CROSS (REST
            error-envelope 'code' field; gRPC google.rpc.ErrorInfo reason; batch
            per-item error.code). Matching the 'post-only order would cross'
            message substring is a legacy fallback. LIMIT orders with GTC only;
            rejected on MARKET orders and IOC/FOK.
          nullable: true
        clientOrderId:
          example: quote-btc-1130-a
          type: string
          description: >-
            Client-assigned correlation handle, echoed back on order reads
            (detail and list) and on order WebSocket events. At most 64
            characters from [A-Za-z0-9._:-]; surrounding whitespace is trimmed
            before storage, and a blank or whitespace-only value is treated as
            absent. Uniqueness is enforced only among your orders that are
            RESTING on the book: a create or replace reusing a value another of
            your resting orders still holds is rejected with HTTP 409 / gRPC
            ALREADY_EXISTS and the code CLIENT_ORDER_ID_CONFLICT. An order that
            never rests — MARKET, IOC/FOK, or a LIMIT that fills completely on
            arrival — does not take the handle, and the value is released the
            moment any order reaches a terminal state. It is therefore NOT an
            idempotency key, though on this replace path a retry cannot
            double-execute: the request names the original order id, and the
            sequencer revalidates that original in memory and on the book at
            sequence time, so once the first replacement succeeds the original
            is gone and a retry is rejected with ORDER_NOT_FOUND rather than
            placing a second order. That code is itself ambiguous — the original
            may instead have filled or been cancelled — so the risk here is
            acting on a stale view, not duplicate execution. Reconcile a lost
            response against the order WebSocket stream, which carries this
            value on the submit acknowledgement and on fills, including for
            orders that never rest; order history is replica-backed and can omit
            an order that did land. The stream is not replayable and has no
            sequence number to backfill from, and its fan-out is non-persistent
            Core NATS: the service can re-establish an ended upstream
            subscription without closing your socket, so events can be missed
            while your connection still looks healthy. A matching event is
            therefore positive proof the order was accepted, but silence is
            NEVER evidence it was not, and no client-observable condition makes
            it so. Absent positive evidence the outcome is unresolved: hold and
            escalate rather than resubmitting. A replacement carries no order
            type or time-in-force and its original must still be RESTING, so the
            post-acceptance rejection shapes are unreachable here: the reachable
            failures are all pre-acceptance — malformed, post-only would cross,
            handle conflict, or the original no longer resting (ORDER_NOT_FOUND)
            — and each fails the request, emits no event and is never written to
            order history (an order rejected AFTER acceptance is persisted with
            status REJECTED, so only the pre-acceptance class is absent). Where
            no surface is conclusive, do not resubmit. A replacement is a new
            order with a new id, so it carries its own value and inherits
            nothing from the original — restate it to keep the handle.
          nullable: true
      additionalProperties: false
    ReplaceOrderResponse:
      type: object
      properties:
        orderId:
          example: 987e6543-e21b-12d3-a456-426614174000
          type: string
          description: New replacement order UUID
          format: uuid
          nullable: true
        status:
          example: SUCCESS
          type: string
          description: 'Result status: SUCCESS or FAILED'
          nullable: true
        message:
          example: Order replaced successfully
          type: string
          description: Human-readable status message
          nullable: true
        originalOrderId:
          example: 123e4567-e89b-12d3-a456-426614174000
          type: string
          description: UUID of the original cancelled order
          format: uuid
          nullable: true
        updatedFields:
          $ref: '#/components/schemas/UpdatedFields'
        matchResult:
          $ref: '#/components/schemas/MatchResult'
    UpdatedFields:
      type: object
      properties:
        price:
          example: '35500.00'
          type: string
          description: >-
            The replacement's limit price: the requested price, or the original
            order's price when price was omitted.
          nullable: true
        quantity:
          example: '0.7'
          type: string
          description: >-
            The replacement's total quantity: the requested quantity, or the
            original order's total when quantity was omitted. It is not the
            resting size: the replacement rests this total minus the
            already-filled amount, so a 100-lot with 60 filled reports 100 here
            and rests 40. Read the order's remainingQuantity for the resting
            size. Margin reduce-only replacements report their total the same
            way.
          nullable: true
    MatchResult:
      type: object
      properties:
        tradesCount:
          example: 2
          type: integer
          description: Number of trades generated by this order
          format: int32
          nullable: true
        totalFilled:
          example: '0.2'
          type: string
          description: Total quantity filled
          nullable: true
        remainingQuantity:
          example: '0.3'
          type: string
          description: Remaining unfilled quantity
          nullable: true
        averageFillPrice:
          example: '35100.00'
          type: string
          description: Volume-weighted average fill price
          nullable: true
        status:
          example: PARTIALLY_FILLED
          type: string
          description: Resulting order status after matching
          nullable: true
        actualSlippageBps:
          example: 15
          type: integer
          description: Actual slippage incurred in basis points
          format: int32
          nullable: true
        maxSlippageBps:
          example: 50
          type: integer
          description: Maximum slippage tolerance that was set
          format: int32
          nullable: true
        executionPriceRange:
          $ref: '#/components/schemas/ExecutionPriceRange'
    ExecutionPriceRange:
      type: object
      properties:
        bestPrice:
          example: '2045.00'
          type: string
          description: Best execution price achieved
          nullable: true
        worstPrice:
          example: '2052.00'
          type: string
          description: Worst execution price in the fill
          nullable: true
  securitySchemes:
    monacoSignature:
      type: apiKey
      description: >-
        Ed25519 session-key request signing. Every authenticated request carries
        three headers: `X-Monaco-PublicKey` (64-char lowercase-hex session
        public key), `X-Monaco-Timestamp` (Unix milliseconds, within 30s of
        server time), and `X-Monaco-Signature` (hex ed25519 signature). The
        signature is over `METHOD\npath?query\ntimestamp_ms\nSHA256_hex(body)`,
        where the body hash is the SHA-256 of the empty byte string when there
        is no body. Obtain the session keypair from `POST
        /api/v1/auth/challenge` followed by `POST /api/v1/auth/verify`.
      name: X-Monaco-Signature
      in: header
    monacoHttpSignature:
      type: apiKey
      description: >-
        RFC 9421 Ed25519 session-key request signatures. Send Signature-Input,
        Signature, and Content-Digest together; never combine them with
        X-Monaco-* credentials. The monaco signature covers @method, @path,
        @query, and content-digest in that order, with created (Unix seconds
        within 30s of server time), keyid (registered lowercase-hex session
        public key), and alg=ed25519 parameters. Content-Digest uses RFC 9530
        sha-256 over the exact body bytes, including the empty body. Query
        coverage retains ordering and percent encoding. Timestamp freshness does
        not reject repeated identical requests; use endpoint idempotency where
        supported. Existing legacy signing remains supported during server-first
        migration; SDK RFC 9421 signing is opt-in. See
        https://docs.0xmonaco.com/reference/http-message-signatures for the
        complete profile and trust model.
      name: Signature
      in: header

````

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