---
title: "private/replace"
method: POST
path: "/private/replace"
tags: ["Orderbook"]
---

# private/replace

`POST /private/replace`

## Request

- Base URL: `https://api.derive.xyz/v3`
- URL: `https://api.derive.xyz/v3/private/replace`
- Auth: API key in header `X-DeriveWallet` and API key in header `X-DeriveTimestamp` and API key in header `X-DeriveSignature`

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.

## Request body

- ReplaceOrderRequest: `private/replace` parameters: a `private/order` payload plus the cancel-target fields (`order_id_to_cancel`, `nonce_to_cancel`, `expected_filled_amount`).
  - `algo_duration_sec` integer, nullable
  - `algo_num_slices` integer, nullable
  - `algo_type` 'twap', nullable
  - `amount` string, decimal, required: Order amount in units of the base, as a decimal string (e.g. `"1.5"`) or a JSON number.
  - `client` string, nullable
  - `direction` 'buy' | 'sell', required
  - `expected_filled_amount` string, decimal, nullable: 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
  - `extra_fee` string, decimal, nullable: Optional builder fee for the whole order, in USDC, as a decimal string or JSON number. Each fill pays its pro-rata share. Defaults to zero.
  - `instrument_name` string, required
  - `is_atomic_signing` boolean, nullable
  - `label` string, nullable
  - `limit_price` string, decimal, required: Limit price in quote currency, as a decimal string (e.g. `"3100.5"`) or a JSON number.
  - `max_fee` string, decimal, required: Max fee per unit of volume in quote currency, as a decimal string or a JSON number.
  - `mmp` boolean, nullable: Tags the order for market maker protection. Only tagged orders are cancelled by cancel on disconnect.
  - `nonce` string, required
  - `nonce_to_cancel` string, nullable
  - `order_id_to_cancel` string, uuid, nullable: Optional UUID v4 string
  - `order_type` 'limit' | 'market'
  - `reduce_only` boolean, nullable
  - `referral_code` string, nullable
  - `reject_post_only` boolean, nullable
  - `reject_timestamp` integer, nullable
  - `signature` string, required
  - `signature_expiry_sec` integer, required
  - `signer` string, required
  - `subaccount_id` integer, required
  - `time_in_force` 'gtc' | 'post_only' | 'fok' | 'ioc'
  - `trigger_price` string, decimal, nullable: Trigger price as a decimal string or JSON number; omit for non-trigger orders.
  - `trigger_price_type` 'mark' | 'index', nullable
  - `trigger_type` 'stoploss' | 'takeprofit', nullable

## Response `200`

Success

- ReplaceOrderResponse
  - `cancelled_order` Order, required
    - `algo_duration_sec` integer, nullable
    - `algo_num_slices` integer, nullable
    - `algo_slices_completed` integer, nullable
    - `algo_type` 'twap', nullable
    - `amount` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `average_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `cancel_reason` '' | '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' | 'max_crossed_orders'
    - `creation_timestamp` integer, required
    - `direction` 'buy' | 'sell', required
    - `extra_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `filled_amount` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `instrument_name` string, required
    - `is_transfer` boolean, required
    - `label` string
    - `last_update_timestamp` integer, required
    - `limit_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `max_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `mmp` boolean, required
    - `nonce` string, required
    - `order_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `order_id` string, required
    - `order_status` 'open' | 'filled' | 'rejected' | 'cancelled' | 'expired' | 'untriggered' | 'algo_active', required
    - `order_type` 'limit' | 'market', required
    - `quote_id` string, uuid, nullable, required: Optional UUID v4 string
    - `replaced_order_id` string, uuid, nullable, required: Optional UUID v4 string
    - `signature` string, required
    - `signature_expiry_sec` integer, required
    - `signed_limit_price` string, decimal, nullable, required: 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
    - `signer` string, required
    - `subaccount_id` integer, required
    - `time_in_force` 'gtc' | 'post_only' | 'fok' | 'ioc', required
    - `trigger_price` string, decimal, nullable, required: 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
    - `trigger_price_type` 'mark' | 'index', nullable
    - `trigger_reject_message` string, nullable
    - `trigger_type` 'stoploss' | 'takeprofit', nullable
  - `create_order_error` RPCError, nullable
    - `code` integer, required
    - `data` string, nullable
    - `message` string, required
  - `order` Order, nullable
    - `algo_duration_sec` integer, nullable
    - `algo_num_slices` integer, nullable
    - `algo_slices_completed` integer, nullable
    - `algo_type` 'twap', nullable
    - `amount` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `average_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `cancel_reason` '' | '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' | 'max_crossed_orders'
    - `creation_timestamp` integer, required
    - `direction` 'buy' | 'sell', required
    - `extra_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `filled_amount` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `instrument_name` string, required
    - `is_transfer` boolean, required
    - `label` string
    - `last_update_timestamp` integer, required
    - `limit_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `max_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `mmp` boolean, required
    - `nonce` string, required
    - `order_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `order_id` string, required
    - `order_status` 'open' | 'filled' | 'rejected' | 'cancelled' | 'expired' | 'untriggered' | 'algo_active', required
    - `order_type` 'limit' | 'market', required
    - `quote_id` string, uuid, nullable, required: Optional UUID v4 string
    - `replaced_order_id` string, uuid, nullable, required: Optional UUID v4 string
    - `signature` string, required
    - `signature_expiry_sec` integer, required
    - `signed_limit_price` string, decimal, nullable, required: 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
    - `signer` string, required
    - `subaccount_id` integer, required
    - `time_in_force` 'gtc' | 'post_only' | 'fok' | 'ioc', required
    - `trigger_price` string, decimal, nullable, required: 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
    - `trigger_price_type` 'mark' | 'index', nullable
    - `trigger_reject_message` string, nullable
    - `trigger_type` 'stoploss' | 'takeprofit', nullable
  - `trades` Trade[], nullable
    - `batch_status` 'Batching' | 'Executing' | 'Da' | 'Proving' | 'Settling' | 'Settled' | 'BatchingError' | 'ExecutingError' | 'DaError' | 'ProvingError' | 'SettlingError' | 'SettledError', nullable: Batch lifecycle status — the single source of lifecycle truth for every operation in the batch (individual ops carry no status of their own). Each stage has a healthy variant and a corresponding `...Error` variant meaning that stage failed. Serialized as the variant name (string) in API responses.
    - `block_trade_id` string, uuid, nullable, required: Optional UUID v4 string
    - `direction` 'buy' | 'sell', required
    - `expected_rebate` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `extra_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `index_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `instrument_name` string, required
    - `is_transfer` boolean, required
    - `label` string
    - `liquidity_role` 'maker' | 'taker', required
    - `mark_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `op_uuid` string, required
    - `order_id` string, required
    - `quote_id` string, uuid, nullable, required: Optional UUID v4 string
    - `realized_pnl` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `realized_pnl_excl_fees` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `rfq_id` string, uuid, nullable, required: Optional UUID v4 string
    - `subaccount_id` integer, required
    - `timestamp` integer, required
    - `trade_amount` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `trade_fee` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `trade_id` string, required
    - `trade_price` string, decimal, required: Decimal string of the human value (e.g. `"1.5"`), up to 12 fractional digits; a string or JSON number is accepted
    - `tx_hash` string, nullable

## Other responses

- `default`: JSON-RPC error (see Error Codes)

## Changes

- **2026-11-12** `1daf38a69a7a`: 1 info
  - added the required property `trades/items/block_trade_id` to the response with the `200` status
- **2026-10-20** `0c500202be49`: 2 info
  - the endpoint scheme security `DeriveWallet AND DeriveTimestamp AND DeriveSignature` was added to the API
  - added the media type `application/json` for the response with the status `default`
- **2026-10-14** `bbc792e18f1a`: 2 warning
  - added the new `max_crossed_orders` enum value to the `cancelled_order/cancel_reason` response property for the response status `200`
  - added the new `max_crossed_orders` enum value to the `order/anyOf[#/components/schemas/Order]/cancel_reason` response property for the response status `200`

[Operation history](https://skmtc.dev/lyra/apis/derive-v3-api/changes/private/replace/post.md)

---

[API](https://skmtc.dev/lyra/apis/derive-v3-api.md) - [All operations](https://skmtc.dev/lyra/apis/derive-v3-api/llms.txt) - [OpenAPI document](https://skmtc.dev/lyra/apis/derive-v3-api/revisions/415f8a73b10c?raw)
