A lightweight, high-performance matching engine built in Go with REST APIs using Echo.
Supports basic limit and market order matching with an in-memory order book.
- REST API built with Echo
- Limit and Market order support
- In-memory order book using heap-based priority queues
- Real-time trade execution
- Clean modular design (API, Algo, Types packages)
- Ready for WebSocket integration
├── engine
│ ├── handlers
│ │ └── validateInput.go
│ ├── matchingAlgorithm.go
│ ├── orchestrator.go
│ └── submitOrderEntry.go
├── go.mod
├── go.sum
├── loadtest
│ ├── cancel_order.lua
│ ├── get_orderbook.lua
│ ├── get_status.lua
│ └── post_order.lua
├── main.go
├── Matching_Engine_Documentation.md
├── metrics
│ └── metrics.go
├── README.md
├── routes
│ ├── api
│ │ ├── get_orderbook.go
│ │ ├── order_cancel.go
│ │ ├── order.go
│ │ └── order_status.go
│ ├── health.go
│ └── metrics.go
├── run_bench.sh
└── types
├── heap.go
├── order.go
├── registry.go
└── response.go
git clone https://github.com/baync180705/low-latency-matching-engine.git
cd low-latency-matching-enginego mod tidygo run main.goServer runs by default on http://localhost:8080
Load Testing using wrk is supported
Make the shell script executable
chmod +x run_bench.shRun the script
./run_bench.shBelow are the benchmark results obtained from one of the test runs:
| Metric | Value |
|---|---|
| Orders Received | 391,896 |
| Orders Matched | 503,497 |
| Orders Cancelled | 74,380 |
| Orders In Book | 75 |
| Trades Executed | 316,321 |
| Latency P50 (ms) | 0.003 |
| Latency P99 (ms) | 0.073 |
| Latency P99.9 (ms) | 0.595315 |
| Throughput (orders/sec) | 22,870.64 |
- Metrics API
- WebSocket order/trade stream
- Persistent orderbook using Redis or PostgreSQL
- Amend orders