A modern C++20 implementation of a high-frequency trading system featuring a matching engine, order book management, and market data processing.
- Low-latency matching engine with price-time priority
- Lock-free order book implementation
- Template-based design with C++20 concepts
- Comprehensive test suite using Boost.Test
- Performance benchmarking with Google Benchmark
# Install dependencies using Homebrew
brew install cmake boost tbb google-benchmarksudo apt-get install build-essential cmake libboost-all-dev libtbb-dev libbenchmark-devAlways clean build after changes:
# Clean and rebuild
rm -rf build
mkdir build && cd build
cmake ..
make
# Run tests with detailed output
ctest --output-on-failureRun specific test suites:
./tests/hft-tests --run_test=OrderBookTests
./tests/hft-tests --run_test=MatchingEngineTestshft-trading-system/
├── include/ # Header files (.hpp)
│ ├── Concepts.hpp # Type constraints
│ ├── MatchingEngine.hpp # Order matching
│ ├── OrderBook.hpp # Order management
│ ├── MarketDataFeed.hpp # Market data handling
│ └── Utils.hpp # Utilities
├── src/ # Source files (.cpp)
├── tests/ # Test suite
└── build/ # Build artifacts (not in git)
#include "MatchingEngine.hpp"
#include "OrderBook.hpp"
#include "Utils.hpp"
// Initialize matching engine
hft::MatchingEngine<double, int64_t, uint64_t> engine;
// Set up fill callback
engine.set_fill_callback([](const uint64_t& id, double price, int64_t quantity) {
std::cout << "Order " << id << " filled: " << quantity << " @ " << price << std::endl;
});
// Create and submit an order
typename hft::OrderBook<double, int64_t, uint64_t>::Order order{
.id = hft::utils::generate_order_id(),
.price = 100.50,
.quantity = 100,
.is_buy = true,
.timestamp = hft::utils::current_time()
};
engine.handle_order(order);- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see the LICENSE file for details.