This is an attempt to implement a matching engine with Rust. Currently, I have created an implementation of a Limit Order Book. The LOB offers fast processing of the ITCH data clocking at 11.3 Million messages per second (or a latency of 88 ns) as tested on my local machine. Checkout the Performance section for more information.
- Project Structure
- Build, Run, and Test
- Device Specifications
- Performance
- ITCH Specifications
- Contributing
- Credits
- License
These project consists of two libraries:
- itch-parser: This library is responsible for managing the processing of NASDAQ ITCH 5.0 protocol data. It parses the useful fields that will be required for the Limit Order Book. The remaining fields are skipped using placeholders. Check out the folder's README for more information.
- optimized-lob: This library contains a streamlined and efficient implementation of a Limit Order Book (LOB). It is worth noting that the LOB simply stores a few useful fields that will be required for creating a LOB. It just keeps an aggregate quantities at each level. Check out the folder's README for more information.
Apart from that, there is a testing suite for both libraries that can be found in the "tests" directory.
Make sure you have Rust installed. Also, you must download the NASDAQ ITCH 5.0 data whose instructions are available in the ITCH Specifications.
All of these operations are performed in the tests
directory.
cd tests
cargo build
or
cargo build --release
ITCH_DATA=PATH_TO_ITCH_DATA_FILE cargo run
or
ITCH_DATA=PATH_TO_ITCH_DATA_FILE cargo run --release
ITCH_DATA=PATH_TO_ITCH_DATA_FILE cargo run -- --itch-parser
or
ITCH_DATA=PATH_TO_ITCH_DATA_FILE cargo run --release -- --itch-parser
cargo test
At the time of testing:
Device: MacBook Air M2
CPU architecture: Apple M2
CPU logical cores: 8
CPU physical cores: 8
RAM total: 16 GB
RAM free: 11.5 GB
ITCH Parser Processing...
Success...
ITCH Parsing Statistics:
Total Messages: 268744780
Total Time: 6.082 seconds
Speed: 44189583 msg/second
Latency: 22 ns
LOB Processing...
Success...
Performance Metrics:
Total Messages: 268744780
ITCH Latency: 88 ns
Total Time: 23.660 seconds
Speed: 11358746 msg/second
Orderbook Statistics:
Total Add Orders: 118631456
Total Execute Orders: 5822741
Total Cancel Orders: 2787676
Total Delete Orders: 114360997
Total Replace Orders: 21639067
The project follows the Nasdaq TotalView-ITCH 5.0
standard for the processing of data.
- Protocol Specifications
- Binary Specification File
- ITCH data can be downloaded from their website: https://emi.nasdaq.com/ITCH/Nasdaq%20ITCH/
I have specifically used their 12302019.NASDAQ_ITCH50
data whose compressed file can be downloaded from here.
Contributions to matching-engine-rs are welcome! If you encounter any issues, have suggestions, or would like to add new features, please feel free to open an issue or submit a pull request. Note that I'm still learning my way around Rust and trading systems, so any feedback is appreciated!
This project is licensed under the MIT License.