# Shorting and Stop-Loss

**URL:** <https://forum.alpaca.markets/t/shorting-and-stop-loss/14098>\
**Category:** Alpaca Trading\
**Created:** [April 27, 2024, 7:35pm UTC](https://forum.alpaca.markets/t/shorting-and-stop-loss/14098 "2024-04-27T19:35:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KelE](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@KelE](https://forum.alpaca.markets/u/KelE)\
**Post date:** [April 27, 2024, 7:35pm UTC](https://forum.alpaca.markets/t/shorting-and-stop-loss/14098/1 "2024-04-27T19:35:12Z")

</div>

Hello, first time poster, long time lurker,

Currently, I am in the process of integrating shorting into my trading algorithm and I can successfully enter and exit a short position at specified times (market sell plus a delayed buy-in-force), but I have not been able to automate a stop-loss for shorting, such that if the price of a security rises above a certain point then I buy the quantity that I am in the short position.

Any guidance on how to automate this process with alpaca’s python API would be appreciated!

---

<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 28, 2024, 11:15pm UTC](https://forum.alpaca.markets/t/shorting-and-stop-loss/14098/2 "2024-04-28T23:15:34Z")

</div>

@KelE to enter a stop-loss order which will trigger if the price exceeds a certain value, simply submit a buy stop-loss order (ie not a sell) with a [StopOrderRequest](https://alpaca.markets/sdks/python/api_reference/trading/requests.html#stoporderrequest). That will trigger a buy (to cover) order when the stop prices is exceeded (the opposite of a sell order). Something like this

> # **Single stop order to ‘buy to cover’ when stop\_price is exceeded**
> 
> buy\_stop\_order = client.submit\_order( StopOrderRequest(  
> symbol=‘SPY’,  
> qty=1,  
> side=OrderSide.BUY,  
> time\_in\_force=TimeInForce.DAY,  
> stop\_price=300.00),  
> ))

However, a bit better way to enter this type of order would be to pen the initial short position with a bracket order and include the stop order and also a take-;rofit order at the same time.

> # **Bracket order with market order as initial ‘parent’ order**
> 
> market\_bracket\_order = client.submit\_order(MarketOrderRequest(  
> symbol=‘SPY’,  
> qty=1,  
> side=OrderSide.SELL,  
> time\_in\_force=TimeInForce.DAY,  
> order\_class = OrderClass.BRACKET,  
> stop\_loss=StopLossRequest(stop\_price=300.00),  
> take\_profit=TakeProfitRequest(limit\_price=250.00)  
> ))

> # **Bracket order with limit order as initial ‘parent’ order**
> 
> market\_bracket\_order = client.submit\_order(LimitOrderRequest(  
> symbol=‘SPY’,  
> qty=1,  
> side=OrderSide.SELL,  
> limit\_price=275.00,  
> time\_in\_force=TimeInForce.DAY,  
> order\_class = OrderClass.BRACKET,  
> stop\_loss=StopLossRequest(stop\_price=300.00),  
> take\_profit=TakeProfitRequest(limit\_price=250.00)  
> ))
