Bracket order to automate your trades

You requested it. Now it’s here.

Bracket orders are now available on Alpaca (and in our docs here) to better help you automate trades and mitigate risk. This is a new-to-Alpaca, advanced order type with three components: a primary order, a take-profit order, and a stop-loss order.

How Bracket order works

The first order sets everything up the way a normal order does, but it truly becomes a bracket order when it comes to deciding which of the two conditional orders remaining will be kept or canceled. Depending on where you set the low and high brackets, the order will wait to execute until it hits one of those two “max” or “min” numbers (optimized for profit or the most acceptable losses, respectively) and then cancel the remaining order type.

For example (like in the chart below), if you set your “take-profit” number at $145 (yellow line) and “stop loss” at $95 (red line), corresponding with a primary order at $105 and the stock goes up to $125 but then the price drops, hitting $95 (before reaching $145), your “stop-loss” order will trigger and be executed, while also cancelling the “take-profit” order. All in all, bracket orders can be great when you are trying to stay within a target price range.

Due to the way bracket orders work, it’s completely possible to set this logic up algorithmically/via API. However, the full functionality enabled within the Alpaca platform allows for better risk controls, which are provided to help minimize potentially costly mistakes. Alpaca is committed to providing better risk controls to help reduce the possibility of exactly those kinds of errors.

How to set up Bracket order

If you’re ready to dive in*, you’ll need to add extra parameters to the POST /v2/orders endpoint to submit bracket orders via API and submit your order.

  1. First, set the new parameter “order_class” to “bracket”.

Next, add two more parameters named “take_profit” and “stop_loss”—both should be nested JSON objects.  (see example JSON below)

  1. When creating “take_profit”, make sure to add “limit_price” as a parameter that limits the price of the “take_profit” order.
  2. The “stop_loss” will need fields for mandatory “stop_price” and optional “limit_price”.
  3. If your “limit_price” is specified within “stop_loss”, your order will be queued as a “stop_limit” order—otherwise it will be queued as a classic stop order.
  4. Run it!

*Consider testing a strategy in paper trading to see if and how it works before trying it in a live brokerage account.

{
  "side": "buy",
  "symbol": "SPY",
  "type": "market",
  "qty": "100",
  "time_in_force": "gtc",
  "order_class": "bracket",
  "take_profit": {
    "limit_price": "301"
  },
  "stop_loss": {
    "stop_price": "299",
    "limit_price": "298.5"
  }
}

Brokerage services are provided by Alpaca Securities LLC ("Alpaca"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.

Conditional orders may have increased risk as a result of their reliance on trigger processing, market data, and other internal and external systems. Such orders are not sent to the market until specified conditions are met. During that time, issues such as system outages with downstream technologies or third parties may occur. Conditional orders triggering near the market close may fail to execute that day. Furthermore, our executing partner may impose controls on conditional orders to limit erroneous trades triggering downstream orders. Alpaca Securities may not always be made aware of such changes to external controls immediately, which may lead to some conditional orders not being executed. As such, it is important to monitor conditional orders for reasonability. Conditional orders are “Not Held” orders whose execution instructions are on a best efforts basis upon being triggered. Furthermore, conditional orders may be subject to the increased risks of stop orders and market orders outlined above. Given the increased potential risk of using conditional orders, the client agrees that Alpaca Securities cannot be held responsible for losses, damages, or missed opportunity costs associated with market data problems, systems issues, and user error, among other factors. By using conditional orders the client understands and accepts the risks outlined above. Alpaca Securities encourages leveraging the use of Paper accounts to become more comfortable with the intricacies associated with these orders.