matching-engine

matching-enginev0.1.0

Rust · spot matching service

Price first. Time next.

Match spot orders with price-time priority and eight-decimal fixed-point arithmetic. Connect over TCP or Unix sockets, persist decisions in a write-ahead log and recover orders and sessions after a restart.

Rust · MIT · Last update

Single-node service. Balances, settlement and failover are handled by your platform.

Illustrative order flowmatching-engine
ASK  #41   100.01 × 2
ASK  #42   100.02 × 3

BUY  #43   100.02 × 3
  →  2 @ 100.01  maker #41
  →  1 @ 100.02  maker #42

REST #42   100.02 × 2

matching-engine

From order entry to recovery

Orders with precise rules

Limit, market, stop, trailing-stop and iceberg orders. Choose GTC, IOC, FOK or GTD, with maker-only flags and optional self-trade prevention.

Recovery you can trace

With WAL enabled, durable decisions, snapshots and retained session history support recovery and idempotent mutation retries.

A service you can integrate

Binary protocol v2, a Go client and examples in Go, Python, TypeScript and Rust. TLS/mTLS, Prometheus metrics and health/readiness endpoints.

Rust · spot matching service

Start local. Integrate deliberately.

  1. Build and run locally

    Use Rust 1.96 or newer. Build the TLS-enabled server, then start it with config.toml. The sample binds trading to 127.0.0.1:9090 and HTTP to port 9091.

  2. Connect your client

    Check /ready, then run the Go example with a fresh data directory. Read the handbook for message framing, session replay and mutation request IDs.

  3. Prepare your deployment

    Choose persistent storage and a fixed shard count. Configure TLS and risk limits; keep account balances, settlement and failover in your surrounding platform.

01 / Install

Install

git clone https://github.com/rekurt/matching-engine.git && cd matching-engine && cargo build --release --locked -p me-server --features tls && ./target/release/me-server --config config.toml

02 / README

Documentation

Rust spot matching service with price-time priority, fixed-point orders, WAL recovery and a binary TCP protocol.

Setup, examples and API reference.

README ↗
Read the documentation

matching-engine

CI Site

A Rust service for matching spot orders with price-time priority. Each symbol is processed by one shard worker; clients connect through a binary protocol over TCP or Unix domain sockets.

Features

  • Limit, market, stop-limit, stop-market, trailing-stop and iceberg orders; GTC, IOC, FOK and GTD.
  • Fixed-point prices and quantities with eight decimal places.
  • Per-symbol risk checks, order ownership, maker-only flags and optional self-trade prevention.
  • Durable decisions, snapshots, session replay and idempotent mutation retries when WAL is enabled.
  • TLS/mTLS, Prometheus metrics, health checks and authenticated trading halt/resume.
  • Go client and Go, Python, TypeScript and Rust integration examples.

Build and run

Requires Rust 1.96 or newer. From the repository root:

cargo build --release --locked -p me-server --features tls
./target/release/me-server --config config.toml

The sample configuration listens on 127.0.0.1:9090 for trading and 127.0.0.1:9091 for HTTP, and stores journals under ./data/wal.

In another terminal:

curl --fail http://127.0.0.1:9091/ready
cd examples/go
go run . 127.0.0.1:9090

Use a fresh data directory for the example: order IDs and mutation request IDs are retained for recovery. For a remote deployment, configure TLS, a fixed shard count and persistent storage as described in the deployment guide.

Service boundaries

This is a single-node matching service. Account balances, reserved funds, settlement, replication and failover belong to the surrounding platform. Session IDs are bearer credentials, not account identities. Journals and retained mutation history grow with activity; online compaction and legacy journal migration are not implemented. The example clients do not implement full settlement or reconnect recovery.

No latency SLA is implied. Measure the complete durable path on your own storage and workload; engine microbenchmarks exclude network and synchronous journal costs.

Documentation

Project website · All projects by rekurt

The online handbook is built from docs/src:

Build the handbook with mdbook build; generate Rust API documentation with cargo doc --workspace --no-deps --all-features --locked.

License

MIT, copyright nikita42 (rekurt).

matching-engine

Build on an explicit matching contract.

Build and run →