Bracket

A bracket order consists of an entry limit order, a take-profit order, and a stop-loss order. The take-profit and stop-loss orders are managed via a One-Cancels-Other (OCO) algo as a subalgo.

All orders are placed simultaneously when the algo starts.

Order Structure

  • Entry Order: A limit order that initiates the position

  • Take-Profit Order: A limit order placed at take_profit_price to exit at a profit

  • Stop-Loss Order: A stop-limit order with stop_loss_trigger_price and stop_loss_limit_price to exit at a loss

Execution Behavior

  1. The entry order is placed immediately when the algo starts

  2. When the entry order receives fills, the exit orders (take-profit and stop-loss) are placed as an OCO pair

  3. If trigger_in_proportion is true, exit orders are sized proportionally to the filled quantity of the entry order

  4. If trigger_in_proportion is false, exit orders are only placed after the entry order is fully filled

  5. When either exit order is filled, the other is immediately cancelled via the OCO subalgo

Price Validation

For BUY entries:

  • take_profit_price must be greater than entry limit_price

  • stop_loss_trigger_price must be less than entry limit_price

  • stop_loss_limit_price must be less than or equal to stop_loss_trigger_price

For SELL entries:

  • take_profit_price must be less than entry limit_price

  • stop_loss_trigger_price must be greater than entry limit_price

  • stop_loss_limit_price must be greater than or equal to stop_loss_trigger_price

Completion

The bracket algo completes when:

  • The entry order is outed/cancelled before any fills, OR

  • All exit orders are fully filled or cancelled after entry fills

circle-exclamation

Use Cases

  • Automating profit-taking and risk management for a position

  • Ensuring disciplined exits without manual intervention

  • Managing trades with predefined risk/reward ratios

BracketParams

Parameter
Description

entry (OrderInfo)

The entry order information

take_profit_price (Decimal)

Limit price for the take-profit exit order

stop_loss_trigger_price (Decimal)

Trigger price for the stop-loss order

stop_loss_limit_price (Decimal)

Limit price for the stop-loss order (after triggered)

trigger_in_proportion (bool)

If true, exit orders are sized proportionally to entry fills

Example

Last updated