I’m encountering a consistent issue where my pre-market purchase orders are executed at the peak price immediately after the market opens. For example, if a stock is placed at $10 before market opens and the opening price jumps to $15, my transactions invariably execute at $15, negating potential gains from the initial rise.
This pattern persists regardless of how early I place my orders, suggesting that my position in the order queue doesn’t seem to affect the execution price. I’m seeking clarification on how order execution timing is determined for pre-market orders and any strategies available to improve execution prices for these trades.
This is how I commit my trades with the API using the AAPL stock for example
alpaca_api.submit_order(
symbol=‘AAPL’,
qty=10,
side=‘buy’,
type=‘market’,
time_in_force=‘day’,
stop_loss={
‘stop_price’: 150,
‘time_in_force’: ‘gtc’
}
)
Thank you for the help!
@Roi_Bel In general, market orders placed before markets open, are executed at market open at the ‘open’ price. However, just as any market order, the price is not guaranteed. As a ‘worst case’ buy orders will generally fill at the NBBO ask price as when the order filled.
Could you give an example of orders which you feel filled ‘irregularly’. Either order id and the filled price and filled time vs the day’s open price.
Lets say that a stock closes at 10usd, and during closed market hours people sell insane amounts of shares. When the market opens, all those trades are fulfilled one by one in the order that they were placed, and the price of the stock plummets to lets say 5usd. Assuming that I too tried to sell my stock exactly in the middle of closed market hours, shouldn’t my trade get fulfilled at exactly 7.50? I feel that with the Alpaca api, even if I’m the first to submit a trade after markets close my trade will still only get fulfilled at market open price, missing out on the entire price spike. Maybe I am assessing the situation wrong, or maybe it’s because of my trade parameters. Thanks so much for the help!
@Roi_Bel Maybe a few things to clear up. You stated “When the market opens, all those trades are fulfilled one by one in the order that they were placed”. That’s not really correct. “The Market” isn’t one thing or place. Orders can be executed at any one of over 20 exchanges, over 50 major “Single Dealer Platforms”, and actually any one of the thousands of individual brokers. So they are not executed in the order they were placed. At a particular venue they may be executed in the order they were received (but there is no guarantee of that) but overall your order is randomly executed. Take a look here for a good description of where orders are executed.
The main thing driving the opening price are the opening auctions. While trading during market hours generally match an individual buyer with a seller, there are special ‘auctions’ at the beginning and end of each day which pool orders together and then execute all of them at the same price. If one specifies a time in force of either opg
or cls
(ie Market On Open MOO or Market On Close MOC) then your order will participate in these auctions. However, even though your order may not directly participate, the price at the opening auction tends to drive the price of other trades. Each exchange runs their auctions a bit differently but the NYSE auctions are pretty indicative. Take a look here for how they run theirs.
So, a couple of takeaways. 1) it doesn’t matter when you place a market order during after hour trading. Those all get stored and will get executed very close to when markets open the following trading day but in no particular order. 2) the price it fills at will be at or better than the opening bid (for a sell order) or the opening ask (for a buy order). The price most often will be the opening auction price.
What do you mean by ‘The price most often will be the opening auction price’? I assumed that if I placed a trade before markets open, it will be fulfilled at a random price in the range of the opening spike. So if a stock instantly spikes from 10usd to 15usd when markets open, my trade will most likely be submitted at 15usd?Why is that? And for my trade to be submitted at a cheaper price than that is luck? Is this how all trading exchanges work, where the order that the trades are executed is just randomized and the time at which you submit trades doesn’t matter?
@Roi_Bel A few questions here so I’ll try to answer one at a time
I assumed that if I placed a trade before markets open, it will be fulfilled at a random price in the range of the opening spike
When an order is received by Alpaca it is routed to one of several execution venues. The exact venues change periodically but they are published in SEC mandated quarterly ‘606 Reports’. There is some business logic behind this routing but it is primarily random. Once the execution venue receives the order they generally execute the order as soon as possible (typically under 500ms) but sequence is not guaranteed. The fill price is not ever really random. Buy orders typically fill at the NBBO ask price and sell orders typically fill at the bid price.
The price most often will be the opening auction price’?
Even though Alpaca orders generally do not participate directly in auctions, the auction price drives the quotes. The reason is traders look to that price when setting their limit order prices (ie quotes - why would I try to sell or buy at a price worse than that). The quotes at open are therefore very close to that price.
So if a stock instantly spikes from 10usd to 15usd when markets open, my trade will most likely be submitted at 15usd?
The only thing driving the order fill price is the NBBO quote at the time the order filled (typically 50ms-500ms after open). The price does not depend at all on any previous trades or previous price.
And for my trade to be submitted at a cheaper price than that is luck? Is this how all trading exchanges work, where the order that the trades are executed is just randomized and the time at which you submit trades doesn’t matter?
There is no relationship between when an order is submitted before markets open. An order submitted at midnight is routed just like an order submitted at 9:15 ET. Each venue, including exchanges, have different execution rules and executions are not really random, but they also are not guaranteed to be FIFO. There is a measure of ‘luck’, but if one wants a very good idea what the fill price will be is 1) do not place orders before markets open 2) wait until markets open and check the current quote before submitting your order. Your order will probably fill at that price and 3) if you wish, place a limit order and not a market order and set the limit price to that quote price (or maybe a bit worse).
Thanks for the patience—I’ve been combing through the details you provided and doing some extra reading on my end. Really appreciate the clear breakdown; it’s given me a much better picture of how everything operates.
My only remaining question is about this 2018 article you guys have on using the OPG parameter for time-in-force settings. I’ve been experimenting with it, and I’m seeing different results: sometimes I get prices below the opening, other times near the previous day’s close, or closer to the opening price. Just wondering, how does this actually work? Is it a first-come, first-served kind of deal, or is there some other logic at play for the prices we end up with?
@Roi_Bel While paper trading tries to simulate live trading, and generally comes very close, one area which paper trading doesn’t simulate well is opg
and cls
orders. Those orders get filled as regular market orders at the open or close bid/ask price and not at the open or close auction prices. That is why one can see a discrepancy between fills.
Ah, I understand. So, when moving from paper trading to actual trading, my orders will actually take part in the real opening and closing auctions, which can yield different outcomes compared to the simulated fills. That makes sense! Regarding real trading environments, I’m curious about how orders in the auction queue are prioritized. Is the process based on a first-in first-out (FIFO) system, or is it just random?
Thanks for clarifying this for me!
@Roi_Bel The opening and closing auctions 1) typically fill all submitted orders and 2) all orders fill at the same price. There really isn’t any queue. A price is set and all orders fill at the same time and at the same price.
Each exchange has slightly different rules but take a look here for how NASDAQ runs their open and close auctions (they call them ‘Crosses’).
Thanks for the explanation. Just to clarify, does this mean that all orders during the opening and closing auctions are filled simultaneously at the average price, regardless of when they were submitted? And you mentioned variations across different exchanges – does this imply that the method of order execution during the Open Auction is determined by the exchanges themselves, and not by Alpaca?
If so, can traders choose the specific exchange on which their orders are executed? My strategy significantly relies on rapid response to market news during premarket times, aiming to secure early positions so that when markets open my trade can fill before the stocks price spikes. If all orders are filled at once during the auctions at the average price, does this mean the speed of order submission is irrelevant with the way Alpaca handles open auctions? Is this standard across all trading platforms?
@Roi_Bel You asked several questions…
“does this mean that all orders during the opening and closing auctions are filled simultaneously at the average price, regardless of when they were submitted?”
Yes, all orders fill at the same price. It’s not exactly the ‘average price’ but rather the auction price determined by the exchange and the rules used to calculate that price vary a bit by exchange.
“does this imply that the method of order execution during the Open Auction is determined by the exchanges themselves, and not by Alpaca?”
Correct, each exchange publishes the process they use to determine auction prices. That is not determined by Alpaca. There are links above to documentation published by the NASDAQ and NYS exchanges.
“If so, can traders choose the specific exchange on which their orders are executed?”
No, Alpaca doesn’t have a process for traders to specify the exchange. However, there typically is only a single exchange (the original listing exchange) which holds auctions for a specific symbol, but in some cases there can be several.
“If all orders are filled at once during the auctions at the average price, does this mean the speed of order submission is irrelevant with the way Alpaca handles open auctions? Is this standard across all trading platforms?”
If one places a MOO order to be executed in the opening auction, then the speed and timing of that order is irrelevant. Whether the order is placed the previous evening, or 10 minutes before the markets open, the order will participate equally in the opening auction. This is by design and standard across the industry. It is one of the advantages of the opening auction by creating a level more fair trading field.
I’m aiming to have my trades executed as close to the previous day’s closing price as possible. Given the nature of the opening auction, is there any strategy or approach I could adopt to enhance the likelihood that my trades are among the earliest to be executed, or to better align my trades with the previous day’s closing price?
@Roi_Bel The only way to guarantee a price is submit a limit order. Place a limit order at yesterday’s close and see if it fills.
There really isn’t any way to ‘align’ trades with the previous day’s close other than 1) placing a limit order with the chance it won’t fill or 2) monitor the quotes and submit an order if/when they are at yesterday’s close. Placing your order early doesn’t at all imply the order will fill near to the previous close.
Below is a day’s price chart of a random symbol PSTG. The orange line is the previous close. Notice a few things 1) the open, and orders close to the open, all filled much higher than the previous close 2) within about 15 minutes after the open the price dropped below the previous close but then went back up 3) after about hour the price dropped way below yesterday’s close. Pick another stock on another date and you will see a different pattern.