Can I flip my position from short to long?

I am using the alpaca API to submit orders for the close auction. It may happen that I want to flip a position from a long to a short. If I am long x, I realize that Alpaca fully reject me selling > x.
In this respect, how can I flip my position from short to long, or vice versa? Should I send two independent orders, that will both be executed at the close?
In general, what is the logic behind blocking this behavior, as this can be pretty limiting?

Right now you cannot flip position side in one order. You need to flatten the position first.

Understood, thanks for the quick reply. May I ask if there is any plan to change this?
I also have a side question: I am trying to submit a lot of orders for market close auction or market open. However, it seems that the dashboard is only showing something like the 400 last open orders I have placed, when I can try to place close to 1000. Is that a limitation of the dashboard or a limitation of the API?
How can I manage to place this number of orders without any issue please?

Hi

You posted this about an hour before I was going to ask the same question. I noticed if you place two sell orders (one that liquidated, one that shorts) it places 3 sell orders, which is a dangerous bug I hope alpaca fixes. Even if you stagger the sells by a second it still sometimes does this.

I have tested the code below a few dozen times and seems to be a sustainable work around, but I advise testing it before putting real money down. All it does is wait until the order goes through alpaca and then executes with a small time buffer, ensuring the order doesnt glitch as mentioned above. To implement, simply place an order that liquidates your position above this code and one below to short/long

stag = api.list_positions()

while stag != []:
stag = api.list_positions()
print(“queuing”)
time.sleep(0.1)

time.sleep(0.3)

Hi,

I am currently closing the position before opening a new one. Received this error previously:
“cannot open a long buy while a short sell order is open”

Best regards,
Pascal


Tradingview @paaax
Telegram @paaax255
Email info@pascal-simon.de

From all my testing of flipping from long to short and vice versa, the minimum safe delay between market orders is 5 seconds. Anything shorter can lead to this error “cannot open a long buy while a short sell order is open” or “cannot open a short sell while a long buy order is open”

so less than 5 seconds sometimes work but not close to 99.9%

it is sad but it would’ve been so much better if alpaca just delete this annoying safety check in the API.

Any updates on supporting flipping a position? Waiting for the first order to fill before submitting the other one slows down the order execution a lot. I use webull on my other algos and it supports it just fine.

Any updates on this? For those using TradingView Webhooks to trigger Alpaca this is extremely important for long/short strategy viability.

@bobdylan, @carnagecain still no change regarding this feature request.