Order Types: Market Orders, Limit Orders, and Execution
The same trade, submitted with a different order type, can fill several ticks apart. Market, limit, and stop orders are all positions on one tradeoff: certainty of execution versus certainty of price.
What a trade costs you depends on what you buy and when — and on a variable beginners tend to skip entirely: how the order gets submitted. The same “buy 200 shares,” sent as a market order versus a limit order, can land in your account several ticks apart. And once you strip away the jargon, the whole subject of order types comes down to one tradeoff: you can be certain of execution, or certain of price, but not both. Every order type below is just a different position on that tradeoff.
Market orders: take the fill, whatever the price
A market order buys or sells immediately at the best available price. It sits at one end of the tradeoff: as long as there’s a counterparty in the market, you will get filled — barring a market with no liquidity at all, execution is guaranteed. What’s not guaranteed is the price. Where you fill is decided by the bid and ask at that instant, not by you.
In a liquid stock this is usually fine — the spread is narrow and you get roughly the price on your screen. In an illiquid stock or a fast-moving market, a market order will betray you: the screen shows one price when you submit, the fill confirmation comes back with another. That gap between the price you expected and the price you got is called slippage. The bigger your order and the thinner the book, the worse it gets, because your order eats through the book level by level — the code at the end of this article computes exactly that.
So the conditions for using a market order are actually quite specific: the stock is liquid, and getting filled now matters more than the exact price. When you need to get in or out immediately, paying a bit of spread for certainty is a fair trade. Throwing a market order at a thinly traded stock, on the other hand, is handing your fill price to chance.
Limit orders: name your price, gamble on the fill
A limit order sits at the opposite end of the tradeoff: a buy limit fills at your specified price or below, a sell limit at your specified price or above. Mechanically, you place a buy limit at or below the current ask — you will never pay more than your limit — and a sell limit at or above the current bid — you will never sell for less. You control the price entirely. What you give up is the other end: execution is not guaranteed, and your order can sit there unfilled indefinitely.
And non-execution is not evenly distributed bad luck. Limit orders have a counterintuitive flaw: the moments when they fill most easily are often the moments you least want them to. Say you park a buy limit a few ticks below the market. If the stock runs up, you never get filled and watch the move leave without you. If the stock breaks down through your limit, you do get filled — you just bought into a falling market. That doesn’t make limit orders bad; it’s a reminder that “I controlled the price” is not the same as “I got a bargain.” Sometimes that fill confirmation is the market handing you something it no longer wants.
When do limit orders make sense? When the specific price matters more to you than certainty of execution — for instance, when you’ve worked out that the trade is only worth doing below a certain price. In that case, not filling above it isn’t a failure; it’s the correct outcome.
Stop orders: a market order with a delayed fuse
A stop order looks like a third option, but it isn’t one. A stop order stays dormant until a specified price is touched, then becomes a market order. A stop-loss order triggers a sell when the price falls through your stop, to cap the loss on a long position; a stop-buy order triggers a buy when the price rises through your stop, to cap the loss on a short or to enter on a breakout. The mechanism is identical either way: nothing executes until the stop price is reached, and from the moment it triggers, it is an ordinary market order with no price guarantee whatsoever.
That last part deserves an extra beat of thought. The moment a stop triggers is, almost by definition, a moment when the market is moving fast — which is precisely when market-order slippage is at its worst. Using stops for risk management is right; reading the stop price as a promise that “this is the most I can lose” is wrong. A stop is a switch: “from this price on, exit at market.” The actual exit price is decided after the switch flips, and it’s often worse than where the switch was set.
Orders expire: time-in-force
All three order types also have a time dimension: how long the order stays alive after you submit it. The most common is the day order, which cancels automatically at the close if it hasn’t filled. A good-til-cancelled (GTC) order stays working until it fills or you cancel it — though most brokers cap GTC at 60 to 90 days. The other two are mostly the territory of large orders and algorithms: immediate-or-cancel (IOC) demands an immediate fill and cancels whatever portion doesn’t execute, while fill-or-kill (FOK) is stricter still — the entire order must fill immediately or the whole thing is cancelled, which suits large orders that must get done in one shot or not at all. For a beginner trading by hand, the one that actually matters is the first: the day limit order you placed yesterday is gone today.
Where your order actually goes
Between clicking “submit” and shares appearing in your account, there’s a pipeline:
- Order entry: you send the order to your broker (phone, app, API)
- Order routing: the broker sends it to an exchange or market maker
- Order matching: the exchange matches your order with a counterparty
- Execution: the trade happens at a specific price
- Clearing and settlement: securities and cash change hands
The step that most affects your fill price is the second one. Retail brokers often route orders to particular market makers, and those market makers pay the broker for the privilege — an arrangement called payment for order flow. The broker collects revenue; the price you fill at may be worse than if the order had gone straight to an exchange. This isn’t a conspiracy — it’s a disclosed, ordinary business model — but it does mean “commission-free” is not the same as “cost-free”: the cost may be hiding inside your fill price. It’s worth a few minutes to find out where your broker routes orders.
Putting numbers on the tradeoff
Saying “market orders have slippage and limit orders might not fill” is one thing; computing it is better. The first function below simulates a market order walking through a limit order book level by level. The second compresses the limit-versus-market decision into an expected-value comparison.
def simulate_market_order(limit_order_book, quantity, side='buy'):
"""
Simulate the expected cost of a market order given current LOB.
Market orders walk up/down the book until filled.
Each level has a specific size and price.
"""
if side == 'buy':
book = limit_order_book[limit_order_book['side'] == 'ask'].sort_values('price')
else:
book = limit_order_book[limit_order_book['side'] == 'bid'].sort_values('price', ascending=False)
remaining = quantity
total_cost = 0
for _, row in book.iterrows():
if remaining <= 0:
break
fill_size = min(remaining, row['size'])
total_cost += fill_size * row['price']
remaining -= fill_size
avg_price = total_cost / (quantity - remaining) if remaining < quantity else None
return {
'filled': quantity - remaining,
'remaining': remaining,
'avg_fill_price': avg_price,
'expected_slippage_bps': (avg_price - book.iloc[0]['price']) / book.iloc[0]['price'] * 10000 if avg_price else None
}
def limit_order_vs_market_order(limit_price, market_cost, probability_fill):
"""
Compare expected value of limit order vs market order.
"""
# Limit order: get limit price if filled, miss opportunity if not
limit_expected = limit_price * probability_fill
# Market order: pay market cost
market_expected = market_cost
return {
'limit_order_expected_cost': limit_expected,
'market_order_cost': market_expected,
'limit_better_if': limit_expected < market_expected
}
PROMPT
Use pandas to simulate a market order walking the limit order book, and compare its expected cost to a limit order with an assumed fill probability.
The first function turns the market-order section above into numbers. When your quantity is smaller than the size at the top of the book, your average fill is just the best bid or ask and slippage is near zero; make the order bigger and the average price gets pushed level by level, with expected_slippage_bps telling you in basis points how far. The second function is crude — it doesn’t price the opportunity cost of the unfilled case, it just multiplies the limit price by the fill probability and compares that to the market cost — but its direction is right: the lower the fill probability, the cheaper a limit order looks on paper and the less reliable it is in practice. That is the core tradeoff, in numeric form.
Which brings this back to where it started: a market order buys certainty with price, a limit order buys price with certainty, a stop order is a market order on a delayed fuse, and routing decides the venue where all of it plays out. If you want to genuinely master orders and execution, Chapter 3 of Harris’s Trading and Exchanges explains order types better than any broker’s help pages; when you’re ready to go deeper into the empirical side of market microstructure, continue with Hasbrouck.
References
- Harris, Trading and Exchanges, Ch. 3. Oxford University Press, 2003. ISBN: 978-0-19-514470-3.
- Hasbrouck, Empirical Market Microstructure. Oxford University Press, 2007. ISBN: 978-0-19-530164-9.