DocsOrderbook
Learning Path00 Start Here01 Big Picture
IntroductionWhat Is an Order BookBids and AsksSpread and Mid PriceLimit OrdersMarket OrdersDepth and Liquidity
Matching Engine Basics02 Core Domain03 Matching Flow05 Guided Exercises06 Visual Guide07 Why This Design08 Performance Bridge
ArchitectureTechnical ArchitectureUI Notes and Terminal Ideas
Engine Performance NotesPerformance
Milestones
Glossary
LearnTerminal
DocsEngine Study

02 Core Domain

Learn the engine-owned types before trying to follow matching logic.

02 Core Domain

Goal

Learn the main types before trying to follow the matching logic.

This chapter is about vocabulary and ownership.

If a term is unfamiliar, stop and look it up in docs/glossary.md before continuing.

Why this matters

A lot of confusion in exchange code comes from mixing up:

  • input sent by the caller
  • state owned by the engine
  • output produced by a trade

This repo intentionally keeps those separate.

Read these files

  • src/types.rs
  • src/order.rs
  • src/market_config.rs
  • src/errors.rs
  • src/events.rs

The most important type split

`NewOrderRequest`

This is what an outside caller asks for.

It is a request, not a promise.

It may still be rejected.

`Order`

This is what the engine stores after it accepts an order.

It has engine-owned fields such as:

  • order_id
  • sequence
  • remaining_qty

`Trade`

This is an execution record.

It is not a request and not a resting order.

It is the record of something that already happened.

Why wrapper types exist

You will see types like:

  • Price
  • Quantity
  • OrderId
  • SequenceNumber

These exist so the engine does not pass around loose primitives everywhere.

That helps because:

  • prices and quantities have market rules
  • IDs and sequences mean different things
  • accidental mixing becomes harder

The market config

MarketConfig is the rulebook for the book.

It defines:

  • which market this book is for
  • tick size
  • lot size
  • allowed decimal precision

That is why validation can be strict and deterministic.

Errors are part of the design

Do not treat errors as side noise.

In this project, typed errors are part of the engine contract.

That means:

  • invalid orders get rejected explicitly
  • bad data is not silently rounded or fixed
  • a reader can tell whether a failure came from validation or book state

A good beginner question

Pick one field and trace it across the system.

Good choices:

  • remaining_qty
  • price
  • order_id
  • sequence

For that field, ask:

  1. where is it introduced?
  2. who owns it?
  3. when can it change?
  4. which outputs expose it?

Words to look up if needed

  • NewOrderRequest
  • Order
  • Trade
  • Market config
  • Validation
  • Rejection
  • Sequence number

Check yourself

By the end of this chapter, you should be able to explain:

  • why NewOrderRequest and Order are not the same thing
  • why Trade is a separate output type
  • why the engine wraps raw numbers in domain types
  • why validation belongs before matching
PreviousNext
On This Page13
GoalWhy this mattersRead these filesThe most important type split`NewOrderRequest``Order``Trade`Why wrapper types existThe market configErrors are part of the designA good beginner questionWords to look up if neededCheck yourself