POST Cancel and Bracket
Cancel all working orders and submit a bracket order in one shot
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.
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.
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.
Cancel and Bracket can be used as an entry strategy. If no underlying positions exist, an OCO bracket will be entered at the quantity specified. This can be used to "straddle" the underlying price and take position if the spot price moves in either direction.
Cancel and Bracket
POST /v1/api/accounts/{account}/orders/cancel_and_bracket
Headers
Content-Type
application/json
Authorization
Bearer <token>
Path Parameters
account
string
Required
Account name in NT8
Body Parameters
instrument
string
Required
Instrument name (e.g., "ES 09-26")
action
string
Required
Direction of the position being protected: Buy or Sell
quantity
integer
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
Response
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.
Last updated