Cancel Orders (WebSocket)
Cancel one or more existing orders through the WebSocket connection for fastest order management.
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": "cancel-1",
"method": "post",
"params": {
"action": "cancelOrders",
"orderIds": ["1948058938469519360", "1948058938469519361"],
"nonce": 1704067200000,
"expiresAfter": 1704067300000,
"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 "cancelOrders" |
orderIds | array | Yes | Array of order IDs to cancel |
nonce | integer | Yes | Incrementing nonce (Unix ms timestamp as number) |
expiresAfter | integer | No | Optional expiration timestamp (Unix ms as number) |
signature | object | Yes | EIP-712 signature |
Response Format
Success Response
{
"id": "cancel-1",
"status": 200,
"result": [
{
"canceled": {
"orderId": "1948058938469519360"
}
},
{
"canceled": {
"orderId": "1948058938469519361"
}
}
]
}Error Response
{
"id": "cancel-1",
"status": 404,
"result": null,
"error": {
"code": 404,
"message": "Order not found or does not belong to this subaccount"
}
}Implementation Example
// Cancel single order
const cancelRequest = {
id: "cancel-1",
method: "post",
params: {
action: "cancelOrders",
orderIds: ["1948058938469519360"],
nonce: Date.now(),
expiresAfter: Date.now() + 30000,
signature: await signCancelMessage(...)
}
};
ws.send(JSON.stringify(cancelRequest));
// Cancel multiple orders
const cancelMultiple = {
id: "cancel-2",
method: "post",
params: {
action: "cancelOrders",
orderIds: ["1948058938469519360", "1948058938469519361"],
nonce: Date.now(),
expiresAfter: Date.now() + 30000,
signature: await signCancelMessage(...)
}
};
ws.send(JSON.stringify(cancelMultiple));Implementation Notes
- Cancellation requests must include at least one order ID
- Order IDs must belong to the authenticated subaccount
- Authentication timestamps must be monotonically increasing per subaccount
- EIP-712 domain separator must use "Synthetix" for WebSocket endpoints
Cancellation Behavior
- Only
OPENandPARTIALLY_FILLEDorders can be cancelled - Filled portions of partially filled orders remain executed
- Cancellation is immediate upon validation
- Freed margin becomes available instantly
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 current timestamp in milliseconds as nonce
- Each nonce must be greater than the previous one
- Recommended: Use
Date.now()or equivalent - If nonce conflicts occur, increment by 1 and retry
| Error | Description |
|---|---|
| Invalid signature | EIP-712 signature validation failed |
| Invalid market symbol | Market symbol not recognized |
| Nonce already used | Nonce must be greater than previous value |
| Rate limit exceeded | Too many requests in time window |
| Request expired | expiresAfter timestamp has passed |
Next Steps
- Modify Order - Order modification via WebSocket
- Cancel All Orders - Emergency cancellation
- REST Alternative - REST API comparison