Changing stops on a open position

I’m looking to change the stop (or limit) value for an open position. This isn’t a trailing stop as requested elsewhere, just the change of the regular stop/limit value on a position - I can’t see anything in the documentation that allows the update of a position or any specific stop/limit related methods.

It seems like such an obvious thing- am I missing something? How would I do this?

thanks

2 Likes

I am very new to the Alpaca API, so perhaps this is a stupid answer, but…

Isn’t this the use case for the patch concept on the orders endpoint?

Even if patching the existing order doesn’t work, could you not just delete the existing stop order, and immediately create another one with the new parameters?

1 Like

With most brokers I’ve worked with, the stop is associated with a the open ticket or position and that there is no concept of a PUT for positions or even tickets, I hadn’t realised that I do need to submit orders with a stop price. So you’re right, orders are the way to go. Seems obvious now. thanks.

1 Like

I had the same question @rusted.
I thought that orders are converted to Positions when they are fulfilled.
Can you confirm that changing the stop loss of an open order actually moves the stop loss of the position?

@XLTechie One can use the replace order endpoint to modify the stop price of an open order. In the background this actually cancels the existing order then creates a new order with the new stop loss price. Because it creates a new order, the order number will change, and if there was a client_order_id, that will change too. Note this is effectively a “request to replace” an order. While one may get an initial 200 success response, that simply means the request was successful. One should monitor the order to verify it was actually replaced (which happens asynchronously).

2 Likes

Thanks for your answer @Dan_Whitnable_Alpaca
So essentially, the position is closed, losses/profits updated and the order is re-opened at a new enter price?

Also, in the documentation is written: “If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected, and these events are sent in the trade_updates stream channel.”. What does “filled” mean here?

1 Like

@cksrc You asked

So essentially, the position is closed, losses/profits updated and the order is re-opened at a new enter price?

Not exactly. Positions and orders are two separate things. A position is what you currently have in your account. An order is a request to buy or sell more. The position isn’t impacted by replacing the stop loss price. If you had 10 shares of XYZ then you still have 10 shares of XYZ. Only the order is closed and then replaced with a new order but now with your updated stop price.

When you submit an order, that request is sent to an execution partner (you can think of it as the exchange) for execution. When the order is actually executed (eg you buy 10 shares of XYZ) that is called ‘filling the order’. When an order ‘fills’ it simply means it is executed. Also note that orders fill asynchronously (or may not fill at all). The comment in the docs where it says

If the existing open order is filled before the replacing (new) order reaches the execution venue, the replacing (new) order is rejected

That simply means the replace request was sent to the execution partner (asynchronous to your algo) and, if when it gets to that partner, the order has already been executed then it’s too late to replace the order.

2 Likes