Free lesson · Execution & microstructure
Make the order lifecycle auditable
Open interactive lessonPractice calculationsExplore labs
Start with the idea
The broker, market-data feed and internal ledger can temporarily disagree. Treating acknowledgements, fills and cancellations as separate events avoids confusing “requested” with “executed.”
Symbols, units & horizon
- Q_old: reconciled signed position before fills
- ΔQⱼ: signed executed fill j
- Q_new: old position plus executed fills
- Q_target: desired signed position
- Q_open: signed remaining acknowledged open orders
- Residual intent: target minus reconciled position minus open quantity
- Signed quantities: buys positive, sells negative
- dⱼ: fill direction, +1 buy and −1 sell
- qⱼ: positive fill size
- Pⱼ: fill price in currency per unit
- feesⱼ: currency cost of fill j
When and why to use this
Use reconciliation invariants during partial fills, cancellations, reconnections and restarts. They are essential wherever an automated strategy has outstanding orders.
An order can be created, submitted, acknowledged, partially filled, filled, cancelled, or rejected. A network timeout does not tell you which state the broker reached. Submitting a replacement blindly can double the intended position.
- Assign a stable client order ID and persist intent before submitting. Query and reconcile an uncertain outcome before retrying.
- Update exposure from fills, including partial fills, rather than requested order quantity.
- Treat a cancellation request as pending until confirmed; fills can arrive during cancellation.
- On restart, reconcile open orders, positions, cash, and execution history before issuing new orders.
- Use pretrade limits for exposure, price deviation, order size, stale data, and trading hours; define a human escalation path.
Research sources, review dates and limitations
Extend the research question
Replay incomplete fills and cancellation races. Reconcile cash and position changes at every event; an observed touch does not prove an order would fill.
Continue with the connected research module →
Connect the ideas: Cash flows and accounting
Retrieve: Track units, signed cash movements and ownership at each event.
Check the change: Instrument obligations, financing and external capital flows change the ledger you need.
Math & notation → Markets & returns → Trading different assets → Research & backtests → Fund operations & capstone → Putting it all together
Self-assessed. Write your explanation before opening this comparison. A deposit raises the balance without being investment P&L. Reconcile external flows separately from fills, fees and marked holdings.Explain it yourself: Why can an account balance rise without an investment profit?
Connect the ideas: Constraints and survival
Retrieve: A desired position must fit available capital and explicit limits.
Check the change: Portfolio weights, venue collateral, working orders and redemption obligations impose different constraints.
Risk → Portfolio construction → Optimization → Arbitrage → Crypto derivatives → Fund operations & capstone
Self-assessed. Write your explanation before opening this comparison. No. Cash may be required before the hedge pays, or in another account. Check the path, collateral location and feasible transfer times.Explain it yourself: Can an offsetting terminal payoff remove a margin problem today?
Reconcile signed positions after fills
- Position after a set of unique fills is , with buy sign +1 and sell sign −1.
- Cash changes by . Cancel requests do not alter filled positions; only confirmed executions do.
Starting with 40 shares and $10,000, a buy fill of 10 at $50 with $1 fee produces 50 shares and $9,499 cash. Replaying the same fill ID must change neither again.
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.
def reconcile_position(old_position, signed_fills):
return old_position+sum(signed_fills)
def residual_order(target, reconciled_position, acknowledged_open_quantity):
return target-reconciled_position-acknowledged_open_quantity
print(reconcile_position(40,[10,-5]), residual_order(100,45,30))
def reconcile_cash(starting_cash, signed_quantity_price_fee):
"""Apply unique execution IDs once upstream before supplying this ledger."""
return starting_cash-sum(q*p+fee for q,p,fee in signed_quantity_price_fee)
Continue learning
Execution & Market Microstructure — all lessons- The spread is a price for immediacy
- Measure implementation shortfall
- Capacity is where alpha meets market impact
- Make the order lifecycle auditable
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations