FakeX
FakeX is an experimental trading engine built to explore order matching, risk checks, settlement, write-ahead logging, and low-latency event processing in Java.
The project is intentionally small and is not intended to be a production-ready exchange. Its purpose is to demonstrate the core ideas behind a trading system and provide a foundation for further experiments and performance testing.
Current Features
- Buy and sell limit orders
- Price-time priority matching
- Partial fills and matching against multiple orders
- Order cancellation
- Basic account and balance management
- Basic buy-side funds reservation
- Separate risk, matching, and settlement processing stages
- Command processing through LMAX Disruptor
- Command journaling with Chronicle Queue
- JMH benchmarks
Architecture
Commands are published to a single-producer Disruptor ring buffer and processed through several stages:
Command ├── CommandLogger └── RiskEngine ↓ MatchingEngine ↓ SettlementEngine
The order book currently uses:
- PriorityQueue for buy and sell orders
- Long2ObjectHashMap for lookup by order ID
This implementation favors simplicity and readability over a fully optimized order-book data structure.
Limitations
FakeX is a prototype and currently has several intentional limitations:
- A single order book
- Only limit orders
- Simplified asset and balance model
- Incomplete reservation handling
- No persisted state recovery or journal replay
- No snapshots
- No networking or exchange protocol
- No market-data feed
- No high availability or replication
- Cancellation from a priority queue is linear-time
Requirements
- JDK 23 or newer
- Gradle, or the included Gradle wrapper
Build
./gradlew build
Run
./gradlew run
Benchmarks
The project includes JMH benchmarks for selected engine operations.
Run all benchmarks:
./gradlew jmh
Run a specific benchmark:
./gradlew jmh --includes=BasicOrderMatchingBenchmark
Benchmark results should be treated as local experimental measurements rather than production performance claims.
Main Libraries
- LMAX Disruptor
- Agrona
- Chronicle Queue
- Chronicle Wire
- JMH
Possible Next Steps
- Deterministic command replay
- Correct reservation release on cancellation and partial fills
- Sell-side asset reservation
- Atomic risk, matching, and settlement transitions
- Multiple instruments
- A more efficient order-book representation
- Snapshots and recovery
- Property-based and model-based tests
- More realistic latency and throughput benchmarks