Cancel All Orders (WebSocket)
Cancel all open orders for specific market(s), or all markets with the wildcard symbol, through the WebSocket connection.
Action Result Notifications
This method executes cancellations immediately. Cancellation events are automatically sent via SubAccount Updates Subscription if subscribed.
Endpoint
ws.send() wss://api.synthetix.io/v1/ws/tradeRequest
Request Format
{
"id": "cancelall-1",
"method": "post",
"params": {
"action": "cancelAllOrders",
"subAccountId": "1867542890123456789",
"symbols": ["BTC-USDT", "ETH-USDT"],
"source": "direct",
"nonce": 1704067200000,
"expiresAfter": 1704067300,
"signature": {
"v": 28,
"r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
}
}
}Parameters
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Client-generated unique request identifier |
method | string | Yes | Must be "post" |
params | object | Yes | Contains all parameters for the request |
Params Object
| Parameter | Type | Required | Description |
|---|---|---|---|
action | string | Yes | Must be "cancelAllOrders" |
subAccountId | string | Yes | SubAccount ID to cancel orders for |
symbols | array | Yes | Array of symbols to cancel. Use ["*"] to cancel across all markets. [] is rejected. ["*", "ETH-USDT"] is rejected |
source | string | No | Request source identifier for tracking and rebates (max 100 characters). Use "direct" for generic integrations |
nonce | integer | Yes | Positive integer, incrementing nonce |
expiresAfter | integer | No | Optional expiration Unix timestamp in seconds (0 = no expiration) |
signature | object | Yes | EIP-712 signature with v, r, s components |
EIP-712 Signature
const domain = {
name: "Synthetix",
version: "1",
chainId: 1,
verifyingContract: "0x0000000000000000000000000000000000000000"
};
const types = {
CancelAllOrders: [
{ name: "subAccountId", type: "uint256" },
{ name: "symbols", type: "string[]" },
{ name: "nonce", type: "uint256" },
{ name: "expiresAfter", type: "uint256" }
]
};
const message = {
subAccountId: "1867542890123456789",
symbols: ["BTC-USDT", "ETH-USDT"],
nonce: Date.now(),
expiresAfter: 0
};
const signature = await signer._signTypedData(domain, types, message);Wildcard Rules for symbols
["*"]: Cancel all open orders across all markets["BTC-USDT", "ETH-USDT"]: Cancel only those markets[]: Rejected["*", "ETH-USDT"]: Rejected (wildcard must be used alone)
Response Format
Success Response
{
"id": "cancelall-1",
"status": 200,
"result": {
"status": "success",
"response": [
{
"order": {
"venueId": "1958787130134106112",
"clientId": "cli-1958787130134106112"
},
"orderId": "1958787130134106112",
"message": "",
"symbol": "BTC-USDT"
},
{
"order": {
"venueId": "1958787130134106113",
"clientId": "cli-1958787130134106113"
},
"orderId": "1958787130134106113",
"message": "",
"symbol": "ETH-USDT"
}
]
}
}Empty Result (No Orders to Cancel)
{
"id": "cancelall-1",
"status": 200,
"result": {
"status": "success",
"response": []
}
}Error Response
{
"id": "cancelall-1",
"status": 400,
"result": null,
"error": {
"code": 400,
"message": "Invalid request parameters"
}
}Code Examples
Migration Note: Use order.venueId as canonical in cancellation responses. orderId is deprecated compatibility output.
The message field contains an error description when cancellation fails for a specific order, and is empty on success. Do not treat a non-empty message as a success confirmation.
Cancel Orders for Specific Markets
{
"id": "cancelall-markets",
"method": "post",
"params": {
"action": "cancelAllOrders",
"subAccountId": "1867542890123456789",
"symbols": ["BTC-USDT", "ETH-USDT"],
"nonce": 1704067200000,
"expiresAfter": 1704067300,
"signature": {
"v": 28,
"r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
}
}
}Cancel Orders for All Markets
{
"id": "cancelall-all",
"method": "post",
"params": {
"action": "cancelAllOrders",
"subAccountId": "1867542890123456789",
"symbols": ["*"],
"nonce": 1704067200000,
"expiresAfter": 1704067300,
"signature": {
"v": 28,
"r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
}
}
}Cancel Orders for Single Market
{
"id": "cancelall-btc",
"method": "post",
"params": {
"action": "cancelAllOrders",
"subAccountId": "1867542890123456789",
"symbols": ["BTC-USDT"],
"nonce": 1704067200000,
"expiresAfter": 1704067300,
"signature": {
"v": 28,
"r": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"s": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
}
}
}Implementation Example
class OrderCancellation {
constructor(ws, signer) {
this.ws = ws;
this.signer = signer;
this.pendingRequests = new Map();
}
async cancelAllOrders(subAccountId, symbols) {
if (!symbols || symbols.length === 0) {
throw new Error('symbols array must contain at least one market symbol');
}
if (symbols.includes('*') && symbols.length > 1) {
throw new Error('wildcard "*" must be used alone as ["*"]');
}
const nonce = Date.now();
const expiresAfter = Math.floor(Date.now() / 1000) + 30; // 30 seconds from now (Unix seconds)
// Create EIP-712 signature
const signature = await this.signCancelAllOrders({
subAccountId,
symbols,
nonce,
expiresAfter
});
const request = {
id: `cancelall-${Date.now()}`,
method: "post",
params: {
action: "cancelAllOrders",
subAccountId,
symbols,
nonce,
expiresAfter,
signature
}
};
return this.sendRequest(request);
}
async signCancelAllOrders({ subAccountId, symbols, nonce, expiresAfter }) {
const domain = {
name: "Synthetix",
version: "1",
chainId: 1,
verifyingContract: "0x0000000000000000000000000000000000000000"
};
const types = {
CancelAllOrders: [
{ name: "subAccountId", type: "uint256" },
{ name: "symbols", type: "string[]" },
{ name: "nonce", type: "uint256" },
{ name: "expiresAfter", type: "uint256" }
]
};
const message = {
subAccountId,
symbols,
nonce,
expiresAfter
};
const signature = await this.signer._signTypedData(domain, types, message);
const { v, r, s } = ethers.utils.splitSignature(signature);
return { v, r, s };
}
sendRequest(request) {
return new Promise((resolve, reject) => {
this.pendingRequests.set(request.id, { resolve, reject });
this.ws.send(JSON.stringify(request));
setTimeout(() => {
if (this.pendingRequests.has(request.id)) {
this.pendingRequests.delete(request.id);
reject(new Error('Request timeout'));
}
}, 10000);
});
}
handleResponse(response) {
const pending = this.pendingRequests.get(response.id);
if (pending) {
this.pendingRequests.delete(response.id);
if (response.error) {
pending.reject(new Error(response.error.message));
} else {
pending.resolve(response.result);
}
}
}
}
// Usage Examples
// Cancel all orders for specific markets
async function cancelByMarkets(cancellation, subAccountId, symbols) {
try {
const result = await cancellation.cancelAllOrders(subAccountId, symbols);
console.log(`Cancelled ${result.response.length} orders in ${symbols.join(', ')}`);
return result;
} catch (error) {
console.error('Cancel by markets failed:', error);
throw error;
}
}
// Cancel all BTC orders
async function cancelAllBtcOrders(cancellation, subAccountId) {
return cancelByMarkets(cancellation, subAccountId, ['BTC-USDT']);
}Cancel Behavior
- Immediate Effect: Orders are cancelled immediately upon validation
- Margin Release: Freed margin becomes available instantly
- Partial Fills: Partially filled orders are cancelled for remaining quantity
- All Order Types: Cancels limit, market, and trigger orders
- Atomic Operation: All specified orders are cancelled together
Implementation Details
The API performs the following steps:
- Validates that the
symbolsarray contains at least one market - Validates wildcard usage (
*may only appear as["*"]) - Retrieves all open orders for the authenticated subaccount
- Filters orders by the specified symbols (or all when
["*"]is used) - Iterates through each order and attempts to cancel it
- Returns an array of cancellation statuses for each processed order
Implementation Notes
symbolsarray must contain at least one valid market symbolsymbols: ["*"]cancels all markets and wildcard cannot be mixed with other symbols- Market symbols must be valid trading pairs (e.g., "BTC-USDT")
- Authentication timestamps must be strictly increasing per subaccount
- EIP-712 domain separator must use "Synthetix" for WebSocket endpoints
expiresAfteruses Unix seconds (not milliseconds)
Validation Rules
noncemust be a positive integer, incrementing and unique per requestsymbolsarray must contain at least one valid market symbol["*"]cancels all markets and cannot be combined with other symbols[]is invalid- Must be signed by account owner or authorized delegate
- Subaccount ID must be valid and accessible
Signing
All trading methods are signed using EIP-712. Each successful trading request will contain:
- A piece of structured data that includes the sender address
- A signature of the hash of that structured data, signed by the sender
For detailed information on EIP-712 signing, see EIP-712 Signing.
Nonce Management
The nonce system prevents replay attacks and ensures order uniqueness:
- Use any positive integer as nonce
- Each nonce must be greater than the previous one (incrementing)
Date.now()is a convenient option, not a requirement- If nonce conflicts occur, increment by 1 and retry
:::note SubAccountAction Exception
SubAccountAction endpoints (getPositions, getOpenOrders, getOrdersHistory, getTrades, getFundingPayments, getSubAccount, getSubAccounts, getDelegatedSigners, getBalanceUpdates) do not require a nonce. Only the signature and optional expiresAfter parameters are needed.
:::
| Error Code | Description | Retryable |
|---|---|---|
UNAUTHORIZED | EIP-712 signature validation failed | No |
VALIDATION_ERROR | Request validation failed | No |
MISSING_REQUIRED_FIELD | Required field is missing | No |
INVALID_FORMAT | Field format is invalid | No |
INVALID_VALUE | Invalid parameter value | No |
RATE_LIMIT_EXCEEDED | Too many requests in time window | Yes |
INSUFFICIENT_MARGIN | Not enough margin for trade | No |
ORDER_NOT_FOUND | Order does not exist | No |
OPERATION_TIMEOUT | Operation timed out | Yes |
| Error | Description |
|---|---|
| Symbols must be non-empty | symbols array cannot be empty |
| Invalid wildcard usage | * must be used alone as ["*"] |
| Invalid market symbol | Market symbol not recognized |
| No orders found | No open orders to cancel |
| Request expired | expiresAfter timestamp has passed |
Next Steps
- Cancel Orders - Cancel specific orders by ID
- Get Order History - Query order status
- REST Alternative - REST API comparison