PitchHut logo
A high-performance C++ trading engine for low-latency trading strategies.
Pitch

Mercury is a cutting-edge trading engine implemented in C++, designed for optimal performance in quantitative finance. With sustained throughput of over 3.2M orders per second and microsecond-level latency, it employs custom data structures to facilitate efficient order book management, backtesting, and risk management.

Description

Mercury is a high-performance C++ trading engine designed for low-latency trading applications. This engine features a fully implemented limit order book with price-time priority matching, built from scratch utilizing optimized data structures for maximum efficiency. It serves as an educational resource, demonstrating key principles of systems programming applicable to quantitative finance, including cache-friendly design and memory management.

Key Features

  • Order Management: Supports various order types including Limit, Market, Cancel, and Modify.
  • Time-in-Force Variants: Implemented options such as GTC (Good-til-Canceled), IOC (Immediate-or-Cancel), and FOK (Fill-or-Kill).
  • Advanced Matching: FIFO matching protocol for order execution, ensuring optimal trade execution.
  • Risk Management: Pre-trade checks for position limits and exposure thresholds to ensure safety in high-volume trading scenarios.
  • P&L Tracking: Realized and unrealized profit and loss, allowing for effective performance monitoring and strategy evaluation.
  • Backtesting Framework: Comprehensive environment for simulating trading strategies with detailed execution and P&L logs.
  • Concurrency Support: Designed to leverage multi-threading capabilities with features such as a parallelized CSV parser and asynchronous I/O to enhance throughput.

Performance Metrics

  • Achieves 3.2M+ orders/sec sustained throughput.
  • Orders insertion latency averages around 320 ns.
  • O(1) complexity for order lookup, insertion, and cancellation operations.

Architecturally Robust

Using a modular architecture, Mercury's design incorporates various components:

  • Matching Engine: Processes and matches orders to optimize execution times and trading outcomes.
  • Concurrent Matching Engine: Designed for thread-safe operations, improving performance in high-concurrency environments.
  • Risk Manager and PnL Tracker: Ensures compliance with risk limits and provides detailed tracking of financial performance.

Data Structures

The engine utilizes custom data structures to enhance performance:

  • HashMap for efficient order ID lookup.
  • IntrusiveList for managing order queues at different price levels.
  • ObjectPool for reducing memory allocation overhead.

Example Usage

Integrate trading strategies with the engine seamlessly:

#include "StrategyManager.h"

MarketMakingConfig config;
config.name = "MarketMaker";
config.quoteQuantity = 100;  // Size per quote
...
StrategyManager manager(engine);
manager.addStrategy(std::make_unique<MarketMakingStrategy>(config));

Backtesting and Performance Evaluation

Utilize the backtesting facility to validate trading strategies against historical data:

./build/mercury --backtest momentum  # Executes momentum strategy backtest.

Conclusion

Mercury stands as a robust foundation for those looking to understand and implement a high-performance trading system, providing essential functionalities that can be further expanded to accommodate more complex trading frameworks.

0 comments

No comments yet.

Sign in to be the first to comment.