Capstone Scenario¶
Objective¶
Run a complete exchange session that combines configuration, market making, trading, risk controls, clearing, market data, persistence, and reporting.
Prerequisites¶
- Chapters 01–16 completed.
- Ability to run multiple terminals/processes simultaneously.
Scenario¶
You are running a classroom exchange with three symbols (AAPL, MSFT, TSLA),
two human traders, one admin/operator, and one manual market maker per symbol.
Your goal is to open the market, provide liquidity, generate trades, trigger a
risk event, inspect P&L/statistics, and verify persistence.
Exercise 1: Generate a Fresh Config¶
pm-config-gen \
--symbols AAPL MSFT TSLA \
--gateways TRADER01:TRADER TRADER02:TRADER GW_ADMIN:ADMIN MM_AAPL_01:MARKET_MAKER MM_MSFT_01:MARKET_MAKER MM_TSLA_01:MARKET_MAKER \
--sessions-enabled \
--static-band 0.10 \
--dynamic-band 0.05 \
--output engine_config.yaml --force
Open the file and confirm the symbol and gateway sections are present.
Checkpoint: config contains 3 symbols, 2 traders, 1 admin, and 3 MMs.
Exercise 2: Start the Exchange Stack¶
Use separate terminals:
pm-engine --config engine_config.yaml --verbose
pm-scheduler
pm-stats
pm-clearing
pm-audit --terminal
pm-viewer --symbol AAPL
Checkpoint: every process starts cleanly and connects.
Exercise 3: Connect Gateways¶
Open gateway terminals:
pm-alf-console --id TRADER01
pm-alf-console --id TRADER02
pm-alf-console --id GW_ADMIN
pm-alf-console --id MM_AAPL_01
pm-alf-console --id MM_MSFT_01
pm-alf-console --id MM_TSLA_01
Checkpoint: all gateway identities authenticate.
Exercise 4: Provide Manual MM Liquidity¶
Submit quotes:
MM_AAPL_01> QUOTE|SYM=AAPL|BID=149.95|ASK=150.05|BID_QTY=500|ASK_QTY=500|TIF=DAY|QUOTE_ID=AAPL-CAP-001
MM_MSFT_01> QUOTE|SYM=MSFT|BID=419.90|ASK=420.10|BID_QTY=300|ASK_QTY=300|TIF=DAY|QUOTE_ID=MSFT-CAP-001
MM_TSLA_01> QUOTE|SYM=TSLA|BID=249.75|ASK=250.25|BID_QTY=200|ASK_QTY=200|TIF=DAY|QUOTE_ID=TSLA-CAP-001
Verify with QLEGS|SHOW=ALL on each MM gateway and BOOK|SYM=... from a trader.
Checkpoint: every symbol has a live two-sided market.
Exercise 5: Generate Trades and Amendments¶
From TRADER01:
TRADER01> NEW|SYM=AAPL|SIDE=BUY|TYPE=MARKET|QTY=100
TRADER01> NEW|SYM=MSFT|SIDE=BUY|TYPE=LIMIT|QTY=100|PRICE=419.50|TIF=DAY
TRADER01> ORDERS
TRADER01> AMEND|ID=<msft_order_id>|PRICE=419.70
From TRADER02:
Checkpoint: you have at least one market fill, one amended order, and one cross-trader fill.
Exercise 6: Trigger an Operator Action¶
From the admin gateway:
Try to trade TSLA from a trader gateway and confirm it is rejected. Then resume:
Checkpoint: symbol halt blocks trading and resume restores it.
Exercise 7: Inspect P&L, Audit, and Stats¶
Check the observer terminals and run:
Explain what each observer showed:
pm-clearing: positions and P&L.pm-audit: raw event stream.pm-stats-cli: persisted trade/statistics view.pm-viewer: current book state.
Checkpoint: you can trace one trade through all observers.
Exercise 8: Persistence Check¶
Place a GTC order, restart the engine, and confirm whether it restores:
Restart pm-engine, reconnect TRADER01, then run:
Checkpoint: you can explain what persisted and what expired.
Final Review Questions¶
Answer these without looking at earlier chapters:
- Which process owns the order book?
- Which commands create, amend, cancel, and inspect resting orders?
- Why does a quote have both a
quote_idand two child order IDs? - What is the difference between public market data and drop-copy?
- Which order types never rest on the book?
- What happens to DAY vs GTC orders at session close?
- How do you halt and resume a single symbol?
Checkpoint: you can answer every question from memory or by using the user guide.
Review map:
- Q1: Architecture Overview
- Q2: Gateway Commands
- Q3: MM Quotes Concept
- Q4: Drop Copy
- Q5: Order Types
- Q6: Time-in-Force & Session Lifecycle
- Q7: Controlling the Exchange
Further Reading¶
- How an Exchange Works
- User Guide
- Architecture Overview
- Glossary
- Exchange Observer Processes
- Order Book Deep Dive
You have completed the capstone. Finish with 18 — Exchange Observer Processes to compare the different live views of the exchange.