Low-latency system that consumes historical market data from Databento, passes it through a lock-free ring buffer, and processes it in a separate thread to compute a simple real-time statistic.
- Lock-Free MPMC Queue: High-performance lock-free ring buffer for concurrent data processing
- Databento Integration: Seamless integration with Databento C++ API
- BBO Schema Support: Optimized for Best Bid/Offer (BBO) historical data
- Asynchronous Processing: Non-blocking data fetching and processing
- Performance Metrics: Built-in monitoring and statistics
┌─────────────────┐    ┌──────────────────────┐    ┌─────────────────┐
│   Databento     │    │   MPMC Lock-Free     │    │   Consumer      │
│   Historical    │───▶│   Ring Buffer        │───▶│   Threads       │
│   API           │    │   (1M capacity)      │    │  (VWAP + book)  │
└─────────────────┘    └──────────────────────┘    └─────────────────┘
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
- CMake 3.14+
- Databento C++ SDK
- API key from Databento
# Clone and setup the project
git clone https://github.com/Neelaksh-Singh/market_data_engine.git
cd market_engine_data
# Set your Databento API key as environment variable
export DATABENTO_API_KEY=<"your-api-key-here">
# Create build directory
mkdir build
cd build
# Configure with CMake
cmake .. -DCMAKE_BUILD_TYPE=Release
# Build
make -j$(nproc)
# Run the Engine
./market_engine_dataThe system uses a header-only configuration file that allows easy customization of all parameters without recompilation of dependencies.
- QUEUE_SIZE: Ring buffer capacity (default: 1M messages)
- DATASET: Databento dataset (e.g., "GLBX.MDP3" for CME futures)
- SYMBOLS: List of instruments to fetch (ES, NQ, YM futures)
- START_TIME/END_TIME: Historical data time range (ISO format)
- SCHEMA: Data schema ("bbo-1s" for 1-second BBO data)
- FETCH_TIMEOUT_SECONDS: Maximum wait time for data fetch
- ENABLE_SAMPLE_OUTPUT: Enable/disable sample data printing
- SAMPLE_PRINT_EVERY: Print sample data every N messages
- DATABENTO_API_KEY: Your Databento API key (required)
The consumer thread processes market data and provides:
- Real-time VWAP calculations per instrument
- Sample data points every 1000 messages
- Performance reports every 5 seconds
- Final summary with complete statistics
struct MarketDataPoint {
    double bid_px;           // Best bid price
    double ask_px;           // Best ask price
    int64_t timestamp_delta; // Event timestamp (nanoseconds since epoch)
    int32_t instrument_id;   // Instrument identifier
    uint32_t bid_sz;         // Bid size
    uint32_t ask_sz;         // Ask size
};The handler provides real-time performance monitoring:
- messages_received: Total messages received from Databento
- messages_processed: Total messages successfully processed
- total_latency_ns: Cumulative processing latency
- max_latency_ns: Maximum observed latency
- buffer_overruns: Queue full events
- buffer_underruns: Queue empty events
- avg_latency_us(): Average latency in microseconds
- push_success_rate(): Queue insertion success rate
- BBO-1s: Best Bid/Offer at 1-second intervals
- BBO-1m: Best Bid/Offer at 1-minute intervals
- DATABENTO_API_KEY: Your Databento API key
- CMAKE_BUILD_TYPE: Set to- Releasefor production,- Debugfor development
- CMAKE_CXX_STANDARD: C++ standard (default: 17)
- 
Queue Size: Default queue capacity is 1M messages. Adjust based on your data volume and processing speed. 
- 
Batch Processing: For high-frequency data, consider batching multiple records before processing. 
- 
Consumer Threads: Use multiple consumer threads for parallel processing of market data. 
- 
Memory Alignment: The MarketDataPoint structure is packed and cache-line aligned for optimal performance. 
- 
Build Errors: Ensure Databento C++ SDK is properly installed and CMake can find it. 
- 
API Key Issues: Verify your DATABENTO_API_KEYenvironment variable is set correctly.
- 
Queue Overruns: If you see many buffer overruns, increase queue size or add more consumer threads. 
- 
Connection Issues: Check your internet connection and Databento API status. 
Enable debug mode by building with:
cmake .. -DCMAKE_BUILD_TYPE=Debug
makeThis project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For issues related to:
- Databento API: Contact Databento Support
- This Implementation: Open an issue in the repository
- Databento for providing the market data API
- The C++ community for lock-free queue implementations

