private/batch_order
Places, replaces and cancels orders for one subaccount in a single request. orders holds post-only limit orders and cancels holds open orders to cancel, each by order_id and instrument_name; together they hold 1 to 1000 items. Each order is a signed private/order payload; an order that also sets order_id_to_cancel or nonce_to_cancel replaces that open order, which must be on the same instrument. Every order must use the batch subaccount_id, the same signer, time_in_force post_only and order_type limit, with no trigger or algo fields, reduce_only or is_atomic_signing. The batch is checked as a whole first, including margin for all of its orders together; open orders that it cancels or replaces do not count. If a check fails, no order is placed or cancelled, and the error data names the failing order as index=<n> or the failing cancel as cancel index=<n>. A batch of cancels alone has no margin check. Otherwise, on each instrument the cancels apply before the orders. Returns one result per order with its nonce, order_id, status (open, rejected with its error, or pending if it had no result yet), final limit_price and cancelled_order_id, and one result per cancel with its order_id and status (cancelled, rejected with its error, or pending). A cancel of an order that is not open on the named instrument is rejected and does not affect the rest of the batch. A replace cancels its old order even when the new order is then rejected. A batch costs 50 matching rate-limit points, whatever its size. A batch refused for lack of points costs nothing. Requires Orderbook trade scope for the instrument of every order; a batch of cancels alone requires any trade scope.
curl --request POST \
--url https://api.derive.xyz/v3/private/batch_order \
--header 'Content-Type: application/json' \
--header 'X-DeriveSignature: <api-key>' \
--header 'X-DeriveTimestamp: <api-key>' \
--header 'X-DeriveWallet: <api-key>' \
--data '
{
"subaccount_id": 123,
"cancels": [
{
"instrument_name": "<string>",
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"orders": [
{
"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/batch_order"
payload = {
"subaccount_id": 123,
"cancels": [
{
"instrument_name": "<string>",
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"orders": [
{
"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 = {
"X-DeriveWallet": "<api-key>",
"X-DeriveTimestamp": "<api-key>",
"X-DeriveSignature": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-DeriveWallet': '<api-key>',
'X-DeriveTimestamp': '<api-key>',
'X-DeriveSignature': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
subaccount_id: 123,
cancels: [
{instrument_name: '<string>', order_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'}
],
orders: [
{
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/batch_order', 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/batch_order",
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([
'subaccount_id' => 123,
'cancels' => [
[
'instrument_name' => '<string>',
'order_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
],
'orders' => [
[
'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",
"X-DeriveSignature: <api-key>",
"X-DeriveTimestamp: <api-key>",
"X-DeriveWallet: <api-key>"
],
]);
$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/batch_order"
payload := strings.NewReader("{\n \"subaccount_id\": 123,\n \"cancels\": [\n {\n \"instrument_name\": \"<string>\",\n \"order_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n }\n ],\n \"orders\": [\n {\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 }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-DeriveWallet", "<api-key>")
req.Header.Add("X-DeriveTimestamp", "<api-key>")
req.Header.Add("X-DeriveSignature", "<api-key>")
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/batch_order")
.header("X-DeriveWallet", "<api-key>")
.header("X-DeriveTimestamp", "<api-key>")
.header("X-DeriveSignature", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"subaccount_id\": 123,\n \"cancels\": [\n {\n \"instrument_name\": \"<string>\",\n \"order_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n }\n ],\n \"orders\": [\n {\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 }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.derive.xyz/v3/private/batch_order")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-DeriveWallet"] = '<api-key>'
request["X-DeriveTimestamp"] = '<api-key>'
request["X-DeriveSignature"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"subaccount_id\": 123,\n \"cancels\": [\n {\n \"instrument_name\": \"<string>\",\n \"order_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n }\n ],\n \"orders\": [\n {\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 }\n ]\n}"
response = http.request(request)
puts response.read_body{
"cancels": [
{
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "cancelled",
"error": {
"code": 123,
"message": "<string>",
"data": "<string>"
}
}
],
"orders": [
{
"cancelled_order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"limit_price": "<string>",
"nonce": "<string>",
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "open",
"error": {
"code": 123,
"message": "<string>",
"data": "<string>"
}
}
]
}{
"error": {
"code": 123,
"message": "<string>",
"data": "<string>"
}
}Authorizations
Body
private/batch_order params.
curl --request POST \
--url https://api.derive.xyz/v3/private/batch_order \
--header 'Content-Type: application/json' \
--header 'X-DeriveSignature: <api-key>' \
--header 'X-DeriveTimestamp: <api-key>' \
--header 'X-DeriveWallet: <api-key>' \
--data '
{
"subaccount_id": 123,
"cancels": [
{
"instrument_name": "<string>",
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"orders": [
{
"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/batch_order"
payload = {
"subaccount_id": 123,
"cancels": [
{
"instrument_name": "<string>",
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"orders": [
{
"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 = {
"X-DeriveWallet": "<api-key>",
"X-DeriveTimestamp": "<api-key>",
"X-DeriveSignature": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-DeriveWallet': '<api-key>',
'X-DeriveTimestamp': '<api-key>',
'X-DeriveSignature': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
subaccount_id: 123,
cancels: [
{instrument_name: '<string>', order_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'}
],
orders: [
{
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/batch_order', 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/batch_order",
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([
'subaccount_id' => 123,
'cancels' => [
[
'instrument_name' => '<string>',
'order_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
],
'orders' => [
[
'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",
"X-DeriveSignature: <api-key>",
"X-DeriveTimestamp: <api-key>",
"X-DeriveWallet: <api-key>"
],
]);
$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/batch_order"
payload := strings.NewReader("{\n \"subaccount_id\": 123,\n \"cancels\": [\n {\n \"instrument_name\": \"<string>\",\n \"order_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n }\n ],\n \"orders\": [\n {\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 }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-DeriveWallet", "<api-key>")
req.Header.Add("X-DeriveTimestamp", "<api-key>")
req.Header.Add("X-DeriveSignature", "<api-key>")
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/batch_order")
.header("X-DeriveWallet", "<api-key>")
.header("X-DeriveTimestamp", "<api-key>")
.header("X-DeriveSignature", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"subaccount_id\": 123,\n \"cancels\": [\n {\n \"instrument_name\": \"<string>\",\n \"order_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n }\n ],\n \"orders\": [\n {\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 }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.derive.xyz/v3/private/batch_order")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-DeriveWallet"] = '<api-key>'
request["X-DeriveTimestamp"] = '<api-key>'
request["X-DeriveSignature"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"subaccount_id\": 123,\n \"cancels\": [\n {\n \"instrument_name\": \"<string>\",\n \"order_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n }\n ],\n \"orders\": [\n {\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 }\n ]\n}"
response = http.request(request)
puts response.read_body{
"cancels": [
{
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "cancelled",
"error": {
"code": 123,
"message": "<string>",
"data": "<string>"
}
}
],
"orders": [
{
"cancelled_order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"limit_price": "<string>",
"nonce": "<string>",
"order_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "open",
"error": {
"code": 123,
"message": "<string>",
"data": "<string>"
}
}
]
}{
"error": {
"code": 123,
"message": "<string>",
"data": "<string>"
}
}