LPsLux Proposals
DEX & Trading
LP-9028

CLOB Matching Engine

Final

Central limit order book matching engine — price-time priority core, four hardware backends, FIX 4.4 order entry, and replicated multi-node deployment

Category
Core
Created
2025-12-01

Abstract

The Lux CLOB is a central limit order book matching engine with price-time priority and sub-microsecond matching latency. It supports equities, options, futures, and digital assets. The same matching core ships in four backends — pure Go, C++ via CGO, Metal/MLX, and FPGA — and as the in-consensus matcher of the D-Chain dexvm (LP-9000).

Motivation

One matching core, many places to run it. The rules of a book — price-time priority, partial fills, cancel semantics — do not change when the venue moves from a colocated FPGA to a block's Verify step; only the latency and the trust model change. Specifying the core once and enumerating its backends is what keeps a fill deterministic across all of them, which is the precondition for the batch commitments of LP-9031.

Specification

Backends

EngineLanguageLatencyUse Case
Pure GoGo~1µsDefault, portable
CGO/C++C++ via CGO~200nsProduction HFT
MLXGo + Metal~500nsMac Studio acceleration
FPGAVHDL + Go~50nsColocation
In-consensusD-Chain dexvm, match at block Verify~1msChain-verified fills

The in-consensus backend is the D-Chain matcher of LP-9000: every validator re-executes the match, so a lying proposer is rejected. EVM-side settlement of its fills is the 0x9999 precompile (LP-9999).

Architecture

┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  FIX Gateway │     │  REST/WS API │     │  NATS Cluster │
│  (port 9878) │     │  (port 8085) │     │  (multi-node) │
└──────┬───────┘     └──────┬───────┘     └──────┬───────┘
       │                    │                    │
       └────────────┬───────┘────────────────────┘
                    │
              ┌─────┴─────┐
              │  Matching  │
              │  Engine    │
              │            │
              │ Order Book │
              │ Price-Time │
              │ Priority   │
              └─────┬──────┘
                    │
         ┌──────────┼──────────┐
         │          │          │
    ┌────┴───┐ ┌────┴───┐ ┌───┴────┐
    │ Market │ │ Trade  │ │ Risk   │
    │ Data   │ │ Report │ │ Engine │
    └────────┘ └────────┘ └────────┘

Order Types

  • Limit, Market, Stop, Stop-Limit
  • IOC (Immediate or Cancel), FOK (Fill or Kill), GTC (Good til Cancel)
  • Iceberg (hidden quantity), Pegged (dynamic price)

FIX Protocol

The engine accepts orders via FIX 4.4 over TCP or ZeroMQ:

  • NewOrderSingle (D), OrderCancelRequest (F), OrderCancelReplaceRequest (G)
  • ExecutionReport (8), OrderCancelReject (9)
  • MarketDataRequest (V), MarketDataSnapshotFullRefresh (W)

The public wire surface — the CCXT-shaped API and the frozen dex_* ZAP wire — is LP-9027.

Replicated Deployment

For an off-chain cluster, the engine replicates its order stream across nodes with NATS JetStream and elects a leader for exactly-once execution. This is the venue's own replication for an off-chain deployment; it is not chain consensus. When the engine runs in-consensus on D-Chain, ordering and finality come from Lux consensus and no separate leader exists.

Price Feeds

Marks and reference prices are aggregated from multiple sources:

  • CoinGecko, CoinMarketCap (crypto)
  • Alpaca, IBKR (equities)
  • CurrencyCloud (FX)
  • On-chain pools and the native oracle (LP-9005)

Rationale

Price-time priority is the only matching rule that is both simple to state and impossible to argue with after the fact: given the same ordered input, every backend produces the same fills. That determinism is what lets the FPGA, the CPU, and the chain be described by one specification rather than three.

Security Considerations

  1. Backend parity: all backends MUST produce identical fills for identical ordered input. Divergence between a hardware backend and the reference Go implementation is a consensus fault when the engine runs in-consensus.
  2. Session integrity: FIX sessions require sequence numbers, gap fill, and cancel-on-disconnect so a dropped connection cannot leave live orders unattended.
  3. Risk before match: pre-trade risk (limits, fat-finger bounds, self-trade prevention) executes ahead of the matcher; see LP-9017.
  • LP-9000 — D-Chain order book and AMM
  • LP-9001 — order types, book structures, and measured throughput
  • LP-9027 — CCXT surface and dex_* ZAP wire
  • LP-9029 — instrument types the engine matches
  • LP-9031 — batch commitments over the engine's output

References

  • Lux research: lux-lightspeed-dex (matching engine design and benchmarks), lux-perpetuals-derivatives, lux-oracle-infrastructure, lux-data-availability, lux-defi-hft-formal-verification
  • FIX 4.4: Financial Information eXchange Protocol
  • CME SPAN: Standard Portfolio Analysis of Risk
  • ITCH 5.0: NASDAQ market data protocol

Copyright and related rights waived via CC0.