Matching engine
Price-time priority books hold FIFO resting orders within ordered price levels. GTC, post-only, IOC and FOK use fixed-point arithmetic, nonce checks, reservations, fees and discardable delta buffers.
Technical note · 2026
A Rust exchange research system spanning deterministic price-time matching, signed order flow, ledger integration, real-time feeds, and experimental proof machinery.
Fast matching is only one part of an exchange. Vela explored how order handling, financial state, market data, and verification fit together.
The Rust workspace brings together a price-time priority order book, wallet-signed requests, HTTP and WebSocket interfaces, a conditional PostgreSQL ledger commit path, a Sepolia contract demo, and local commitment and proving experiments.
Deterministic matching, signed API requests, market data feeds, local state roots and batch records.
A configured PostgreSQL ledger can commit matched financial effects before customer acknowledgement.
External proving, public data availability, on-chain dispute enforcement and forced inclusion.
Recorded May 20, 2026 on an Apple M3. These isolated results have not been reproduced on the current code and do not represent exchange capacity.
realistic_mm_workload times single-threaded engine.process() calls. It excludes networking, signatures, database commits, custody, and settlement.
| Benchmark | Time (p50) | Throughput |
|---|---|---|
realistic_mm_workload | 0.38 μs / request | 2.5M ops/sec |
post_order_gtc | 9.13 μs | — |
cancel_order | 10.16 μs | — |
fill_order | 3.80 μs | — |
fok_rollback | 802 ns | — |
hft_nonce_window (20 orders) | 27.98 μs | 715k orders/sec |
credit_auto_cancel | 4.10 μs | — |
| Benchmark | Time (p50) |
|---|---|
fee_calculation_overhead/with_fees | 3.81 μs |
fee_calculation_overhead/zero_fees | 3.43 μs |
latency_percentiles/post_order_raw (p50) | 1.019 μs |
component_breakdown/user_metadata_clone | 58.2 ns |
component_breakdown/nonce_window_accept | 19.5 ns |
component_breakdown/engine_process_post_order | 1.95 μs |
The core is a Rust workspace. In ledger-backed mode, a successful financial response waits for the database commit. In demo mode without a ledger, balances are non-authoritative.
Research side path: local state roots → batch records and local data availability → experimental prover.
Price-time priority books hold FIFO resting orders within ordered price levels. GTC, post-only, IOC and FOK use fixed-point arithmetic, nonce checks, reservations, fees and discardable delta buffers.
Axum handles signed orders and cancellations, market data, account views and WebSocket topics. Short-lived account-bound sessions protect private reads; feed sequences support gap detection.
Hot books and account state live in memory. Local roots, snapshots and write-ahead records support research inspection and demo recovery. Configured ledger balances replace recovered snapshot financial values.
When configured, balanced idempotent effects and an outbox event post in one serializable PostgreSQL transaction. The API publishes proposed financial state only after that commit.
Ordered requests and fills become hashed batch records. The current data-availability adapter writes locally; a hash alone cannot ensure public access to batch data.
Deterministic replay and an SP1-compatible adapter sit behind configuration. The default provider is PlaceholderProver; no on-chain verifier is deployed.
Aggregate quoting limits can evict older resting orders across markets. A rolling 20-entry nonce window accepts overlapping signed requests without accepting a duplicate nonce. This is engine behavior, not a production credit facility.
Fixed-point values, ordered price levels and copy-on-write deltas keep order handling reproducible. Batch dispatch groups independent market work; shared financial state still needs careful merge rules.
WebSocket topics carry book, trade, market and authenticated account events. Reference charts can use external spot prices while testnet orders execute against Vela's separate synthetic book.
The repository also contains feature-gated or incomplete work on committees, TEE attestation, perpetual margin math, FIX sessions and agent interfaces.