# Help understanding protective order workflows

**URL:** <https://forum.alpaca.markets/t/help-understanding-protective-order-workflows/13725>\
**Category:** App-Integration\
**Created:** [February 24, 2024, 9:29am UTC](https://forum.alpaca.markets/t/help-understanding-protective-order-workflows/13725 "2024-02-24T09:29:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![l.kerrigan87](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/l.kerrigan87/32/5877_2.png) [@l.kerrigan87](https://forum.alpaca.markets/u/l.kerrigan87)\
**Post date:** [February 24, 2024, 9:29am UTC](https://forum.alpaca.markets/t/help-understanding-protective-order-workflows/13725/1 "2024-02-24T09:29:17Z")

</div>

Hello Alpaca Community,

I am currently developing an app and need some guidance on integrating my order workflows, specifically regarding protective orders. I have two scenarios where I’m a bit stuck:

**Scenario 1** : I’m looking to create a buy order followed by protective orders which include:

1. A Stop order (sell) to set a fixed stop-loss price.
2. A Limit order (sell) to set a take-profit price and secure profits.

**Scenario 2:** Similarly, I want to create a buy order followed by protective orders that include:

1. A Trailing Stop order (sell) to set a trailing percentage value.
2. A Limit order (sell) to set a take-profit price and secure profits.

After reviewing the documentation, it appears that bracket orders won’t suffice for scenario 2 due to the absence of a trailing stop feature. My current understanding is that I might have to place each order separately through the API, starting with the buy order and then the protective orders.

However, I want to ensure that this approach won’t trigger the ‘wish trade’ validation logic on Alpaca’s platform.

Could you confirm whether this is a valid integration pattern for Alpaca? If not, could you provide some insights or resources on how to chain these orders correctly for both scenarios?

Draft code for ref:

async def place\_order(self, client\_order\_id, symbol, qty, side, order\_type, limit\_price=None, stop\_price=None, trail\_percent=None, trail\_price=None):

```
    if order_type == 'market':
        order_data = MarketOrderRequest(
            client_order_id=client_order_id,
            symbol=symbol, 
            qty=qty, 
            side=OrderSide.BUY if side.lower() == 'buy' else OrderSide.SELL, 
            time_in_force=TimeInForce.DAY
        )
   
   elif order_type == 'limit':
       order_data = LimitOrderRequest(
           client_order_id=client_order_id,
           symbol=symbol, 
           qty=qty, 
           side=OrderSide.BUY if side.lower() == 'buy' else OrderSide.SELL, 
           limit_price=limit_price, 
           time_in_force=TimeInForce.GTC
       )
   elif order_type == 'stop':
       order_data = StopOrderRequest(
           client_order_id=client_order_id,
           symbol=symbol, 
           qty=qty, 
           side=OrderSide.BUY if side.lower() == 'buy' else OrderSide.SELL, 
           stop_price=stop_price, 
           time_in_force=TimeInForce.GTC
       )
   elif order_type == 'trailing_stop':
       order_data = TrailingStopOrderRequest(
           client_order_id=client_order_id,
           symbol=symbol, 
           qty=qty, 
           side=OrderSide.BUY if side.lower() == 'buy' else OrderSide.SELL, 
           trail_price=trail_price if trail_price else None, 
           trail_percent=trail_percent if trail_percent else None, 
           time_in_force=TimeInForce.GTC
       )
   else:
       raise ValueError(f"Unsupported order type: {order_type}")

   try:
       return self.trading_client.submit_order(order_data=order_data)
   except Exception as e:
       logging.error(f"Error placing {order_type} order for {symbol}: {e}")
       return None

```

Thank you in advance for your assistance!
