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

# Cancel an existing order and place a new one

> Atomically cancels a resting order (identified by order_id_to_cancel or nonce_to_cancel) and submits a replacement order in a single request. The payload is a full new-order specification plus the cancel target and an optional expected_filled_amount guard. Requires a signed order payload and Orderbook trade scope; returns both the cancelled and the newly created order.



## OpenAPI

````yaml /openapi.json post /private/replace
openapi: 3.1.0
info:
  title: Derive v3 API
  version: 0.2.0
  description: JSON-RPC 2.0 methods, served over WebSocket and HTTP POST.
servers:
  - url: https://api.derive.xyz/v3
    description: Production (HTTP POST base)
  - url: https://testnet.api.derive.xyz/v3
    description: Testnet (HTTP POST base)
security: []
tags:
  - name: Subaccounts
    description: >-
      List, inspect, and label subaccounts, portfolios, positions, and
      collateral.
  - name: Session Keys
    description: Register, edit, and list delegated signing keys.
  - name: Account
    description: Wallet-level account information and settings.
  - name: Orderbook
    description: Place, replace, cancel, and query orders, trigger orders, and algos.
  - name: RFQ
    description: 'Request-for-quote: send RFQs, quote, and execute block trades.'
  - name: Vault Shareholders
    description: >-
      Deposit into and withdraw from vaults, and track shares, requests, and
      performance.
  - name: Vault Curators
    description: >-
      Create and operate curated vaults: settle deposit and withdrawal requests,
      and manage vault metadata.
  - name: History
    description: >-
      Per-account historical records: orders, trades, transfers, and
      settlements.
  - name: Market Maker Protection
    description: Configure, read, and reset market-maker protection.
  - name: Transfers & Withdrawals
    description: Move collateral between subaccounts, to other wallets, and on-chain.
  - name: System
    description: Rate limits and transaction lookups.
  - name: Market Data
    description: Instruments, currencies, tickers, and market-wide feeds.
  - name: Referrals
    description: Referral codes and program performance.
  - name: Other
    description: Uncategorized.
paths:
  /private/replace:
    post:
      tags:
        - Orderbook
      summary: Cancel an existing order and place a new one
      description: >-
        Atomically cancels a resting order (identified by order_id_to_cancel or
        nonce_to_cancel) and submits a replacement order in a single request.
        The payload is a full new-order specification plus the cancel target and
        an optional expected_filled_amount guard. Requires a signed order
        payload and Orderbook trade scope; returns both the cancelled and the
        newly created order.
      operationId: private_replace
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplaceOrderRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReplaceOrderResponse'
        default:
          description: JSON-RPC error (see Error Codes)
components:
  schemas:
    ReplaceOrderRequest:
      description: >-
        `private/replace` parameters: a `private/order` payload plus the
        cancel-target fields (`order_id_to_cancel`, `nonce_to_cancel`,
        `expected_filled_amount`).
      type: object
      required:
        - amount
        - direction
        - instrument_name
        - limit_price
        - max_fee
        - nonce
        - signature
        - signature_expiry_sec
        - signer
        - subaccount_id
      properties:
        algo_duration_sec:
          default: null
          type:
            - integer
            - 'null'
          format: int32
        algo_num_slices:
          default: null
          type:
            - integer
            - 'null'
          format: int32
        algo_type:
          default: null
          anyOf:
            - $ref: '#/components/schemas/AlgoType'
            - type: 'null'
        amount:
          description: >-
            Order amount in units of the base, as a decimal string (e.g.
            `"1.5"`) or a JSON number.
          type: string
          format: decimal
        client:
          default: null
          type:
            - string
            - 'null'
        direction:
          $ref: '#/components/schemas/Direction'
        expected_filled_amount:
          description: >-
            Optional decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits, or null; a string or JSON number is accepted
          default: null
          type:
            - string
            - 'null'
          format: decimal
        extra_fee:
          description: >-
            Optional extra fee per unit of volume, as a decimal string or JSON
            number. Defaults to zero.
          default: null
          type:
            - string
            - 'null'
          format: decimal
        instrument_name:
          type: string
        is_atomic_signing:
          default: null
          type:
            - boolean
            - 'null'
        label:
          default: null
          type:
            - string
            - 'null'
        limit_price:
          description: >-
            Limit price in quote currency, as a decimal string (e.g. `"3100.5"`)
            or a JSON number.
          type: string
          format: decimal
        max_fee:
          description: >-
            Max fee per unit of volume in quote currency, as a decimal string or
            a JSON number.
          type: string
          format: decimal
        mmp:
          default: null
          type:
            - boolean
            - 'null'
        nonce:
          type: string
        nonce_to_cancel:
          default: null
          type:
            - integer
            - 'null'
          format: int64
        order_id_to_cancel:
          description: Optional UUID v4 string
          default: null
          type:
            - string
            - 'null'
          format: uuid
        order_type:
          $ref: '#/components/schemas/OrderType'
          default: limit
        reduce_only:
          default: null
          type:
            - boolean
            - 'null'
        referral_code:
          default: null
          type:
            - string
            - 'null'
        reject_post_only:
          default: null
          type:
            - boolean
            - 'null'
        reject_timestamp:
          default: null
          type:
            - integer
            - 'null'
          format: int64
        signature:
          type: string
        signature_expiry_sec:
          type: integer
          format: int64
        signer:
          type: string
        subaccount_id:
          type: integer
          format: int64
        time_in_force:
          $ref: '#/components/schemas/TimeInForce'
          default: gtc
        trigger_price:
          description: >-
            Trigger price as a decimal string or JSON number; omit for
            non-trigger orders.
          default: null
          type:
            - string
            - 'null'
          format: decimal
        trigger_price_type:
          default: null
          anyOf:
            - $ref: '#/components/schemas/TriggerPriceType'
            - type: 'null'
        trigger_type:
          default: null
          anyOf:
            - $ref: '#/components/schemas/TriggerType'
            - type: 'null'
    ReplaceOrderResponse:
      type: object
      required:
        - cancelled_order
      properties:
        cancelled_order:
          $ref: '#/components/schemas/Order'
        create_order_error:
          default: null
          anyOf:
            - $ref: '#/components/schemas/RPCError'
            - type: 'null'
        order:
          default: null
          anyOf:
            - $ref: '#/components/schemas/Order'
            - type: 'null'
        trades:
          default: null
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/Trade'
    AlgoType:
      type: string
      enum:
        - twap
    Direction:
      type: string
      enum:
        - buy
        - sell
    OrderType:
      type: string
      enum:
        - limit
        - market
    TimeInForce:
      type: string
      enum:
        - gtc
        - post_only
        - fok
        - ioc
    TriggerPriceType:
      type: string
      enum:
        - mark
        - index
    TriggerType:
      type: string
      enum:
        - stoploss
        - takeprofit
    Order:
      type: object
      required:
        - amount
        - average_price
        - creation_timestamp
        - direction
        - extra_fee
        - filled_amount
        - instrument_name
        - is_transfer
        - last_update_timestamp
        - limit_price
        - max_fee
        - mmp
        - nonce
        - order_fee
        - order_id
        - order_status
        - order_type
        - quote_id
        - replaced_order_id
        - signature
        - signature_expiry_sec
        - signed_limit_price
        - signer
        - subaccount_id
        - time_in_force
        - trigger_price
      properties:
        algo_duration_sec:
          type:
            - integer
            - 'null'
          format: int32
        algo_num_slices:
          type:
            - integer
            - 'null'
          format: int32
        algo_slices_completed:
          type:
            - integer
            - 'null'
          format: int32
        algo_type:
          anyOf:
            - $ref: '#/components/schemas/AlgoType'
            - type: 'null'
        amount:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        average_price:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        cancel_reason:
          $ref: '#/components/schemas/CancelReason'
          default: ''
        creation_timestamp:
          type: integer
          format: int64
        direction:
          $ref: '#/components/schemas/Direction'
        extra_fee:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        filled_amount:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        instrument_name:
          type: string
        is_transfer:
          type: boolean
        label:
          default: ''
          type: string
        last_update_timestamp:
          type: integer
          format: int64
        limit_price:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        max_fee:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        mmp:
          type: boolean
        nonce:
          type: string
        order_fee:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        order_id:
          type: string
        order_status:
          $ref: '#/components/schemas/OrderStatus'
        order_type:
          $ref: '#/components/schemas/OrderType'
        quote_id:
          description: Optional UUID v4 string
          type:
            - string
            - 'null'
          format: uuid
        replaced_order_id:
          description: Optional UUID v4 string
          type:
            - string
            - 'null'
          format: uuid
        signature:
          type: string
        signature_expiry_sec:
          type: integer
          format: int64
        signed_limit_price:
          description: >-
            Optional decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits, or null; a string or JSON number is accepted
          type:
            - string
            - 'null'
          format: decimal
        signer:
          type: string
        subaccount_id:
          type: integer
          format: int64
        time_in_force:
          $ref: '#/components/schemas/TimeInForce'
        trigger_price:
          description: >-
            Optional decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits, or null; a string or JSON number is accepted
          type:
            - string
            - 'null'
          format: decimal
        trigger_price_type:
          anyOf:
            - $ref: '#/components/schemas/TriggerPriceType'
            - type: 'null'
        trigger_reject_message:
          type:
            - string
            - 'null'
        trigger_type:
          anyOf:
            - $ref: '#/components/schemas/TriggerType'
            - type: 'null'
    RPCError:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int64
        data:
          type:
            - string
            - 'null'
        message:
          type: string
    Trade:
      description: Info that the user expects to get delivered when requesting trade info.
      type: object
      required:
        - direction
        - expected_rebate
        - extra_fee
        - index_price
        - instrument_name
        - is_transfer
        - liquidity_role
        - mark_price
        - op_uuid
        - order_id
        - quote_id
        - realized_pnl
        - realized_pnl_excl_fees
        - rfq_id
        - subaccount_id
        - timestamp
        - trade_amount
        - trade_fee
        - trade_id
        - trade_price
        - tx_status
      properties:
        direction:
          $ref: '#/components/schemas/Direction'
        expected_rebate:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        extra_fee:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        index_price:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        instrument_name:
          type: string
        is_transfer:
          type: boolean
        label:
          default: ''
          type: string
        liquidity_role:
          $ref: '#/components/schemas/LiquidityRole'
        mark_price:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        op_uuid:
          type: string
        order_id:
          type: string
        quote_id:
          description: Optional UUID v4 string
          type:
            - string
            - 'null'
          format: uuid
        realized_pnl:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        realized_pnl_excl_fees:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        rfq_id:
          description: Optional UUID v4 string
          type:
            - string
            - 'null'
          format: uuid
        subaccount_id:
          type: integer
          format: int64
        timestamp:
          type: integer
          format: int64
        trade_amount:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        trade_fee:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        trade_id:
          type: string
        trade_price:
          description: >-
            Decimal string of the human value (e.g. `"1.5"`), up to 12
            fractional digits; a string or JSON number is accepted
          type: string
          format: decimal
        tx_hash:
          type:
            - string
            - 'null'
        tx_status:
          $ref: '#/components/schemas/TxStatus'
    CancelReason:
      type: string
      enum:
        - ''
        - user_request
        - mmp_trigger
        - insufficient_margin
        - signed_max_fee_too_low
        - cancel_on_disconnect
        - ioc_or_market_partial_fill
        - session_key_deregistered
        - subaccount_withdrawn
        - compliance
        - trigger_failed
        - validation_failed
        - algo_completed
    OrderStatus:
      type: string
      enum:
        - open
        - filled
        - rejected
        - cancelled
        - expired
        - untriggered
        - algo_active
    LiquidityRole:
      type: string
      enum:
        - maker
        - taker
    TxStatus:
      oneOf:
        - type: string
          enum:
            - requested
            - pending
            - settled
            - reverted
            - ignored
            - timed_out
        - description: Applied off-chain; not yet included in an on-chain settlement batch.
          type: string
          enum:
            - applied
        - description: Included in a settlement batch and executing.
          type: string
          enum:
            - in_batch
        - description: Settlement proof in progress.
          type: string
          enum:
            - proving
        - description: Settlement transaction broadcast on-chain; awaiting confirmation.
          type: string
          enum:
            - submitted

````

## Related topics

- [Orderbook Trading](/trading/order-types.md)
- [Place a new order](/api-reference/orderbook/place-a-new-order.md)
- [Cancel and resubmit a maker quote atomically](/api-reference/rfq/cancel-and-resubmit-a-maker-quote-atomically.md)
