The usual cause of the insufficient qty available error is there are existing open orders. When selling (from a long position) the Alpaca systems look at the currently held quantity, minus any outstanding sell orders, to determine the available to sell quantity. If there isnāt enough available quantity to sell then one will get this error.
In general, before closing a position, cancel any outstanding orders (both buy and sell).
There are sell orders open but those are the result of sending in a bracket order. Would I have to cancel all corresponding bracket orders relating to that particular stock before I can issue a sell order?
In my case, I get the error when attempting to cancel a stop loss sell and the launch a market sell. Iām not sure what to wait for other than a successful cancel on the first order which Iām already doing. It seems as though the shares from cancelled orders donāt become āavailableā for another order for quite a while sometimes.
@Aky All outstanding sell orders are considered when checking if there are shares available. This includes bracket orders. The logic however is smart enough that the two legs of a bracket order arenāt counted twice. You would need to cancel those orders before closing a position.
@Joel_Neuendorf After requesting an order to be cancelled, one should wait for a confirmation. This can take tens of seconds during live trading. There isnāt a good way to ācancelā a stop order other than cancelling it. However, one approach I use for limit orders is to simply replace the limit price so the order becomes marketable. This effectively cancels the limit order and then submits a market order in one step. No need to wait for a ācancelledā update.
@Dan_Whitnable_Alpaca Could you share how one would replace the limit price using the api?
The mobile app and api has an amazing feature to close all open orders as well as liquidate all positions IE api to cancel all orders using api.cancel_all_orders(). However, if you use this liquidate all positions and there are already limit sale orders in place you get an error saying that you donāt have available shares to liquidate.
Is there a good way to cancel only the open sale orders before liquidating? Reason being I have lots of buy orders I donāt want to cancel when trying to liquidate, I want to just cancel the current sell orders and then liquidate all the shares I have. Same argument for the buy orders, perhaps I want to keep my current limit orders to sell the shares I have but I want to cancel all my open buy orders so I dont buy any more.
Not sure if this is just a feature request to add a cancel all buy and cancel all sell orders fuction or if there is already a way to address this issue?
I am unable to close any positions via the API or the UI.
I currently have short position against TSLA and whether I try to close via the API, or on the UI via the āLiquidate all posittionsā button, or simply buy back the number of shares I originally sold short. None of it works, the orders donāt fill.
I will have to change broker if I canāt fix it on my paper trading account.