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.
curl --request POST \
--url https://api.derive.xyz/v3/private/replace \
--header 'Content-Type: application/json' \
--data '
{
"amount": "<string>",
"instrument_name": "<string>",
"limit_price": "<string>",
"max_fee": "<string>",
"nonce": "<string>",
"signature": "<string>",
"signature_expiry_sec": 123,
"signer": "<string>",
"subaccount_id": 123,
"algo_duration_sec": null,
"algo_num_slices": null,
"algo_type": "twap",
"client": null,
"expected_filled_amount": null,
"extra_fee": null,
"is_atomic_signing": null,
"label": null,
"mmp": null,
"nonce_to_cancel": null,
"order_id_to_cancel": null,
"order_type": "limit",
"reduce_only": null,
"referral_code": null,
"reject_post_only": null,
"reject_timestamp": null,
"time_in_force": "gtc",
"trigger_price": null
}
'import requests
url = "https://api.derive.xyz/v3/private/replace"
payload = {
"amount": "<string>",
"instrument_name": "<string>",
"limit_price": "<string>",
"max_fee": "<string>",
"nonce": "<string>",
"signature": "<string>",
"signature_expiry_sec": 123,
"signer": "<string>",
"subaccount_id": 123,
"algo_duration_sec": None,
"algo_num_slices": None,
"algo_type": "twap",
"client": None,
"expected_filled_amount": None,
"extra_fee": None,
"is_atomic_signing": None,
"label": None,
"mmp": None,
"nonce_to_cancel": None,
"order_id_to_cancel": None,
"order_type": "limit",
"reduce_only": None,
"referral_code": None,
"reject_post_only": None,
"reject_timestamp": None,
"time_in_force": "gtc",
"trigger_price": None
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
amount: '<string>',
instrument_name: '<string>',
limit_price: '<string>',
max_fee: '<string>',
nonce: '<string>',
signature: '<string>',
signature_expiry_sec: 123,
signer: '<string>',
subaccount_id: 123,
algo_duration_sec: null,
algo_num_slices: null,
algo_type: 'twap',
client: null,
expected_filled_amount: null,
extra_fee: null,
is_atomic_signing: null,
label: null,
mmp: null,
nonce_to_cancel: null,
order_id_to_cancel: null,
order_type: 'limit',
reduce_only: null,
referral_code: null,
reject_post_only: null,
reject_timestamp: null,
time_in_force: 'gtc',
trigger_price: null
})
};
fetch('https://api.derive.xyz/v3/private/replace', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.derive.xyz/v3/private/replace",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount' => '<string>',
'instrument_name' => '<string>',
'limit_price' => '<string>',
'max_fee' => '<string>',
'nonce' => '<string>',
'signature' => '<string>',
'signature_expiry_sec' => 123,
'signer' => '<string>',
'subaccount_id' => 123,
'algo_duration_sec' => null,
'algo_num_slices' => null,
'algo_type' => 'twap',
'client' => null,
'expected_filled_amount' => null,
'extra_fee' => null,
'is_atomic_signing' => null,
'label' => null,
'mmp' => null,
'nonce_to_cancel' => null,
'order_id_to_cancel' => null,
'order_type' => 'limit',
'reduce_only' => null,
'referral_code' => null,
'reject_post_only' => null,
'reject_timestamp' => null,
'time_in_force' => 'gtc',
'trigger_price' => null
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.derive.xyz/v3/private/replace"
payload := strings.NewReader("{\n \"amount\": \"<string>\",\n \"instrument_name\": \"<string>\",\n \"limit_price\": \"<string>\",\n \"max_fee\": \"<string>\",\n \"nonce\": \"<string>\",\n \"signature\": \"<string>\",\n \"signature_expiry_sec\": 123,\n \"signer\": \"<string>\",\n \"subaccount_id\": 123,\n \"algo_duration_sec\": null,\n \"algo_num_slices\": null,\n \"algo_type\": \"twap\",\n \"client\": null,\n \"expected_filled_amount\": null,\n \"extra_fee\": null,\n \"is_atomic_signing\": null,\n \"label\": null,\n \"mmp\": null,\n \"nonce_to_cancel\": null,\n \"order_id_to_cancel\": null,\n \"order_type\": \"limit\",\n \"reduce_only\": null,\n \"referral_code\": null,\n \"reject_post_only\": null,\n \"reject_timestamp\": null,\n \"time_in_force\": \"gtc\",\n \"trigger_price\": null\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.derive.xyz/v3/private/replace")
.header("Content-Type", "application/json")
.body("{\n \"amount\": \"<string>\",\n \"instrument_name\": \"<string>\",\n \"limit_price\": \"<string>\",\n \"max_fee\": \"<string>\",\n \"nonce\": \"<string>\",\n \"signature\": \"<string>\",\n \"signature_expiry_sec\": 123,\n \"signer\": \"<string>\",\n \"subaccount_id\": 123,\n \"algo_duration_sec\": null,\n \"algo_num_slices\": null,\n \"algo_type\": \"twap\",\n \"client\": null,\n \"expected_filled_amount\": null,\n \"extra_fee\": null,\n \"is_atomic_signing\": null,\n \"label\": null,\n \"mmp\": null,\n \"nonce_to_cancel\": null,\n \"order_id_to_cancel\": null,\n \"order_type\": \"limit\",\n \"reduce_only\": null,\n \"referral_code\": null,\n \"reject_post_only\": null,\n \"reject_timestamp\": null,\n \"time_in_force\": \"gtc\",\n \"trigger_price\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.derive.xyz/v3/private/replace")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": \"<string>\",\n \"instrument_name\": \"<string>\",\n \"limit_price\": \"<string>\",\n \"max_fee\": \"<string>\",\n \"nonce\": \"<string>\",\n \"signature\": \"<string>\",\n \"signature_expiry_sec\": 123,\n \"signer\": \"<string>\",\n \"subaccount_id\": 123,\n \"algo_duration_sec\": null,\n \"algo_num_slices\": null,\n \"algo_type\": \"twap\",\n \"client\": null,\n \"expected_filled_amount\": null,\n \"extra_fee\": null,\n \"is_atomic_signing\": null,\n \"label\": null,\n \"mmp\": null,\n \"nonce_to_cancel\": null,\n \"order_id_to_cancel\": null,\n \"order_type\": \"limit\",\n \"reduce_only\": null,\n \"referral_code\": null,\n \"reject_post_only\": null,\n \"reject_timestamp\": null,\n \"time_in_force\": \"gtc\",\n \"trigger_price\": null\n}"
response = http.request(request)
puts response.read_body{
"cancelled_order": {
"amount": "<string>",
"average_price": "<string>",
"creation_timestamp": 123,
"extra_fee": "<string>",
"filled_amount": "<string>",
"instrument_name": "<string>",
"is_transfer": true,
"last_update_timestamp": 123,
"limit_price": "<string>",
"max_fee": "<string>",
"mmp": true,
"nonce": "<string>",
"order_fee": "<string>",
"order_id": "<string>",
"quote_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"replaced_order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"signature": "<string>",
"signature_expiry_sec": 123,
"signed_limit_price": "<string>",
"signer": "<string>",
"subaccount_id": 123,
"trigger_price": "<string>",
"algo_duration_sec": 123,
"algo_num_slices": 123,
"algo_slices_completed": 123,
"algo_type": "twap",
"cancel_reason": "",
"label": "",
"trigger_reject_message": "<string>"
},
"create_order_error": {
"code": 123,
"message": "<string>",
"data": "<string>"
},
"order": {
"amount": "<string>",
"average_price": "<string>",
"creation_timestamp": 123,
"extra_fee": "<string>",
"filled_amount": "<string>",
"instrument_name": "<string>",
"is_transfer": true,
"last_update_timestamp": 123,
"limit_price": "<string>",
"max_fee": "<string>",
"mmp": true,
"nonce": "<string>",
"order_fee": "<string>",
"order_id": "<string>",
"quote_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"replaced_order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"signature": "<string>",
"signature_expiry_sec": 123,
"signed_limit_price": "<string>",
"signer": "<string>",
"subaccount_id": 123,
"trigger_price": "<string>",
"algo_duration_sec": 123,
"algo_num_slices": 123,
"algo_slices_completed": 123,
"algo_type": "twap",
"cancel_reason": "",
"label": "",
"trigger_reject_message": "<string>"
},
"trades": null
}Body
private/replace parameters: a private/order payload plus the cancel-target fields (order_id_to_cancel, nonce_to_cancel, expected_filled_amount).
Order amount in units of the base, as a decimal string (e.g. "1.5") or a JSON number.
buy, sell Limit price in quote currency, as a decimal string (e.g. "3100.5") or a JSON number.
Max fee per unit of volume in quote currency, as a decimal string or a JSON number.
twap 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
Optional extra fee per unit of volume, as a decimal string or JSON number. Defaults to zero.
Optional UUID v4 string
limit, market gtc, post_only, fok, ioc Trigger price as a decimal string or JSON number; omit for non-trigger orders.
mark, index stoploss, takeprofit curl --request POST \
--url https://api.derive.xyz/v3/private/replace \
--header 'Content-Type: application/json' \
--data '
{
"amount": "<string>",
"instrument_name": "<string>",
"limit_price": "<string>",
"max_fee": "<string>",
"nonce": "<string>",
"signature": "<string>",
"signature_expiry_sec": 123,
"signer": "<string>",
"subaccount_id": 123,
"algo_duration_sec": null,
"algo_num_slices": null,
"algo_type": "twap",
"client": null,
"expected_filled_amount": null,
"extra_fee": null,
"is_atomic_signing": null,
"label": null,
"mmp": null,
"nonce_to_cancel": null,
"order_id_to_cancel": null,
"order_type": "limit",
"reduce_only": null,
"referral_code": null,
"reject_post_only": null,
"reject_timestamp": null,
"time_in_force": "gtc",
"trigger_price": null
}
'import requests
url = "https://api.derive.xyz/v3/private/replace"
payload = {
"amount": "<string>",
"instrument_name": "<string>",
"limit_price": "<string>",
"max_fee": "<string>",
"nonce": "<string>",
"signature": "<string>",
"signature_expiry_sec": 123,
"signer": "<string>",
"subaccount_id": 123,
"algo_duration_sec": None,
"algo_num_slices": None,
"algo_type": "twap",
"client": None,
"expected_filled_amount": None,
"extra_fee": None,
"is_atomic_signing": None,
"label": None,
"mmp": None,
"nonce_to_cancel": None,
"order_id_to_cancel": None,
"order_type": "limit",
"reduce_only": None,
"referral_code": None,
"reject_post_only": None,
"reject_timestamp": None,
"time_in_force": "gtc",
"trigger_price": None
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
amount: '<string>',
instrument_name: '<string>',
limit_price: '<string>',
max_fee: '<string>',
nonce: '<string>',
signature: '<string>',
signature_expiry_sec: 123,
signer: '<string>',
subaccount_id: 123,
algo_duration_sec: null,
algo_num_slices: null,
algo_type: 'twap',
client: null,
expected_filled_amount: null,
extra_fee: null,
is_atomic_signing: null,
label: null,
mmp: null,
nonce_to_cancel: null,
order_id_to_cancel: null,
order_type: 'limit',
reduce_only: null,
referral_code: null,
reject_post_only: null,
reject_timestamp: null,
time_in_force: 'gtc',
trigger_price: null
})
};
fetch('https://api.derive.xyz/v3/private/replace', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.derive.xyz/v3/private/replace",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount' => '<string>',
'instrument_name' => '<string>',
'limit_price' => '<string>',
'max_fee' => '<string>',
'nonce' => '<string>',
'signature' => '<string>',
'signature_expiry_sec' => 123,
'signer' => '<string>',
'subaccount_id' => 123,
'algo_duration_sec' => null,
'algo_num_slices' => null,
'algo_type' => 'twap',
'client' => null,
'expected_filled_amount' => null,
'extra_fee' => null,
'is_atomic_signing' => null,
'label' => null,
'mmp' => null,
'nonce_to_cancel' => null,
'order_id_to_cancel' => null,
'order_type' => 'limit',
'reduce_only' => null,
'referral_code' => null,
'reject_post_only' => null,
'reject_timestamp' => null,
'time_in_force' => 'gtc',
'trigger_price' => null
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.derive.xyz/v3/private/replace"
payload := strings.NewReader("{\n \"amount\": \"<string>\",\n \"instrument_name\": \"<string>\",\n \"limit_price\": \"<string>\",\n \"max_fee\": \"<string>\",\n \"nonce\": \"<string>\",\n \"signature\": \"<string>\",\n \"signature_expiry_sec\": 123,\n \"signer\": \"<string>\",\n \"subaccount_id\": 123,\n \"algo_duration_sec\": null,\n \"algo_num_slices\": null,\n \"algo_type\": \"twap\",\n \"client\": null,\n \"expected_filled_amount\": null,\n \"extra_fee\": null,\n \"is_atomic_signing\": null,\n \"label\": null,\n \"mmp\": null,\n \"nonce_to_cancel\": null,\n \"order_id_to_cancel\": null,\n \"order_type\": \"limit\",\n \"reduce_only\": null,\n \"referral_code\": null,\n \"reject_post_only\": null,\n \"reject_timestamp\": null,\n \"time_in_force\": \"gtc\",\n \"trigger_price\": null\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.derive.xyz/v3/private/replace")
.header("Content-Type", "application/json")
.body("{\n \"amount\": \"<string>\",\n \"instrument_name\": \"<string>\",\n \"limit_price\": \"<string>\",\n \"max_fee\": \"<string>\",\n \"nonce\": \"<string>\",\n \"signature\": \"<string>\",\n \"signature_expiry_sec\": 123,\n \"signer\": \"<string>\",\n \"subaccount_id\": 123,\n \"algo_duration_sec\": null,\n \"algo_num_slices\": null,\n \"algo_type\": \"twap\",\n \"client\": null,\n \"expected_filled_amount\": null,\n \"extra_fee\": null,\n \"is_atomic_signing\": null,\n \"label\": null,\n \"mmp\": null,\n \"nonce_to_cancel\": null,\n \"order_id_to_cancel\": null,\n \"order_type\": \"limit\",\n \"reduce_only\": null,\n \"referral_code\": null,\n \"reject_post_only\": null,\n \"reject_timestamp\": null,\n \"time_in_force\": \"gtc\",\n \"trigger_price\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.derive.xyz/v3/private/replace")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": \"<string>\",\n \"instrument_name\": \"<string>\",\n \"limit_price\": \"<string>\",\n \"max_fee\": \"<string>\",\n \"nonce\": \"<string>\",\n \"signature\": \"<string>\",\n \"signature_expiry_sec\": 123,\n \"signer\": \"<string>\",\n \"subaccount_id\": 123,\n \"algo_duration_sec\": null,\n \"algo_num_slices\": null,\n \"algo_type\": \"twap\",\n \"client\": null,\n \"expected_filled_amount\": null,\n \"extra_fee\": null,\n \"is_atomic_signing\": null,\n \"label\": null,\n \"mmp\": null,\n \"nonce_to_cancel\": null,\n \"order_id_to_cancel\": null,\n \"order_type\": \"limit\",\n \"reduce_only\": null,\n \"referral_code\": null,\n \"reject_post_only\": null,\n \"reject_timestamp\": null,\n \"time_in_force\": \"gtc\",\n \"trigger_price\": null\n}"
response = http.request(request)
puts response.read_body{
"cancelled_order": {
"amount": "<string>",
"average_price": "<string>",
"creation_timestamp": 123,
"extra_fee": "<string>",
"filled_amount": "<string>",
"instrument_name": "<string>",
"is_transfer": true,
"last_update_timestamp": 123,
"limit_price": "<string>",
"max_fee": "<string>",
"mmp": true,
"nonce": "<string>",
"order_fee": "<string>",
"order_id": "<string>",
"quote_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"replaced_order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"signature": "<string>",
"signature_expiry_sec": 123,
"signed_limit_price": "<string>",
"signer": "<string>",
"subaccount_id": 123,
"trigger_price": "<string>",
"algo_duration_sec": 123,
"algo_num_slices": 123,
"algo_slices_completed": 123,
"algo_type": "twap",
"cancel_reason": "",
"label": "",
"trigger_reject_message": "<string>"
},
"create_order_error": {
"code": 123,
"message": "<string>",
"data": "<string>"
},
"order": {
"amount": "<string>",
"average_price": "<string>",
"creation_timestamp": 123,
"extra_fee": "<string>",
"filled_amount": "<string>",
"instrument_name": "<string>",
"is_transfer": true,
"last_update_timestamp": 123,
"limit_price": "<string>",
"max_fee": "<string>",
"mmp": true,
"nonce": "<string>",
"order_fee": "<string>",
"order_id": "<string>",
"quote_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"replaced_order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"signature": "<string>",
"signature_expiry_sec": 123,
"signed_limit_price": "<string>",
"signer": "<string>",
"subaccount_id": 123,
"trigger_price": "<string>",
"algo_duration_sec": 123,
"algo_num_slices": 123,
"algo_slices_completed": 123,
"algo_type": "twap",
"cancel_reason": "",
"label": "",
"trigger_reject_message": "<string>"
},
"trades": null
}