POST Cancel Order
Cancel order by ID
POST /v1/api/accounts/{account}/orders/{orderId}/cancel
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Required | Name of account in NT8 |
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
orderId | string | Required | ID of the order in NT8 |
Code Examples
- Python
- JavaScript
- cURL
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/accounts/Sim101/orders/ce0a8e5002ea463e856eb6384f5cee7e/cancel"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {}
try:
response = requests.post(url, headers=headers, json=data)
print(f"Response Code: {response.status_code}, Response Text: {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
const token = 'my-secret-token';
const url = "https://app.crosstrade.io/v1/api/accounts/Sim101/orders/ce0a8e5002ea463e856eb6384f5cee7e/cancel";
fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({})
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));
TOKEN="my-secret-token"
curl -X POST "https://app.crosstrade.io/v1/api/accounts/Sim101/orders/ce0a8e5002ea463e856eb6384f5cee7e/cancel" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
Response
- 200
- 400 - not found
- 400
{
"orderId": "ce0a8e5002ea463e856eb6384f5cee7e",
"success": true
}
{
"error": "Order linked to 'ce0a8e5002ea463e856eb6384f5cee7e' not found or already terminal."
}
{
"error": "Invalid request"
}
Parsing the not-found error — The "not found or already terminal" string is stable and parseable. Callers can string-match on it to distinguish a gone order from other failure modes, rather than relying on status codes alone.
Order ID note — The orderId returned when you place an order is the NT8-assigned GUID for that order. CrossTrade maintains internal handlers that can always resolve the original GUID you were given, even if NT8 or the broker reassigns the order ID internally. You can use the ID returned at placement time to cancel or look up an order at any point in its lifecycle.
WebSocket API
This request can also be made over the WebSocket API. The account and orderId path parameters are passed inside args.
{
"action": "rpc",
"id": "my-request-id",
"api": "Cancel",
"args": {
"account": "Sim101",
"orderId": "492281fc515e431692da57d957cfebb6"
}
}