A Full Trading Day¶
Learning objectives
After reading this page you will understand:
- How a real exchange trading day is structured into phases
- What happens during opening and closing auctions
- Which order types are valid in each phase
- How price discovery works at the open
- What happens to resting orders at phase transitions
The shape of a trading day¶
A stock exchange does not run as a single continuous matching session from open to close. Instead, the day is divided into session phases, each with different rules about which orders are accepted and whether matching occurs.
This structure exists because:
- The opening price matters enormously (indices, ETF valuations, fund NAVs all reference it). A noisy first few seconds of continuous trading would produce a poor opening price.
- The closing price is even more important — it is the official daily settlement price used by clearinghouses and portfolio managers worldwide.
- Auctions give all participants equal footing at key moments, preventing fast players from exploiting slow ones at the open and close.
The five phases¶
┌─────────────┬─────────────────┬────────────────┬──────────────────┬─────────┐
│ PRE_OPEN │ OPENING_AUCTION │ CONTINUOUS │ CLOSING_AUCTION │ CLOSED │
│ │ │ │ │ │
│ Orders │ Orders rest, │ Live matching │ Orders rest, │ No │
│ rest, │ no matching │ on every new │ no matching │ orders │
│ no match │ ATO orders ok │ order │ ATC orders ok │ │
└─────────────┴─────────────────┴────────────────┴──────────────────┴─────────┘
6:00 AM 8:00 AM 9:30 AM 3:50 PM 4:00 PM
(typical US equity schedule — EduMatcher timings are configurable)
| Phase | Orders accepted? | Matching? | Special order types |
|---|---|---|---|
PRE_OPEN |
Yes | No | LIMIT, ICEBERG, STOP, STOP_LIMIT, TRAILING_STOP |
OPENING_AUCTION |
Yes | No | + TIF=ATO (At-The-Open) |
CONTINUOUS |
Yes | Yes | All types including MARKET, FOK, IOC |
CLOSING_AUCTION |
Yes | No | + TIF=ATC (At-The-Close) |
CLOSED |
No | No | — all orders rejected |
Enabling or disabling session handling¶
Session-phase enforcement is controlled by sessions_enabled in
engine_config.yaml:
sessions_enabled: true: the engine starts inCLOSED, accepts new orders only in open phases, and enforces auction/session rules from scheduler transitions.sessions_enabled: false: the engine ignoressession.transitionmessages and runs in perpetualCONTINUOUSbehavior, which is useful for always-open local testing.
When sessions are enabled, starting the engine outside configured session
times will keep it closed until pm-scheduler sends a transition to an
order-accepting phase.
Specifying time for the daily session¶
Phase transition times are configured in engine_config.yaml under a schedule
section, which is read by pm-scheduler (not by the engine itself). Each day
of the week gets its own five-time block; weekdays: is a shortcut for
Monday-Friday:
sessions_enabled: true
schedule:
weekdays:
pre_open: "09:00"
opening_auction_start: "09:25"
continuous_start: "09:30"
closing_auction_start: "16:00"
closing_auction_end: "16:05"
All values are HH:MM in the exchange's session timezone,
locale.session_timezone in the configuration (default Europe/Stockholm) —
not the timezone of the machine the scheduler runs on.
| Key | Phase triggered | Default (as weekdays:) |
|---|---|---|
pre_open |
PRE_OPEN |
09:00 |
opening_auction_start |
OPENING_AUCTION |
09:25 |
continuous_start |
CONTINUOUS |
09:30 |
closing_auction_start |
CLOSING_AUCTION |
16:00 |
closing_auction_end |
CLOSED |
16:05 |
If the schedule section is absent entirely, the scheduler falls back to
the built-in defaults shown above, applied Monday-Friday (weekends and bank
holidays default to CLOSED). If a block such as weekdays: is present, it
must define all five keys — a block missing one, e.g. closing_auction_end,
is rejected when the config loads rather than silently skipping that one
transition.
Saturday, Sunday and bank holidays can each be given their own block too
(weekend:/sat:/sun:/holidays:) instead of defaulting to CLOSED — see
Session Scheduling → Configuring the schedule
for the full set of keys and worked examples.
sessions_enabled must be true for the scheduler-driven schedule to take
effect. With it set to false, the engine ignores all session.transition
messages and stays in perpetual continuous mode regardless of the schedule
block.
Phase 1 — PRE_OPEN¶
The market is warming up. Traders can submit LIMIT orders that rest on the book, but no matching occurs. This allows participants to gauge where the market might open by watching the accumulating order book.
Example: GW01 submits a pre-open bid
The order is accepted and rests. No trade happens yet.
Phase 2 — OPENING_AUCTION¶
The exchange accumulates all interest before computing a single opening price.
The special TIF=ATO (At-The-Open) order type is only valid here.
Example: several participants add interest
# GW01 — institutional buy
NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=500|PRICE=150.00|TIF=ATO
# GW02 — sell at limit
NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=300|PRICE=149.80|TIF=ATO
# GW03 — sell at limit (willing to sell at a lower price)
NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=400|PRICE=149.50|TIF=ATO
The accumulated order book before uncross might look like:
BID side (buys): ASK side (sells):
200 @ 149.50 (pre-open) 300 @ 149.80
500 @ 150.00 (ATO) 400 @ 149.50
The uncross — how the opening price is computed¶
At the end of OPENING_AUCTION, the engine finds the price that maximises the total quantity traded. It does this by scanning all prices and asking: "if we execute at price P, how many shares would fill?" A buy order only counts as a "matchable buy" at a candidate price P if its own limit is P or higher — a buyer limited to $149.50 is not a willing buyer at $149.80.
For our example:
| Candidate price | Matchable buys | Matchable sells | Exec qty | Surplus |
|---|---|---|---|---|
| 149.50 | 200 + 500 = 700 | 400 | 400 | 300 |
| 149.80 | 500 | 300 + 400 = 700 | 500 ← maximum | 200 |
| 150.00 | 500 | 300 + 400 = 700 | 500 (tied) | 200 |
Above $149.50, GW01's pre-open 200-share bid drops out of "matchable buys" — its limit is $149.50, so it is not a willing buyer at $149.80 or $150.00 — leaving only GW01's 500-share ATO bid on the buy side. Equilibrium price = $149.80: both 149.80 and 150.00 reach the same maximum executable quantity (500 shares) and the same surplus (200), so the tie goes to the lower price. (The full tie-break rule minimises surplus first and only then prefers the lower price — see Session Scheduling → Equilibrium Price. Here surplus happens to be tied too, so the lower price decides directly.)
All crossable orders execute at $149.80: - GW01's ATO 500-share buy fills in full — the only buy order willing to pay $149.80 or more. - GW03's 400-share sell fills in full — its $149.50 limit is the better (lower) price, so it has priority over GW02's on the sell side. - GW02's 300-share sell fills partially: 100 of 300, which is all that is left of the 500 shares GW01's buy demands; the remaining 200 keep resting. - GW01's pre-open 200-share buy does not fill — its $149.50 limit is below the $149.80 clearing price — and keeps resting into CONTINUOUS.
Result published:
Icebergs in the uncross
An ICEBERG's hidden quantity takes part in the uncross, not just its visible peak: the matchable buys and sells above count each order's full remaining quantity, so the indicative published during the call phase is what the uncross prints. At the clearing price the hidden part still queues behind the visible orders at the same price — the uncross fills one peak at a time, and each refilled peak goes to the back of the queue, exactly as in continuous trading.
After the uncross, ATO orders that didn't fill are expired (not cancelled
by the trader — automatically removed by the engine). The order.expired
event identifies the reason as Opening auction ended. The market transitions
to CONTINUOUS.
Phase 3 — CONTINUOUS¶
This is the main trading session. Every new order is immediately swept against resting liquidity. All eight order types, and COMBO and OCO, are valid here.
Price-time priority is in full effect. See The Order Book for a detailed explanation.
Example: continuous trading in action
# GW01 posts a limit bid
NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=100|PRICE=149.90
# GW02 sweeps it with a market order
NEW|SYM=AAPL|SIDE=SELL|TYPE=MARKET|QTY=100
# Trade: 100 shares @ 149.90
STOP and TRAILING_STOP orders activate here when last_trade_price crosses
their trigger levels. See Stop Trigger Logic
for details.
Phase 4 — CLOSING_AUCTION¶
The closing auction works exactly like the opening auction, but for the end of
the day. The TIF=ATC (At-The-Close) order type is only valid in this phase.
The closing price is particularly important because: - Index rebalancing — index funds must buy/sell to match new index weights at the close, generating predictable large order flow. - Fund NAV calculation — mutual funds value their portfolios at the official closing price. - Options expiry — many options settle based on the closing price.
Example: closing auction
# Large index rebalancing buy
NEW|SYM=AAPL|SIDE=BUY|TYPE=LIMIT|QTY=1000|PRICE=152.00|TIF=ATC
# Institutional sell (taking profit)
NEW|SYM=AAPL|SIDE=SELL|TYPE=LIMIT|QTY=800|PRICE=151.50|TIF=ATC
The uncross algorithm runs and produces the official closing price.
Phase 5 — CLOSED¶
The market is closed. All incoming orders are rejected; in the trader console:
On the transition to CLOSED the engine expires every resting DAY
order (EXPIRED <id> (Trading day ended)) and every unfilled ATC order
(Closing auction ended). GTC (Good-Till-Cancelled) orders keep resting.
Stopping the engine is a separate event, not the close. When the engine shuts
down it saves every resting GTC and DAY order to gtc_orders.json in the data
directory (it also writes that file every few seconds while it runs) and
publishes system.eod to all subscribers. On the next start it restores them;
a DAY order is kept only if the business day has not changed since it was
placed.
What happens to my orders at each transition?¶
| Order TIF | At CONTINUOUS start | At CLOSED |
|---|---|---|
DAY |
Keeps resting | Expired and discarded |
GTC |
Keeps resting | Keeps resting into the next day (saved and restored across an engine restart) |
ATO |
Expired if unfilled at OPENING_AUCTION end | — |
ATC |
— | Expired if unfilled at CLOSING_AUCTION end |
Triggering phase transitions in EduMatcher¶
In production, the scheduler process drives phase transitions automatically
from the schedule block:
For testing, --now closes the engine first if it is not CLOSED, then
fires every transition of the day in quick succession, --delay seconds
apart (default 3):
You can also trigger transitions by hand from the admin console,
pm-admin --id <ADMIN gateway> (a participant with role: ADMIN). From
CLOSED the day starts with PRE_OPEN; the engine refuses a transition out
of order:
SESSION|STATE=PRE_OPEN
SESSION|STATE=OPENING_AUCTION
SESSION|STATE=CONTINUOUS
SESSION|STATE=CLOSING_AUCTION
SESSION|STATE=CLOSED
Putting it all together — a full-day scenario¶
| Time | Phase | Event |
|---|---|---|
| 06:00 | PRE_OPEN | Pre-open begins; GTC orders from earlier days are still on the book |
| 06:00–08:00 | PRE_OPEN | Participants submit limit orders; book fills but no trades |
| 08:00 | → OPENING_AUCTION | ATO orders now accepted |
| 08:00–09:30 | OPENING_AUCTION | Book accumulates; price discovery happening |
| 09:30 | → CONTINUOUS | Uncross at equilibrium price; ATO unfilled orders expired |
| 09:30–15:50 | CONTINUOUS | Live matching; all order types active; stops triggering |
| 15:50 | → CLOSING_AUCTION | ATC orders now accepted; new MARKETs rejected |
| 15:50–16:00 | CLOSING_AUCTION | Final accumulation |
| 16:00 | → CLOSED | Uncross at closing price; ATC orders expired; DAY orders expired; GTC orders carry over |