How asthamishra/matching-engine works
This repository is a Rust limit-order matching engine with OUCH/ITCH-style binary and REST adapters. The main workflow accepts an order, routes it to a symbol’s single-owner book, matches or updates it, and returns events or a query response. The README documents the layered runtime and shared engine; excerpts show concrete routing and book operations. Several runtime and protocol modules were not excerpted, so their connections are included only where the README supports them.
Main entry points: gateway.rs OUCH gateway · client/order.rs Order commands · order_book.rs Order book · src/order.rs REST orders
Components 20
Matching core
- Order book
matching-core/src/order_book.rs - Match operations
matching-core/src/matching.rs - Order types
matching-core/src/types/order.rs - Trade events
matching-core/src/types/trade.rs - Symbol registry
matching-core/src/symbol_registry.rs - Response types
matching-core/src/response.rs
Engine runtime
- Shared state
matching-engine/src/app_state.rs - Exchange setup
matching-engine/src/exchange.rs - Worker routing
matching-engine/src/matcher.rs - Order commands
matching-engine/src/client/order.rs
OUCH gateway
- Inbound codec
ouch-gateway/src/codec/inbound.rs - Outbound codec
ouch-gateway/src/codec/outbound.rs - Client sessions
ouch-gateway/src/sessions.rs - OUCH gateway
ouch-gateway/src/gateway.rs
REST adapter
- REST orders
rest-gateway/src/order.rs - Book queries
rest-gateway/src/book.rs
Application
- Server entry
server/src/main.rs
Other components
- Order client
- HTTP client
- TCP client
Connections 26
- TCP client → OUCH gateway: sends orders
- OUCH gateway → Inbound codec: parses frames
ouch-gateway/src/gateway.rs - OUCH gateway → Order book: matches orders
ouch-gateway/src/gateway.rs - OUCH gateway → Match operations: modifies orders
ouch-gateway/src/gateway.rs - OUCH gateway → Client sessions: tracks orders
ouch-gateway/src/gateway.rs - OUCH gateway → Outbound codec: encodes responses
- Order book → Order types: stores orders
matching-core/src/order_book.rs - Match operations → Order book: operates on
- Order book → Trade events: emits events
- Order client → Order commands: submits commands
- Order commands → Symbol registry: looks up symbols
matching-engine/src/client/order.rs - Order commands → Worker routing: routes requests
matching-engine/src/client/order.rs - Worker routing → Order book: dispatches book work
- Exchange setup → Worker routing: starts workers
- Exchange setup → Shared state: provides shared state
- Shared state → Symbol registry: holds registry
- HTTP client → REST orders: submits orders
- HTTP client → Book queries: requests data
- REST orders → Shared state: uses engine state
- Book queries → Shared state: uses engine state
rest-gateway/src/book.rs - REST orders → Order commands: routes commands
- Book queries → Worker routing: requests book data
rest-gateway/src/book.rs - Server entry → OUCH gateway: wires gateway
- Server entry → REST orders: mounts routes
- Server entry → Exchange setup: wires engine
- Order commands → Response types: returns results