MORPHIQLABS
Ferro Suite1 min read

Price-Time Priority Matching in Rust

A matching engine is judged by latency, but the real contract is deterministic priority: price first, time second, with explicit cancellation, tie-breaking, and replay semantics.

By MorphIQ Labs · Ferro Suite

Price-time priority sounds simple until the implementation has to survive real state transitions. Orders arrive, cancel, partially fill, cross multiple price levels, and interact with timestamps, client identifiers, and replay logs. The matching engine has to make the same decision every time.

For a Rust matching engine, latency matters. Determinism matters more.

The priority contract

The core rule is price first, time second. Better-priced orders fill before worse-priced orders; within a price level, earlier orders fill before later orders. Everything else in the engine should preserve that rule:

  • Insertions must maintain level order.
  • Cancellations must not disturb remaining priority.
  • Partial fills must preserve residual order state.
  • Timestamps and sequence numbers must be unambiguous.
  • Replay must reconstruct the same book and the same fills.

If two runs with the same input journal produce different fills, the engine has violated the contract even if both runs were fast.

Why explicit state beats cleverness

Matching engines invite clever data structures. The right question is not whether a structure is clever, but whether its invariants are testable and replayable. O(1) cancellation is useful. Cache locality is useful. But neither is acceptable if the book state becomes difficult to audit.

FerroMatch treats the matching core as a deterministic component. The state transition should be explainable from the input sequence, and the benchmark surface should measure the hot path without hiding correctness assumptions.

Where this fits

In the MorphIQ stack, matching is useful beyond exchange-like venues. It supports simulated fills, replayable execution state, strategy testing, and product workflows that need an execution model without claiming broker-like order routing.

The useful phrase is not "fast matching engine." It is "replay-exact matching with price-time priority."

More from Ferro Suite

July 6, 2026 · 1 min

Wavelet Feature Extraction for Time-Series ML Pipelines

Time-series ML fails quietly when the feature layer ignores scale. A price series, volatility series, or sensor stream may look like one signal, but its behavior is usually a mixture of fast noise, medium-horizon stru…

July 6, 2026 · 2 min

What a Rust Options Pricing Engine Has to Prove

A Rust options pricing engine usually gets judged by surface area first: how many models, how many Greeks, how fast the implied-volatility solver runs. That is necessary, but it is not enough. The harder question is w…

July 6, 2026 · 1 min

Rust Market Data Normalization Starts at the Boundary

Market-data infrastructure becomes fragile when every downstream component learns a different venue dialect. One feed calls it a trade condition, another calls it a flag. One stream uses exchange timestamps, another c…