POST Cancel and Bracket
- NT8
- Tradovate
Cancel and Bracket NT8
Cancel all working orders on an instrument and immediately place new OCO bracket orders (take profit and stop loss) to protect an existing position. This is an atomic operation designed for algo workflows that need to replace protective orders without leaving the position exposed.
Endpoint
POST /v1/api/accounts/{account}/orders/cancel_and_bracket
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Required | Account name in NT8 |
Body parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Required | Instrument name (e.g., "ES 09-26") |
action | string | Required | Direction of the position being protected: Buy or Sell |
quantity | int | Required | Number of contracts for each bracket leg |
takeProfit | number | Optional | Limit price for the take profit order |
stopLoss | number | Optional | Stop price for the stop loss order |
ocoId | string | Optional | Custom OCO ID. If omitted, one is generated automatically |
At least one of takeProfit or stopLoss must be provided, or no orders will be placed.
Code examples
- Python
- JavaScript
- cURL
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/accounts/Sim101/orders/cancel_and_bracket"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {
"instrument": "ES 09-26",
"action": "Buy",
"quantity": 1,
"takeProfit": 5550.00,
"stopLoss": 5450.00
}
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/cancel_and_bracket";
const data = {
instrument: "ES 09-26",
action: "Buy",
quantity: 1,
takeProfit: 5550.00,
stopLoss: 5450.00
};
fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.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/cancel_and_bracket" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"instrument": "ES 09-26",
"action": "Buy",
"quantity": 1,
"takeProfit": 5550.00,
"stopLoss": 5450.00
}'
Response
On normal success, cancelled is the number of existing orders cancelled, placed contains the full newly submitted protection-order objects, and ocoId is their shared OCO identifier.
- 200
- 200 (position lost during cancel)
- 400
{
"success": true,
"cancelled": 2,
"placed": [
{
"orderId": "ddc3f4c244b047fda3f4d9f8f44bc8f3",
"orderType": "Limit",
"orderAction": "Sell",
"quantity": 1,
"limitPrice": 5550.0,
"ocoId": "a1b2c3d4e5"
},
{
"orderId": "b415488f31ff454682a947684e871a90",
"orderType": "StopMarket",
"orderAction": "Sell",
"quantity": 1,
"stopPrice": 5450.0,
"ocoId": "a1b2c3d4e5"
}
],
"ocoId": "a1b2c3d4e5"
}
{
"success": true,
"warning": "Position flattened during cancel window (was 1, now flat). Bracket orders not placed to prevent unintended entry.",
"cancelled": 1,
"placed": []
}
{
"error": "Missing required fields (account, instrument, action, quantity)"
}
Platform nuances
How It Works
The command executes in three phases: first, it cancels all non-terminal orders for the specified instrument on the account. After a configurable delay to allow the broker to process the cancellations, it places a new take profit (limit) and stop loss (stop market) as an OCO pair. The two new orders share an OCO ID, meaning if one fills, the other is automatically cancelled by NinjaTrader.
The action field represents the direction of the position you are protecting, not the direction of the exit orders. If you are long and pass "action": "Buy", the command will place Sell limit and stop market orders to protect the long position. The action is inverted internally.
An open position is required. A flat position is rejected before existing orders are cancelled, and action must match the live position side. A side mismatch is also rejected before cancellation.
If a position in the underlying instrument already exists and the position is smaller than the requested quantity, the bracket is automatically clamped to match the actual position size. If the position goes flat during the cancel window (e.g., a stop was hit while orders were being cancelled), the bracket placement is aborted entirely to prevent accidental naked entry orders.
If a protective stop fills during the cancel phase and the position goes flat before the bracket is placed, bracket placement is automatically aborted. The response will include success: true alongside a warning field. No new orders are placed, preventing an accidental naked entry.
WebSocket API
This request can also be made over the WebSocket API. The account path parameter and request body fields are all passed inside args.
{
"action": "rpc",
"id": "my-request-id",
"api": "CancelAndBracket",
"args": {
"account": "Sim101",
"instrument": "ES 09-26",
"action": "Buy",
"quantity": 1,
"takeProfit": 5550.00,
"stopLoss": 5450.00
}
}
Cancel and Bracket Tradovate
Cancels working orders for one Tradovate instrument, waits for cancellation to settle, and places a fresh OCO target and/or stop to protect the current position. No NinjaTrader add-on is involved: the operation runs server-side with the same validation, Account Manager locks, and Trade Copier fan-out as a webhook signal.
Endpoint
POST /v1/api/tv/accounts/{account}/orders/cancel_and_bracket
The NT8-parity alias /v1/api/tv/accounts/{account}/orders/cancel-and-bracket runs the same command.
Headers
| Name | Value |
|---|---|
| Content-Type | application/json |
| Authorization | Bearer <token> |
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Required | Tradovate account name, for example DEMO12345678. |
Body parameters
| Name | Type | Required | Description |
|---|---|---|---|
instrument | string | Required | Continuous (ES1!), NT8 (ES 09-26), or Tradovate (ESU6) instrument form. |
action | string | Required | Side of the position being protected: buy for long or sell for short. |
qty | int | Required | Requested bracket quantity, clamped to the live position size. |
takeProfit | number | Optional | Absolute take-profit price. |
stopLoss | number | Optional | Absolute stop-loss price. |
At least one of takeProfit or stopLoss must be provided.
Code examples
- Python
- JavaScript
- cURL
import requests
token = 'my-secret-token'
url = "https://app.crosstrade.io/v1/api/tv/accounts/DEMO12345678/orders/cancel_and_bracket"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
data = {
"instrument": "ES1!",
"action": "buy",
"qty": 1,
"takeProfit": 5550.00,
"stopLoss": 5450.00
}
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/tv/accounts/DEMO12345678/orders/cancel_and_bracket";
const data = {
instrument: "ES1!",
action: "buy",
qty: 1,
takeProfit: 5550.00,
stopLoss: 5450.00
};
fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.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/tv/accounts/DEMO12345678/orders/cancel_and_bracket" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"instrument": "ES1!", "action": "buy", "qty": 1, "takeProfit": 5550.00, "stopLoss": 5450.00}'
Response
The response is the response envelope with api set to cancel_and_bracket. The Tradovate bracket result, including the number of orders cancelled, is returned in response.
{
"success": true,
"destination": "tradovate",
"api": "cancel_and_bracket",
"account": "DEMO12345678",
"instrument": "ES1!",
"response": {
"cancelled": 1
},
"durationMs": 214
}
Platform nuances
actionidentifies the protected position side, not the exit-order side. Bracket legs are placed on the opposite side.- A flat position or side mismatch is rejected before any cancellation.
- Existing working orders must finish cancelling before the new bracket is submitted. If they do not settle within the cancellation window, no bracket is placed.
- If the position goes flat or reverses during the cancel window, bracket placement is aborted to prevent an unintended naked entry.
- Account Manager locks and Trade Copier fan-out apply. On failure, the response envelope has
success: falseand anerrormessage.
See the Tradovate API overview for the full field grammar, mutation safety guarantees, and error table.