# Trailing Stop Loss - Canceling Orders

**URL:** <https://forum.alpaca.markets/t/trailing-stop-loss-canceling-orders/5561>\
**Category:** Alpaca Trading\
**Created:** [April 28, 2021, 1:38pm UTC](https://forum.alpaca.markets/t/trailing-stop-loss-canceling-orders/5561 "2021-04-28T13:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beauj34](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/beauj34/32/1176_2.png) [@Beauj34](https://forum.alpaca.markets/u/Beauj34)\
**Post date:** [April 28, 2021, 1:38pm UTC](https://forum.alpaca.markets/t/trailing-stop-loss-canceling-orders/5561/1 "2021-04-28T13:38:14Z")

</div>

What is the most effective way to get an open order ID for a trailing stop loss order?

For example, I open a long position based on an indicator event and simultaneously open a trailing stop loss sell order. One of two things can happen; The trailing stop loss is triggered and I exit the position or the indicators trigger another event that requires you to cancel the open trailing stop loss order and close the open long position.

I can run the list orders API call and query through the list of open orders to find it by symbol then match it to order ID but wasn’t sure if there is an easier method out there. It would be nice to have an API call that cancels open orders by symbol

---

<div class="post-metadata">

**Author:** ![Beauj34](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/beauj34/32/1176_2.png) [@Beauj34](https://forum.alpaca.markets/u/Beauj34)\
**Post date:** [April 28, 2021, 2:21pm UTC](https://forum.alpaca.markets/t/trailing-stop-loss-canceling-orders/5561/2 "2021-04-28T14:21:36Z")

</div>

For anyone curious, This was my solution:

##Get Open Orders List  
orders = api.list\_orders()

##Loop Through Orders List to find the symbol to be canceled (Ticker\_Sym is my ticker variable)  
for order in orders:  
if order.symbol == Ticker\_Sym:  
print(‘Order Found…Canceling Open Order’)  
api.cancel\_order(order.id)

---

<div class="post-metadata">

**Author:** ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)\
**Post date:** [April 29, 2021, 2:57am UTC](https://forum.alpaca.markets/t/trailing-stop-loss-canceling-orders/5561/3 "2021-04-29T02:57:42Z")

</div>

Good solution. You pretty much need to cancel each order separately. One can also get the orders for just a subset of symbols. So something similar could also be done:

```
# Get list of open orders for the stock or stocks you want
my_orders = api.list_orders(params={"symbols":"SPY"})

# Loop through the orders list and cancel the orders
for order in my_orders:
  api.cancel_order(order.id)

```

In future versions of the python SDK the `symbols` parameter will be built in. However, for now it can be added using the `params` keyword.
