Market Mechanics
This reference covers the mechanical foundations of electronic markets: how exchanges process orders, how matching algorithms determine execution priority, how market data is generated, and why these details matter for Bookmap add-on development. Every concept is structured as a discrete unit with explicit causeβeffect relationships.
1. The Core Axiomβ
Price is 100% determined by the orders of traders β and nothing else.
This is not a simplification. It is the literal, mechanical truth of how markets work:
- A trader sends an action (new order, cancel, modify) to the exchange.
- The exchange's matching engine processes the action using a public, deterministic algorithm.
- The matching engine updates the order book.
- The exchange generates market data describing what changed.
- All indicators β price, volume, VWAP, candlesticks, everything β are derived from this market data.
Key implication: When reasoning about "why price moved," the only valid causal chain is: trader action β matching engine processing β order book change β market data update. External events (wars, earnings, Fed decisions) only matter because they change traders' decisions, which change their orders. The event itself does not touch the matching engine.
2. The Exchange Architectureβ
βββββββββββββββββββββββββββββββββββββββββββββββ
β EXCHANGE β
β β
β ββββββββββββββββββββ β
β β Sync & Admin β β Atomic ordering β
β ββββββββββ¬ββββββββββ of all actions β
β βΌ β
β ββββββββββββββββββββ β
β β Matching Engine β β Deterministic β
β β βββββββββββββββ β algorithm β
β β β Order Book β β β
β β βββββββββββββββ β β
β β βββββββββββββββ β β
β β βData Generatorβ β β Market Data out β
β β βββββββββββββββ β β
β ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
β² β
Actions IN Market Data OUT
(send/cancel/modify) (executions + book updates)
β β
β βΌ
ββββββββββββ ββββββββββββββββ
β Traders β β Data Vendors β
β (via β β (redistributeβ
β brokers) β β to clients) β
ββββββββββββ ββββββββββββββββ
Key point: Every trader maintains a local copy of the order book, reconstructed from the market data stream. This copy may lag the exchange's true book by the trader's latency.
3. The Three Trader Actionsβ
There are only two or three fundamental actions a trader can perform. Everything else is a variation.
| # | Action | Parameters | Exchange Response |
|---|---|---|---|
| 1 | Send a new order | Buy/Sell, Quantity, Limit Price | Order ID (assigned by exchange) |
| 2 | Cancel an order | Order ID | Confirmation or rejection |
| 3 | Modify an order | Order ID, New Quantity, New Limit Price | Confirmation or rejection |
Why Modify Exists (Not Just Cancel + Re-Send)β
Modify is technically redundant (cancel + new order achieves the same result), but it solves two problems:
- Latency reduction: Both sub-actions execute atomically inside the exchange β no round-trip gap.
- In-flight risk elimination: If you cancel then re-send as two separate messages, the original order might fill between your cancel arriving and your new order arriving, leaving you with an unintended execution AND a new order. Modify avoids this.
- Queue preservation: If the modification only reduces size at the same price, the order keeps its position in the queue. Any price change or size increase sends it to the back of the queue.
Key insight: When analyzing order book changes via MBO data and you see a replace event at the same price with smaller size β the order kept its queue priority. If you see a replace with a different price β it lost priority (equivalent to cancel + new send).
4. Order Typesβ
4.1 Market Orderβ
- Parameters: Buy/Sell + Size
- Behavior: Executes immediately against resting orders on the opposite side, sweeping through price levels until filled.
- No price protection β you get whatever the book offers.
4.2 Limit Orderβ
- Parameters: Buy/Sell + Size + Price
- Behavior: "Do not execute at a worse price than specified."
- If the limit price allows immediate matching β partial or full fill, remainder rests in book.
- If no immediate match β order rests in book at the specified price.
4.3 Iceberg Orderβ
- Adds: Maximum displayed size (the "tip")
- Behavior: Only shows a fraction of the total size in the visible order book. As the displayed portion fills, the hidden portion refills the displayed amount.
- Detection implication: Repeated refills at the same price level at consistent size intervals signal iceberg activity. With MBO data, you can track the order ID and observe refills directly.
4.4 Stop Orderβ
- Adds: Stop price (trigger condition)
- Behavior: The order is invisible in the order book. When a trade occurs at or worse than the stop price, the exchange publishes/releases the order (typically as a market order or limit order).
- Key insight: Stop orders are part of the invisible conditional order pool. They do not appear in MBP or MBO data until triggered. This is why "stop hunts" work β the triggering trader cannot see where stops are, but can infer their location from price behavior patterns.
4.5 Other Conditional Ordersβ
Exchanges offer many variations: time-in-force conditions (GTC, IOC, FOK, DAY), order-sends-order chains, and custom types. Brokers and OMS platforms add even more flexibility on top, managing orders from co-located facilities with sub-millisecond response times.
5. The Order Bookβ
The order book has two parts:
5.1 Visible Part (What Market Data Shows)β
- Collection of resting limit buy orders (the bid book) and limit sell orders (the ask book).
- These orders rest because their limit price has not yet permitted a match.
- Orders at the same price form an order queue, with priority determined by the matching algorithm.
5.2 Invisible Part (Conditional Orders)β
- Stop orders, hidden iceberg portions, time-conditional orders.
- These exist at the exchange but are not reflected in any market data until their trigger condition is met.
- Key insight: The visible book is always an incomplete picture. Significant liquidity may be hiding as stops, icebergs, or other conditional orders. Never assume the visible book represents total supply/demand.
5.3 Order Queue Mechanicsβ
- Orders advance in the queue when orders in front of them are cancelled or executed.
- Queue position is valuable β it determines execution priority.
- The matching algorithm determines how the queue is structured and how priority is assigned.
6. Market Data Typesβ
6.1 Market by Price (MBP)β
- Shows the total aggregate size at each price level.
- May be full depth or limited (top 5, 10, or 20 levels).
- You see: "There are 350 contracts bid at 5950.00" β but NOT how many individual orders make up those 350.
- Limitation: Cannot distinguish between one order of 350 and thirty-five orders of 10. Cannot detect individual order behavior (spoofing, icebergs, queue dynamics).
6.2 Market by Order (MBO)β
- Shows individual orders with unique Order IDs, their price, size, and queue position.
- Provides full market depth.
- You see: "Order #A7F3 is a bid for 25 contracts at 5950.00, position 3 in queue."
- This is the more modern, more transparent data type.
- Enables: Iceberg detection, spoofing analysis, queue position tracking, individual order lifecycle observation.
6.3 The Data Hierarchy (What You Lose at Each Level)β
MBO Data (100% of available information)
β
β Aggregate by price level, discard order IDs
βΌ
MBP Data (~30-50% of information)
β
β Discard book, keep only trades
βΌ
Times & Sales / Last Trade (~5% of information)
β
β Aggregate by time period
βΌ
Candlestick Charts (~1-2% of information)
Key insight: A candlestick is a lossy compression of the actual market activity. Any analysis done on candlesticks alone is working with roughly 1-2% of the available signal. Order flow analysis (MBO/MBP) recovers 50-100% of the signal.
7. Market Maker vs. Market Takerβ
Every trade has exactly two sides:
| Role | Definition | Typical Commission | Behavior |
|---|---|---|---|
| Market Maker | The resting (passive) limit order that was already in the book | Lower or even negative (exchange pays you) | Provides liquidity, earns spread + rebate |
| Market Taker | The newly arrived (aggressive) order that matches against the resting order | Higher | Consumes liquidity, pays spread + commission |
Key insight: The commission structure directly shapes market behavior. When maker rebates are high (like BitMEX's -0.025% maker / 0.075% taker), traders compete intensely to be the maker rather than taker. This causes:
- Thick resting liquidity at popular levels (everyone wants to be the passive side)
- Price tends to move in discrete jumps rather than smooth ticks (takers need enough expected move to overcome the cost)
- Aggressive "queue competition" where traders race to place limit orders early
Key insight: When analyzing any market, always consider the commission structure. It determines whether the dominant behavior will be aggressive (taker-friendly markets) or passive (maker-friendly markets).
8. Matching Algorithmsβ
8.1 FIFO (Price-Time Priority)β
The most widely used algorithm. Used by CME for E-mini S&P 500 (ES) futures.
Rules for processing a NEW order:
- Match/execute against resting orders on the opposite side:
- As long as the limit price permits (no limit for market orders)
- As long as the incoming order has remaining size
- Add any unfilled remainder to the order book at the end of the queue at the order's limit price.
Rules for processing a CANCEL:
- Cancel the remaining unfilled part, or reject if the order no longer exists.
Rules for processing a MODIFY:
- Reject if the order no longer exists.
- If the only change is reducing size at the same price β adjust size, keep queue position.
- Otherwise β remove from queue, process as a new order with modified price/size (loses queue position).
Implication: In FIFO markets, queue position is extremely valuable. Being first in the queue at a price level means you get filled before everyone else at that price. This creates:
- Incentive to place orders early at anticipated support/resistance levels
- "Queue scalping" strategies where the edge is purely in queue position
- Aggressive cancellation when the queue position is no longer favorable
8.2 Pro-Rataβ
Matches orders proportionally based on their size rather than arrival time.
- A large order at the back of the queue can still get a proportional fill.
- Encourages posting larger size (bigger share of the pro-rata allocation).
- Used in some interest rate and options markets.
8.3 FIFO with LMM (Lead Market Maker)β
Enhanced FIFO that gives registered Lead Market Makers priority allocations before the standard FIFO queue is processed. This means:
- LMMs get filled first at a price level, regardless of when they placed their order.
- Regular participants only get fills from the remainder.
- This is an explicit structural advantage for designated liquidity providers.
Key insight: Always know which matching algorithm applies to the instrument being traded. The algorithm fundamentally determines what constitutes an "edge" β in FIFO markets, speed and queue position matter most; in Pro-Rata markets, size matters most.
9. Latencyβ
9.1 Three Components of Latencyβ
Total Trading Cycle Latency:
1. Market Data Latency
Exchange β Your System
(receiving the information that something changed)
2. Processing Latency
Your System internally
(deciding what to do about it)
3. Round-Trip Time (RTT)
Your System β Exchange β Your System
(sending your action and receiving confirmation)
9.2 Why Latency Mattersβ
- Faster traders capture short-term opportunities before slower traders.
- If two traders identify the same opportunity, the faster one gets a better execution price.
- The slower trader either gets a worse price or misses the opportunity entirely.
9.3 Latency Distribution Is NOT Uniformβ
This is a critical insight for simulation/backtesting:
- Average latency might be ~1 millisecond for a co-located system.
- 99.99th percentile might be 100+ milliseconds.
- These extreme outliers are NOT random β they are highly correlated with bursts of market activity (when the matching engine is overloaded).
- This means: latency spikes happen exactly when you most need low latency (during volatile events when many strategies spot the same opportunity simultaneously).
Key insight: Never assume constant latency in simulations. Never assume latency outliers are randomly distributed. The correlation between latency spikes and market volatility is a fundamental structural feature of electronic markets.
9.4 Artificial Speed Bumpsβ
Some exchanges deliberately add latency delays (e.g., 350 microseconds) for regular participants while allowing designated market makers to bypass the delay. This:
- Gives structural advantage to preferred market participants
- Is publicly documented in exchange rules
- Is conceptually similar to giving LMMs queue priority β just implemented via timing rather than matching logic
10. The Two Fatal Simulation Mistakesβ
10.1 Mistake: Wrong Latency Assumptionsβ
Problem: Assuming constant average latency (e.g., 1ms) in backtests.
Why it's fatal: The most profitable-looking signals in historical data often coincide with the moments of highest latency (market activity bursts). A backtest using average latency will show great fills at these moments. In reality, your order would arrive 100ms+ late, getting a much worse fill or no fill at all.
ML/AI trap: Pattern detection algorithms will preferentially identify "obvious" opportunities that many participants simultaneously detect β precisely the moments when latency spikes and execution quality collapses.
10.2 Mistake: Ignoring Own Market Impactβ
Problem: Assuming your simulated trades would not have changed the market data you're backtesting against.
Why it's fatal: Every order affects the market. Even small orders trigger reactions from other participants (market makers adjusting, other algos responding). The cumulative effect of your activity would have produced different market data than what you observed historically.
Chaotic system analogy: Markets are chaotic systems where infinitesimal differences in starting conditions lead to drastically different outcomes over time. Your backtest is simulating trades in a universe that would not have existed if those trades had actually occurred.
Key insight: The only valid test of a strategy is live trading or an interactive simulation where other participants react to your actions. Static historical backtesting always overstates performance.
11. Information Hierarchy for Trading Decisionsβ
DATA (raw facts)
β Contains: useful signals, irrelevant noise, illusions, deceptions
β
β Structure and filter
βΌ
INFORMATION (organized, meaningful data)
β
β Interpret in context
βΌ
KNOWLEDGE (contextual understanding of patterns and relationships)
β
β Test and validate through experience
βΌ
WISDOM (validated knowledge that guides effective action)
β
β Form intentions
βΌ
DECISIONS (specific plans based on wisdom)
β
β Execute
βΌ
ACTIONS (orders sent to exchange)
β
β Observe outcomes
βΌ
FEEDBACK β loops back to DATA
Key insight: Market data is at the DATA level. It contains noise, illusions (spoofing), and deceptions alongside genuine signals. The agent's job is to help the trader ascend this hierarchy β not just relay raw data, but help convert it into knowledge and wisdom.
12. Why "Wars Don't Affect the Market" (Directly)β
This is a philosophical but practically important point:
- No external event directly touches the matching engine.
- Events affect traders' decisions, which affect their orders, which affect the order book, which affects price.
- The causal chain always passes through human (or algorithmic) decision-making.
- This is why watching order flow (the actions of traders) is, in Bookmap's words, "the fastest global news feed" β you see the reaction to events in real-time, before the news even reaches most people, by observing how market makers and HFT firms reposition.
Practical implication: Rather than trying to predict what events will happen, observe how participants with the fastest information are actually positioning. Their orders are their "vote" backed by real money β more reliable than any analyst's opinion.
13. Key Principles Summaryβ
- All price movement originates from orders. There is no other mechanism.
- The matching algorithm is public and deterministic. Given the same sequence of actions, the same result always occurs.
- The visible order book is incomplete. Conditional orders (stops, icebergs, time-based) are invisible until triggered.
- MBO > MBP > Times & Sales > Candlesticks in information content. Always use the highest-resolution data available.
- Commission structure shapes behavior. Maker-friendly markets behave differently from taker-friendly markets.
- Queue position matters in FIFO markets. Being early at a price level is itself an edge.
- Latency spikes are correlated with opportunity. The best signals are hardest to execute.
- Backtests always lie. They ignore latency reality and own market impact.
- Order flow is the fastest news feed. Watching what traders do with money beats watching what analysts say.
- Markets are interactive, chaotic systems. Every action changes the system for all other participants.
14. Glossaryβ
| Term | Definition |
|---|---|
| Aggressive order | A newly arrived order that immediately matches against resting orders. Synonymous with "market taker." |
| Ask book | The collection of resting sell limit orders, sorted by price ascending. |
| Bid book | The collection of resting buy limit orders, sorted by price descending. |
| Best bid / Best ask | The highest bid price and lowest ask price currently in the book. The "inside market." |
| Spread | Best ask minus best bid. The cost of immediately crossing from one side to the other. |
| Depth | The number of price levels (or total size) available in the order book beyond the best bid/ask. |
| FIFO | First-In-First-Out. Price-time priority matching algorithm. Orders at a price level are filled in the order they arrived. |
| Iceberg | An order where only a fraction of the total size is visible. The hidden portion refills the displayed amount after fills. |
| LMM | Lead Market Maker. A designated participant with structural advantages (queue priority, speed bump exemptions). |
| Market data | The output stream from the exchange describing all changes to the order book and all executions. |
| Matching engine | The exchange component that processes trader actions against the order book using the matching algorithm. |
| MBO | Market by Order. Data feed showing individual orders with unique IDs. Highest information content. |
| MBP | Market by Price. Data feed showing aggregate size at each price level. Less information than MBO. |
| Order book | The collection of all resting limit orders at the exchange, organized by side (bid/ask) and price. |
| Order queue | All orders at a single price level, arranged by the matching algorithm's priority rules. |
| Passive order | A resting limit order in the book. Synonymous with "market maker." |
| Pro-Rata | Matching algorithm that allocates fills proportionally based on order size rather than arrival time. |
| Queue position | An order's place in the priority sequence at its price level. Determines fill order in FIFO markets. |
| RTT | Round-Trip Time. Time from sending an action to receiving the exchange's response. |
| Speed bump | An artificial delay imposed by some exchanges on certain participants' actions. |
| Stop hunt | Price movement specifically aimed at triggering clusters of invisible stop orders, which then cascade into further movement. |
| Times & Sales | Trade-only data feed. Shows executed trades without order book context. ~5% of available information. |
See Alsoβ
- Iceberg Orders β Iceberg order mechanics and detection algorithms
- Iceberg Detector Blueprint β Technical blueprint for building an iceberg detector add-on
- Iceberg Detection Study Guide β Verification questions and answers for all concepts