Skip to Content
How Loaf worksMatching engine

Matching engine

The matching engine keeps each market’s order book and matches buy and sell orders under the same rules for every account. It executes signed orders deterministically at exchange speed, and every fill it makes is then proven with a validity proof and settled on Arbitrum, as Validity proofs and settlement describes.

Motivation

Physical assets have historically traded infrequently, but the matching engine is built to the standard of a high-frequency venue. Professional traders and market makers participate where execution is fast and deterministic, and markets without them stay thin. This allows a physical asset to trade with the depth and immediacy of a liquid stock.

Execution quality depends on the rules being the same for every participant. Every account, Loaf’s own market maker included, trades through the same public API under price-time priority, and every order the engine accepts is recorded in a public journal in arrival order, so matching can be verified after the fact.

Order book and priority

Each market has one central limit order book: a single list of every open buy and sell order, ranked by price. Every spot market and every perpetual future has its own book. Orders match by price-time priority: the best price first, then the earliest order at that price.

Every fill executes at the price of the order already resting on the book, not at the incoming order’s limit. An incoming order that crosses several price levels fills at each level’s price in turn.

Example. Three sell orders rest on a book when a buy order arrives for 12.0 units with a limit of US$10.05.

Resting sell orderPrice (US$)Size (units)ArrivedFilled against the buy
A10.024.0First4.0 units at 10.02
B10.026.0Second6.0 units at 10.02
C10.0510.0Third2.0 units at 10.05

A fills before B because it arrived first at the same price. The buyer gets 12.0 units for US$120.30 before fees, an average of US$10.025 a unit. C keeps 8.0 units on the book.

On perpetual futures, the risk engine works beside the matching engine: it checks margin and runs liquidations, as Margining and Liquidations describe.

Order intake

The engine writes every order it accepts to its record before it replies, so an acknowledgement means your order is on record. If the same signed order arrives twice, for example after a dropped connection, the engine places it once and returns the original result.

The intake journal is a public, hash-chained record of every order the engine took in, so anyone can check the order of arrival TBC. Hash-chained means each entry carries a fingerprint of the one before it, so entries cannot be removed, inserted or reordered unnoticed. Validity proofs check each fill against its signed terms but not arrival order, and the journal covers that gap. Most venues do not publish arrival order; Loaf does.

Every account, the Loaf Liquidity Provider (LLP) included, uses the same public API, with no privileged data and no execution priority. The LLP’s rules of engagement set this out in full. Loaf publishes the engine’s latency and throughput together with the method used to measure them TBC.

Last updated on