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!
@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. 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
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