# Bracket order example in Python

**URL:** <https://forum.alpaca.markets/t/bracket-order-example-in-python/4097>\
**Category:** Alpaca Trading\
**Created:** [January 27, 2021, 6:48pm UTC](https://forum.alpaca.markets/t/bracket-order-example-in-python/4097 "2021-01-27T18:48:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karen](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Karen](https://forum.alpaca.markets/u/Karen)\
**Post date:** [January 27, 2021, 6:48pm UTC](https://forum.alpaca.markets/t/bracket-order-example-in-python/4097/1 "2021-01-27T18:48:26Z")

</div>

Could I get an example of a bracket order in Python? I see one example in JSON.

---

<div class="post-metadata">

**Author:** ![vrso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/vrso/32/1588_2.png) [@vrso](https://forum.alpaca.markets/u/vrso)\
**Post date:** [January 27, 2021, 7:33pm UTC](https://forum.alpaca.markets/t/bracket-order-example-in-python/4097/2 "2021-01-27T19:33:10Z")

</div>

Here ther’s an example of bracket order, you can find them by yourself at [Order Examples - Documentation | Alpaca](https://alpaca.markets/docs/api-documentation/how-to/orders/)

```
import alpaca_trade_api as tradeapi

api = tradeapi.REST()

symbol = 'AAPL'
symbol_bars = api.get_barset(symbol, 'minute', 1).df.iloc[0]
symbol_price = symbol_bars[symbol]['close']

# We could buy a position and add a stop-loss and a take-profit of 5 %
api.submit_order(
symbol=symbol,
qty=1,
side='buy',
type='market',
time_in_force='gtc',
order_class='bracket',
stop_loss={'stop_price': symbol_price * 0.95,
           'limit_price': symbol_price * 0.94},
take_profit={'limit_price': symbol_price * 1.05}
)

# We could buy a position and just add a stop loss of 5 % (OTO Orders)
api.submit_order(
symbol=symbol,
qty=1,
side='buy',
type='market',
time_in_force='gtc',
order_class='oto',
stop_loss={'stop_price': symbol_price * 0.95}
)

# We could split it to 2 orders. first buy a stock,
# and then add the stop/profit prices (OCO Orders)
api.submit_order(symbol, 1, 'buy', 'limit', 'day', symbol_price)

# wait for it to buy position and then
api.submit_order(
symbol=symbol,
qty=1,
side='sell',
type='limit',
time_in_force='gtc',
order_class='oco',
stop_loss={'stop_price': symbol_price * 0.95},
take_profit={'limit_price': symbol_price * 1.05}
)
```

---

<div class="post-metadata">

**Author:** ![Karen](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Karen](https://forum.alpaca.markets/u/Karen)\
**Post date:** [January 27, 2021, 8:28pm UTC](https://forum.alpaca.markets/t/bracket-order-example-in-python/4097/3 "2021-01-27T20:28:13Z")

</div>

Thanks. I should have searched in more places.
