Sub topic 7
Partial Fills and Average Fill Price
Assume you already know how to read bids and asks and how market and limit orders work. This chapter focuses on what happens when an order fills in pieces at different prices.
What a partial fill means
A partial fill occurs when only part of an order executes. The remaining quantity stays open, rests on the order book, or is canceled according to the order's settings.
For example, you submit a market buy for 4 units. The ask side contains:
| Ask price | Available size | Cumulative size |
|---|---|---|
| 100.00 | 2 | 2 |
| 100.50 | 3 | 5 |
| 101.00 | 5 | 10 |
The first 2 units fill at 100.00. The next 2 units fill at 100.50. The order is completely filled, but it has two executions, often called fills or trades.
If you request 8 units, all 2 units at 100.00, all 3 units at 100.50, and 3 units at 101.00 are consumed. If you request 12 units, only 10 units are available in this displayed depth, so the order may fill 10 units and leave 2 units unfilled. The actual result depends on the exchange and order type.
Calculating the average fill price
The average fill price is a quantity-weighted average. It accounts for how many units were bought at each price:
average fill price = total cost / total filled quantityFor the 4-unit order:
total cost = (2 × 100.00) + (2 × 100.50)
= 401.00
average fill price = 401.00 / 4
= 100.25A simple average of the two prices, 100.25, happens to give the same answer here because both prices filled the same quantity. If the quantities differ, weighting matters.
# Ask side of a book: (price, size), sorted from best (lowest) price upward
asks = [(100.0, 2.0), (100.5, 3.0), (101.0, 5.0)]
def market_buy(asks, qty):
"""Walk the ask side and return (filled_qty, average_price)."""
remaining = qty
cost = 0.0
for price, size in asks:
take = min(remaining, size)
cost += take * price
remaining -= take
if remaining == 0:
break
filled = qty - remaining
average = cost / filled if filled else None
return filled, average
filled, average = market_buy(asks, 4.0)
print(filled, average) # 4.0 100.25The function walks from the best ask upward. It stops when the requested quantity is filled or when the available book levels end.
Partial fills at different prices
Suppose a limit buy for 6 units has a limit price of 100.50. It can match the 2 units at 100.00 and 3 units at 100.50. The remaining 1 unit cannot match an ask above 100.50. Depending on its time-in-force setting, that unit may rest on the book or be canceled.
The average price of the 5 filled units is:
((2 × 100.00) + (3 × 100.50)) / 5 = 100.30The limit price is a ceiling for a buy order, not a promise that every unit fills at that price.
Reading the order result
An exchange may report:
- requested quantity
- filled quantity
- remaining quantity
- individual execution prices and sizes
- average fill price
- order status, such as partially filled, filled, or canceled
Use the individual fills when you need to reconstruct fees, slippage, or tax records. Use the average fill price for a quick summary of the executed trade.
Exercise
A market buy consumes 1 unit at 50.00 and 3 units at 51.00. What are the filled quantity and average fill price?
Show answer
The filled quantity is 4 units. The total cost is 203.00, so the average fill price is 203.00 / 4 = 50.75.