Trading Dev AcademyFree quant education

Free lesson · Crypto markets

Order-book depth and average execution price

Open interactive lessonPractice calculationsExplore labs

Start with the idea

The best ask covers only the quantity resting there. Larger orders consume deeper, often more expensive levels.

Symbols, units & horizon
  • i: executed price level
  • q_i: base units filled at level i
  • P_i: quote units per base unit
  • P-bar: volume-weighted execution price in quote/base
  • one order episode

When and why to use this

Estimate size-dependent execution costs for spot and cross-venue research.

The best ask covers only the quantity resting there. Larger orders consume deeper, often more expensive levels.

Walk the visible asks until the desired base quantity is filled. Multiply each fill price by its quantity and divide total quote cost by filled base units.

Visible depth is a snapshot, not a promise. Cancellations, hidden liquidity, latency and fees change actual fills. Keep unfilled quantity explicit; do not divide cost by the requested quantity when fewer units fill.

P‾=∑iqiPi∑iqi
Model assumptions, derivation and arithmetic

Order-book depth and average execution price

  1. Calculate quote cost q_iP_i at every filled level.
  2. Sum actual filled quantities and costs.
  3. Divide total cost by actual filled quantity and report unfilled units separately.
Work it by hand

Buy .5 BTC at 50,000 and .3 BTC at 50,100. Cost=25,000+15,030=40,030 quote units; average=40,030/.8=50,037.50.

Apply it in a strategy

  • Estimate size-dependent execution costs for spot and cross-venue research.
  • Record the input timestamp, executable quantity, currency and horizon. Reconcile the result with a cash-flow or state table.
  • Stress this failure condition: Static depth assumes the book survives until arrival and ignores competing orders.

Research deliverable

Build and explain a order-book depth and average execution price worksheet. Estimate size-dependent execution costs for spot and cross-venue research.

Evidence boundary: Synthetic arithmetic and scenarios illustrate mechanics. They are not historical returns, a paper replication, or evidence of an executable edge. Research sources and their access limitations are recorded at the end of this module.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

# Python 3.10+; standard library unless NumPy is imported below.
# Inputs and outputs use the units defined in this lesson. Synthetic teaching example.
def execution_average(fills):
    if not fills or any(q<=0 or p<=0 for q,p in fills): raise ValueError("Positive quantity/price fills required")
    quantity=sum(q for q,p in fills)
    cost=sum(q*p for q,p in fills)
    return quantity,cost,cost/quantity

print(execution_average([(.5,50000),(.3,50100)]))

Continue learning

Crypto Markets: Instruments, Ownership and Cash Flows — all lessons
  1. Base, quote and instrument identity
  2. Returns across two currencies
  3. Order-book depth and average execution price
  4. Stablecoin conversion is an FX route
  5. Custody claims and recovery scenarios
  6. Token issuance, unlocks and dilution
  7. Staking rewards and economic return
  8. A reconciled spot research ledger

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations