Sub topic 8
Limit orders: certain price, uncertain fill
A limit order sets the worst price you will accept, and it can fail to fill at all. This chapter covers how a limit order interacts with the order book, how to choose the limit price for a buy or a sell, and what happens when the order is only partly filled or not filled.
It assumes you can read a quote (bid, ask, spread), know what a market order is, and are comfortable with simple arithmetic on prices and quantities. This is educational material, not investment advice.
What a limit order promises
A limit order has two parts: a side (buy or sell) and a limit price.
- A buy limit means "pay this price or less per share."
- A sell limit means "receive this price or more per share."
The limit price is a boundary, not a target. The broker will never fill you at a worse price than the limit. It makes no promise that the order will fill, fill fully, or fill soon.
That is the trade-off with a market order:
| Property | Market order | Limit order |
|---|---|---|
| Price | Uncertain; you take what the book offers | Bounded by your limit |
| Fill | Almost always fills if there is a market | May not fill, or may fill partly |
| Main risk | Slippage | Missing the trade |
| Best used when | Speed matters and the spread is tight | Price matters more than speed |
The limit is a cap, not the price you pay
Suppose the quote is bid 49.98, ask 50.02, and you place a buy limit at 50.10. Your order is above the best ask, so it matches immediately. You pay 50.02 per share, the price of the sellers' orders. Your limit never entered into the price. It only said how far up the asks you were willing to go. Getting a better price than your limit is called price improvement.
An order whose limit price lets it match right away is called a marketable limit order. A buy limit at or above the best ask is marketable. So is a sell limit at or below the best bid. A limit order that does not match goes onto the order book and waits. That is a resting order.
Simulating a buy limit
This code walks up a list of asks. It is the same function used to compare market and limit orders.
def fill_buy(asks, qty, limit=None):
"""Simulate a buy against a list of (price, size) asks.
limit=None behaves like a market order; otherwise like a limit order."""
filled, cost = 0, 0.0
for price, size in sorted(asks):
if limit is not None and price > limit:
break
take = min(size, qty - filled)
filled += take
cost += take * price
if filled == qty:
break
avg_price = cost / filled if filled else None
return filled, avg_price
asks = [(50.02, 100), (50.05, 200), (50.10, 500)]
print(fill_buy(asks, 400)) # market order
print(fill_buy(asks, 400, limit=50.05)) # limit orderThe market order fills all 400 shares at an average of about 50.055. It reaches into the 50.10 level for the last 100 shares. The limit order stops before 50.10. It fills 300 shares at an average of 50.04 (100 at 50.02 and 200 at 50.05) and leaves 100 shares unfilled.
Those 100 shares do not vanish. The broker routes them to the book as a resting bid at 50.05. They now sit above the old best bid of 49.98, so the visible spread narrows. They fill only if sellers come to you at 50.05 or lower.
The sell side mirrors the buy side
For a sell, the order walks down the bids from the highest price, and the limit is a floor.
def fill_sell(bids, qty, limit=None):
"""Simulate a sell against a list of (price, size) bids.
limit=None behaves like a market order; otherwise like a limit order."""
filled, proceeds = 0, 0.0
for price, size in sorted(bids, reverse=True):
if limit is not None and price < limit:
break
take = min(size, qty - filled)
filled += take
proceeds += take * price
if filled == qty:
break
avg_price = proceeds / filled if filled else None
return filled, avg_price
bids = [(49.98, 150), (49.95, 100), (49.90, 400)]
print(fill_sell(bids, 300)) # market sell: all 300 fill
print(fill_sell(bids, 300, limit=49.95)) # limit sell: 250 fill, 50 restThe limit sell fills 250 shares at an average of 49.968 (150 at 49.98 and 100 at 49.95). The remaining 50 shares rest on the book as an ask at 49.95.
Choosing the limit price
Pick the limit by deciding which risk you care about more.
- Fill quickly at a fair price. Set a buy limit at or just above the ask. Set a sell limit at or just below the bid. You are using a limit order as a market order with a price cap.
- Get a better price and accept waiting. Set a buy limit at or near the bid, or between bid and ask. You may get filled at a better price, or the price may move away and leave you unfilled.
- Wait for a target price. Set a buy limit well below the market. This is a decision to buy only if the price falls to a level you chose.
A common mistake is placing the limit on the wrong side of the market. A buy limit far above the ask fills immediately at the asks, so it gives no protection against a spike unless the limit is also near the current price. A sell limit below the bid fills right away at the bid, usually not what you meant. Check the side and the price against the quote before you submit.
A sample ticket for a patient buy:
Side: BUY
Symbol: XYZ
Quantity: 20
Order type: LIMIT
Limit price: 50.00
Time in force: DAY
Estimated cost: 20 x 50.00 = 1000.00 at most, plus any feesWith the quote bid 49.98 and ask 50.02, this order sits below the ask. It rests on the book as the new best bid at 50.00. It fills only if the price falls to 50.00 or lower. If the order fills, the most you can pay is 1000.00 plus fees, and the fill can be cheaper per share.
Why an order may not fill even when the price touches your limit
"The stock traded at my price" does not guarantee your fill. Reasons:
- Queue priority. Orders at the same price are usually filled in the order they arrived (price-time priority). If 5,000 shares were bid at 50.00 before you, sellers must exhaust them first.
- A print is not a match for you. A trade at 50.00 may have been matched with orders ahead of yours. It may also have occurred on a different venue or at a better price through price improvement.
- Partial fills. Only part of your quantity may trade before the price moves away.
- Time in force. A day order expires at the close. A good-til-canceled (GTC) order stays active longer, and the next chapter covers how long.
- Price increments. Prices move in ticks, commonly 0.01 for stocks priced above 1.00. A limit of 50.005 is generally not accepted or gets rounded. Use valid increments.
Gaps and the limit's protection
A limit order protects you in a gap. Suppose a stock closes at 50.00 and opens at 55.00 after news. A buy limit at 50.10 will not fill at 55.00. It stays unfilled, and you avoid the jump. A market buy would have paid about 55.00. A sell limit at 50.00 placed beforehand would fill at 55.00 or better at the open, because a limit sell fills at your limit or higher. A limit sell is a promise of a minimum, not a maximum.
Limit orders in thin markets and extended hours
When the spread is wide or few shares are displayed, a market order can slip a lot, and limit orders are the safer choice. The same applies outside regular hours. Many brokers accept only limit orders then, because liquidity is low and quotes are unstable. Treat the extended-hours chapter as the place for details.
Practical checks before sending a limit order
- Is the side correct, and is the limit on the intended side of the current bid and ask?
- Would the order be marketable? If so, expect an immediate fill at the book prices, not at your limit.
- Is the quantity times the limit price within your buying power?
- Does the time in force match how long you want the order to stay active?
- Are you comfortable with a partial fill or no fill?
Exercise
A stock quotes bid 49.98 and ask 50.02. The asks are (50.02, 100), (50.05, 200), (50.10, 500). You place a buy limit for 250 shares at 50.05. What is filled right away, at what average price, and what happens to the rest?
Show answer
The order is marketable because 50.05 is above the best ask. It fills 100 shares at 50.02 and 150 shares at 50.05, so all 250 shares fill. The cost is 100 x 50.02 + 150 x 50.05 = 5002 + 7507.50 = 12509.50, an average of 50.038 per share. No shares remain, because the 50.05 level has 200 shares and you needed only 150. Your limit of 50.05 was never exceeded.
Exercise
You hold shares and place a sell limit at 49.90 when the bid is 49.98. You wanted to wait for a higher price. What went wrong, and how would you fix it?
Show answer
A sell limit at or below the best bid is marketable, so it fills right away at the bid prices (49.98 and below down to 49.90), not at 49.90. You placed the limit on the wrong side of the market. To wait for a higher price, set the sell limit above the current ask, for example 50.30, and accept that it may not fill.