Why is it impossible to concurrently open long and short bracket orders?

Hi all, new to the forum so if I make a mistake or post in the wrong place please let me know.

If I perform the following sequence of events it results in an error and failure to open the second entry.

The initial request to open a long position is as follows:

{
    "symbol": "AAPL",
    "qty": 10,
    "side": "buy",
    "type": "limit",
    "limit_price": 184.0,
    "time_in_force": "gtc",
    "order_class": "bracket",
    "client_order_id": "8/11/23_340",
    "stop_loss": {
        "stop_price": 150.0
    },
    "take_profit": {
        "limit_price": 190.0
    }
}

The response is successful 200 OK and the 3 orders are created on alpaca.
The entry order is filled soon after. While the two exits (sl and tp) remain open.

If I send another bracket order with the following parameters:

{
    "symbol": "AAPL",
    "qty": 10,
    "side": "sell",
    "type": "limit",
    "limit_price": 180.0,
    "time_in_force": "gtc",
    "order_class": "bracket",
    "client_order_id": "8/11/23_341",
    "stop_loss": {
        "stop_price": 190.0
    },
    "take_profit": {
        "limit_price": 170.0
    }
}

The response is unsuccessful:

{
"code": 42210000,
"message": "bracket orders must be entry orders"
}

Of course the intent is to do this in python but the requests were put here instead of code to be easier to reproduce.
Iā€™m not sure if this is behaviour supported on other platforms or if it is my own lack of knowledge?
Any guidance would be greatly appreciated!

To my best knowledge, when I manually trade on ThinkOrSwim, I encounter the same thing: if I want to short, I need to close open long order first, and vice versa.
I had the same experience as you when I am using Alpaca. I assume this is by design. So I just cancel all OLD OPEN bracket orders of a stock when trying to open a new bracket order. Ideally Iā€™d better only cancel the opposite bracket orders

I see, thank you for taking the time to reply.
If another platform does the same thing then I suppose its just how it is.
What you saw on ThinkOrSwim, do you remember if the problem was when you had an open entry to the bracket order or just open exits? i.e the long order entry of the bracket order is still open, vs. the long order is already filled and complete but the stop loss and profit exits are the ones open?
Sorry if that was clear in your response and I didnā€™t get it.

@reshawn There are two underlying issues why one cannot have both a ā€˜go longā€™ and ā€˜go shortā€™ orders open at the same time.

The first is that an account cannot hold both a long and a short position of the same stock. Holding a long and short position is often called ā€œshorting against the boxā€. Back in the day, this was used as a tax avoidance strategy. However, in 1997, congress passed the Taxpayer Relief Act which, among other things, nullified these tax advantages.

There isnā€™t any direct SEC or FINRA rule against holding both long and short positions. However, itā€™s eyed with suspicion. The current ā€˜conventionalā€™ wisdom is thereā€™s little reason for holding a long and a short position simultaneously. One could always simply hold the net difference? Furthermore, because of shorting fees, the cost would be higher than just holding the net difference. The thinking is, if one could accomplish the same ends with less cost by NOT holding both long and short then the trader must be doing something maybe less than legal. Because of this, most, if not all US brokers wonā€™t allow a retail traders to be both long and short simultaneously. They donā€™t want to run the risk of being involved with any activity which even hints at being improper.

What could be improper? There are currently a number of SEC rules around short sales. One is Rule 201 (Alternative Uptick Rule). This restricts the buying short of certain stocks under certain conditions. If one held an equal amount of long and short they could circumvent this rule. How? If there were a short sale restriction in place, a trader holding both long and short, could sell their long shares which would have the net effect of increasing their shorts which is not the intent of this rule. Another potential ā€˜mis-useā€™ would be to pump up trading volume with ā€˜self tradesā€™. FINRA requires brokers to restrict this practice. Those are just a few examples.

The second issue is one cannot move from a long position to a short position (or conversely a short position to a long position) in a single order. Behind the scenes, brokers are required to report short sale trades and the easiest way to do this is to explicitly submit either long or short orders. Some brokers will allow individuals to submit a single long-to-short order, for example, but the broker actually submits it as two orders. Alpaca however, doesnā€™t do this and requires individuals to separate the orders and indicate implicitly that an order is a short order.

So the question was ā€œdo you remember if the problem was when you had an open entry to the bracket order or just open exitsā€. The restriction is on both entry and exit orders. Why? Orders need to be implicitly marked as long, sell short, or buy to cover. If one had a mixture of entry and exit orders, where the net would change the overall side of the position (ie long or short), then depending upon the order those orders got executed, an order may be either a short or a long order. To avoid this, the net of all current outstanding orders must not change the ā€˜sideā€™ of the current position. If a new order is submitted, which would change the side, that order will be rejected.

Hope that helps.

1 Like

Thank you very much for the detailed answer Dan, I understand now it is not as simple as I thought to allow such an action.

If possible can you please provide some advice on how to net the difference?

For example, letā€™s say my system produces a trade
parent long order: buy 1 @ $10 with
exit 1: sell 1 @ 20
exit 2: sell 1 @ 5

and some time later when the price is now $15 it produces a new trade signal
parent short order: sell 1 @ $15 with
exit 1: sell 1 @ 10
exit 2: sell 1 @ 25

How would you suggest I handle that overlap of opposing sides in a way that closest resembles the independent outcome of the two trades?

@reshawn The issue here isnā€™t exactly that you are moving from a long to a short position. The second SELL order would effectively close the position and not go short. However, buried in the Alpaca restrictions on bracket orders is a requirement that all open bracket orders must be 1) on the same ā€˜sideā€™. One could have a BUY and a BUY, or a SELL and a SELL and 2) must be ā€˜entryā€™ orders, ie they must increase a long or short position but cannot decrease it. There are some backend technical issues this causes if not. When one tries to place the above second SELL order (assuming the first BUY order is still open) one gets an error message "bracket orders must be entry orders".

From a logical perspective Iā€™m not sure how you should interpret the two conflicting signals. One is saying go long and stay there until one of the two exit conditions are met, and the other is saying go short. Iā€™m not sure what you are supposed to do with the existing position and existing open orders? If your interpretation is the signal is simply telling you the current position you should have (ie short 1 share) then simply closing the current position and then submitting a SELL bracket order would be the thing to do.

Okay, I understand now it is a complicated issue, and decided to keep the long and short positions separate entirely since handling the way they intertwine is so tricky.
I saw that sub-accounting is on the roadmap for Alpaca and for now, I can just use different accounts.
Thank you very much for your time, patience, and help Dan.