Net positioning market orders

[Paper trade functionality]

Say I’m currently holding long 10 shares of AAPL, but I desire to hold long 40 shares in total.

If I put an OrderSide.BUY for 30 shares, it gives the error:

“message”:“insufficient qty available for order (requested: 30, available: 10)”,“symbol”:“AAPL”}

Note that any existing open orders for AAPL have been closed a long time ago (e.g. the existing 10 long).

Am I using the wrong interface? I’m currently using in Python:

    # Setting parameters for our buy order
    market_order_data = MarketOrderRequest(

    # Submitting the order and then printing the returned object
    market_order = self.trading_client.submit_order(market_order_data)

One obvious solution is to issue two market orders instead of one (i.e. liquidate the existing 10 shares via a OrderSide.SELL and then issue another Orderside.BUY for 40 shares), but this seems strange, especially if I wanted to take this code to live trading, since in live trading it would impose more transaction costs than necessary.

Needless to say, I also have the same problem with trying to go from shorts to longs. Example:

Say i’m holding short -10 shares AAPL, and I desire to hold a total long position of 40 shares. Trying to issue an OrderSide.BUY of 50 shares gives a similar error.

Any help appreciated! Thank you,

Hard to believe given all the sophisticated users posting replies in this forum that not one person knows how to solve this issue?

@paul_kara_alphalayer If one currently holds long 10 shares of a stock then definitely one can buy 30 more shares. It seems from your error that you were holding 10 shares short (ie not long). Could that have been the case?

As for the second case of holding short 10 shares then wanting to move to a long position. That needs to be done in two separate orders. For technical reasons (and a bit of compliance) one needs to 1) close an existing short position then 2) open the long position.

Thanks for the response. I’m almost certain that it was erroring out on a position that was currently long, when I wanted to buy more shares. I’ll double check.