Skip to content
Criée

Teacher sheet

Architecture of a trading venue

Who it is for
Developers, software architects and computer science students; curious finance students can follow each lesson’s opening picture, the code requires reading TypeScript.
Prerequisites
  • The lessons “Modelling an order”, “The book, a sorted structure” and “An engine’s invariants” in The market in code course (/en/developpeur/).
  • The order book and the auction: the student course (/en/etudiant/).
  • Reading TypeScript and a unit test.

Sessions

Session 1 · An order’s path, the gateway, the checks80 min

  • Seven components, one path
    • Name the seven components of a trading venue in the order an order follows
    • Calculate the amount paid for an order filled at two price levels
    • Place the checks described by the BVMAC in the brokerage firm’s aggregator
  • The gateway, a numbered door
    • Spot a numbering gap in a session and say which messages to request
    • Explain how an increasing identifier makes a resent order be ignored
    • Calculate the number of messages refused by a rate limit
  • Pre-trade risk checks
    • Calculate the bounds of a price collar and reject a limit outside them
    • Calculate the maximum quantity a value cap allows
    • Justify the order of the checks, from cheapest to most expensive
  1. 10 min · Opening question: “Between your phone and the book, how many steps does an order go through?” List on the board, kept
  2. 20 min · Reading of “Seven components, one path”: the animated order journey, amount paid across two levels, why the sequencer is unique; compare with the list; quiz
  3. 25 min · Reading of “The gateway, a numbered door”: the gateway expects message 3 and receives 4, an increasing identifier against duplicates, rate limit; quiz
  4. 20 min · Reading of “Pre-trade risk checks”: the animated gate, an order for 500 shares at 10,900 with a reference of 10,000 and a 10% limit, value cap, order of checks; quiz
  5. 5 min · Wrap-up: everyone writes the seven components in path order

Session 2 · Sequence, dissemination, latency80 min

  • The sequencer and determinism
    • Explain why the sequence number, not the time, sets the processing order
    • Spot a read in code that breaks the engine’s determinism
    • Place the writing of an entry to the log before the engine processes it
  • Publishing market data
    • Calculate the size of a MoldUDP64 packet from the number of messages
    • Spot a gap in a numbered feed and say which messages to request again
    • Explain why a market data feed publishes its prices as integers
  • Latency and fairness
    • Calculate a median or a percentile by the nearest-rank method
    • Define latency as the time between two passes through the gateway
    • Compare IEX’s common delay and batch auctions with the race for speed
  1. 10 min · Day’s review at /en/revision/: everyone answers the questions that are due, then the ones several people missed are corrected aloud
  2. 20 min · Reading of “The sequencer and determinism”: the animated sequencer race, number rather than time, a read that breaks determinism in a code excerpt; quiz
  3. 25 min · Reading of “Publishing market data”: MoldUDP64 packet size, a subscriber at 120 receiving a packet starting at 124, integer prices; quiz
  4. 20 min · Reading of “Latency and fairness”: median and percentile by nearest rank, IEX’s common delay and batch auctions versus the speed race; quiz
  5. 5 min · Wrap-up: everyone writes why a good average can hide poor latency

Session 3 · Failure, audit and testing85 min

  • Failing without losing anything
    • Explain why the log is replicated before an entry is processed
    • Calculate how long a replay takes from the log size and the rate
    • Explain the risk of two machines that both believe they are primary
  • After the trade: post-trade and audit trail
    • Correct an execution with a new line and calculate its reversal
    • Explain how the last published fingerprint reveals a rewrite of the trail
    • Name the institution that currently acts as central depository in CEMAC
  • Testing a venue: load, replay, properties
    • Calculate the capacity to demonstrate from the peak of the last five years
    • Check the conservation invariant between quantities entered, executed and remaining
    • Explain what comparative replay requires and how to handle an intended difference
  1. 10 min · Recall: name two sources of non-determinism an engine must avoid
  2. 25 min · Reading of “Failing without losing anything”: replication before acknowledgement, replay duration, last published number 4 with entries 1 to 5 in the log, the risk of two primaries; quiz
  3. 20 min · Reading of “After the trade: post-trade and audit trail”: correction by a new line and reversal, a fingerprint published each evening, the CEMAC central depository; quiz
  4. 25 min · Reading of “Testing a venue”: capacity to demonstrate for a peak of 800 messages per second, the conservation invariant, comparative replay; quiz
  5. 5 min · Wrap-up: everyone writes why comparative replay does not replace property-based tests

Session 4 · Summary and assessment45 min

  • Sheet: the venue on one page
    • Find the role and key rule of each of the seven components
    • Compare the BVMAC’s written requirements with benchmarks published outside CEMAC
  1. 10 min · Day’s review at /en/revision/: everyone answers the questions that are due, then the ones several people missed are corrected aloud
  2. 15 min · The “venue on one page” sheet: each pair presents one component, its role and key rule, then BVMAC’s written requirements are compared with benchmarks published outside the CEMAC
  3. 15 min · Assessment at /en/plateforme/evaluation/, alone and without notes: 15 questions drawn from the quizzes, 11 correct answers for the certificate, to print or photograph
  4. 5 min · Wrap-up: everyone picks one component to prototype or test in their project

Tips

Quiz answer keys

39 questions, with the right answer and its explanation.

Seven components, one path

  1. Which component rejects an order whose price is outside the collar?

    → the pre-trade risk checks

    Pre-trade risk checks filter orders before they reach the book.

  2. Above all, the matching engine produces...

    → concluded executions

    It matches orders and produces executions; numbering comes from the sequencer, authentication from the gateway.

  3. According to the 2025 tender, who checks amount, cap, price and quantity?

    → the brokerage firm's order aggregator

    The document describes an aggregator installed at the brokerage firm that checks these parameters before the API.

  4. Mariam buys 40 at 10,100; she gets 20 at 10,050 and 20 at 10,100. She pays...

    → 403,000 XAF

    20 × 10,050 + 20 × 10,100 = 201,000 + 202,000 = 403,000 XAF.

  5. Which component publishes executions to every screen?

    → the market data feed

    Market data publishes the book and executions, as numbered messages.

The gateway, a numbered door

  1. The gateway expects 8 and receives 10. It...

    → asks for numbers 8, 9

    A number higher than expected reveals a gap: set aside and ask for what is missing.

  2. In OUCH, an order whose identifier is lower than the last one processed is...

    → ignored as a mere retransmission

    The OUCH 5.0 specification treats it as a retransmission and ignores it.

  3. Limit of 50 messages per second, a member sends 120. How many are refused?

    → 70

    120 − 50 = 70 messages refused; the first 50 go through.

  4. The PossDupFlag marker signals a message...

    → perhaps already received once before

    It marks a resent message, which may already have been received.

  5. Which text provides reserved IP addresses for switching to the backup?

    → the 2025 BVMAC general rules

    Article 137 of the BVMAC general rules provides these IP addresses, reserved at the members' initial connection.

Pre-trade risk checks

  1. Reference 20,000, collar ±10%. Which limit is rejected?

    → a limit at 22,500

    The collar runs from 18,000 to 22,000; 22,500 is outside.

  2. Why test the price collar before the funds?

    → it reads no account data

    The collar depends only on the order; the funds check reads shared state, which costs more to look up.

  3. The European delegated regulation requires venues to apply three checks per instrument:

    → collar, value and volume

    Article 20: price collars, maximum order value and maximum order volume.

  4. Maximum value 30,000,000 XAF. At most how many shares at 12,000?

    → 2,500 shares

    30,000,000 ÷ 12,000 = 2,500 shares; one more breaches the cap.

  5. A member's kill switch cancels...

    → its orders not yet executed

    It cancels the member's unexecuted orders; past executions remain.

The sequencer and determinism

  1. Two orders carry the same millisecond. The engine processes them in the order...

    → of their sequence number

    Only the number given by the sequencer sets the processing order.

  2. Which line breaks an engine's determinism?

    → const t = Date.now()

    Date.now() returns a different value on each replay; the time must come from the input.

  3. The sequencer writes the input to the log...

    → before the engine's processing

    Written first, the input survives an engine crash and can be replayed.

  4. Sell of 30 at 10,050; Beta (30 at 10,050) is numbered before Alpha (30 at 10,100). Beta pays...

    → 301,500 XAF

    Beta, processed first, takes the 30 shares at the sell's price: 30 × 10,050 = 301,500 XAF.

Publishing market data

  1. In MoldUDP64, a packet that contains no message serves...

    → as a heartbeat signal

    A message count of zero denotes a heartbeat, which announces the next expected number.

  2. How many bytes for a packet of five ITCH add messages?

    → 210 bytes

    20 + 5 × (2 + 36) = 20 + 190 = 210 bytes.

  3. The subscriber expects 40 and receives 42. It must...

    → request numbers 40 and 41

    40 and 41 are missing: request them, then apply 40, 41 and 42 in order.

  4. Why publish prices as integers rather than floats?

    → to avoid any rounding errors

    A float cannot represent 10.05 exactly; an integer can. ITCH and @criee/marche use integers.

Latency and fairness

  1. Measurements 10, 11, 12, 13, 200 µs. The median (nearest rank) is...

    → 12 µs

    Rank ⌈0.5 × 5⌉ = 3: the third sorted value, 12 µs. 49.2 µs is the mean.

  2. The IEX speed bump approved in 2016 imposes...

    → the same delay on every message

    Every incoming message goes through the same fibre coil: 350 µs for all.

  3. In a batch auction, arriving 90 µs earlier...

    → does not change the price

    All orders in the window are matched together; the price depends on the limits, not on the time.

  4. The European regulation measures latency between...

    → two passes through the gateway

    Article 13: from a gateway receiving a message to the same gateway sending the response.

Failing without losing anything

  1. The log is replicated before processing so that...

    → the secondary can replay everything

    The secondary rebuilds the state from the log; an unreplicated input would be lost with the primary.

  2. The European delegated regulation aims for trading to resume within...

    → about two hours

    Article 15: resumption within about two hours, data loss close to zero.

  3. Log of 900,000 entries, replay at 300,000 per second. The full replay takes...

    → 3 seconds

    900,000 ÷ 300,000 = 3 seconds.

  4. Two machines believe they are primary at the same time. The risk is...

    → two runs of numbers

    Each one numbers on its own: two processing orders, two books, two truths.

After the trade: post-trade and audit trail

  1. In CEMAC, who currently acts as the BVMAC's central depository?

    → the BEAC, on a transitional basis

    The BEAC has been approved since 2019 and acts in this role on a transitional basis; the single depository was not operational at the end of 2025.

  2. A cancelled trade appears in the audit trail as...

    → a new line that cites it

    Append-only: the cancellation is a new fact that references the original trade.

  3. Execution of 30 shares at 10,200 cancelled. The reversal gives the buyer back...

    → 306,000 XAF

    30 × 10,200 = 306,000 XAF, in the opposite direction to the original entry.

  4. The forger recomputes the whole chain. What gives them away is...

    → the last fingerprint already published

    The fingerprint published that evening, outside the system, no longer matches the new last fingerprint.

Testing a venue: load, replay, properties

  1. Peak of 2,000 messages per second over five years. The European benchmark requires at least...

    → 4,000 messages per second

    Twice the peak: 2 × 2,000 = 4,000 messages per second.

  2. A comparative replay requires above all...

    → a deterministic matching engine

    Without determinism, two replays of the same log could differ with no defect at all.

  3. 30 shares entered, 12 executed. How many remain in the book if the invariant holds?

    → 6 shares

    Remaining = entered − 2 × executed = 30 − 24 = 6 shares.

  4. The new engine breaks auction ties differently, by choice. In the replay, this difference is...

    → expected, documented, then excluded

    A new, intended rule produces an expected difference: document it and remove it from the comparison.