A high-frequency trading (HFT) system built in C++ for ultra-low latency order execution targeting cryptocurrency derivatives markets via Deribit's exchange APIs. Engineered to achieve microsecond-level latency for critical path operations while maintaining robustness under extreme market volatility (10,000+ orders/sec).
๐บ Watch the Project Overview: High-Performance Trading Backend Demo
This High-Frequency Trading (HFT) System represents a sophisticated C++ implementation designed for institutional-grade cryptocurrency derivatives trading. The system is built from the ground up to address the unique challenges of modern electronic trading:
- Ultra-Low Latency: Achieve microsecond-level performance for critical trading operations
- High Throughput: Handle 10,000+ orders per second under extreme market conditions
- Institutional Grade: Provide the reliability and performance expected by professional trading firms
- Real-Time Processing: Deliver sub-millisecond market data and order execution
- Spot Trading: Direct cryptocurrency purchases and sales
- Futures Contracts: Leveraged derivatives with sophisticated risk management
- Options Trading: Complex derivative instruments with advanced pricing models
- Cross-Exchange Arbitrage: Multi-venue trading opportunities
- Custom WebSocket Implementation: Built from scratch for maximum performance
- Lock-Free Data Structures: Eliminate contention in high-frequency scenarios
- Hardware-Accelerated Crypto: Leverage Intel AES-NI and ARMv8 crypto instructions
- Zero-Copy Message Processing: Minimize memory allocation overhead
- Order Placement Latency: <100 microseconds end-to-end
- Market Data Processing: Real-time tick processing with <1ms latency
- Risk Calculation: Sub-millisecond position and PnL updates
- Connection Resilience: Automatic failover and reconnection handling
- Ultra-Low Latency: Microsecond-level performance for critical trading operations
- Multi-Protocol Support: REST and WebSocket interfaces for order management and real-time market data
- Comprehensive Coverage: Support for spot, futures, and options instruments
- High Throughput: Designed to handle 10,000+ orders per second
- CLI-Based Interface: Command-line tools for trading operations and system management
- Real-Time Market Data: Custom WebSocket server for streaming market information
- Robust Risk Management: Built-in position and risk controls
- Performance Benchmarking: Comprehensive latency testing and optimization tools
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Client Layer โ โ API Layer โ โ Core Engine โ
โ โ โ โ โ โ
โ โข CLI/GUI โโโโโถโ โข REST API โโโโโถโ โข Order Manager โ
โ โข Algo Engines โ โ โข WebSocket API โ โ โข Risk Manager โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ โข Execution โ
โ โข Market Data โ
โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Event Bus & โ
โ Caches โ
โ โ
โ โข In-Memory Bus โ
โ โข Time-Series โ
โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Deribit โ
โ Connectivity โ
โ โ
โ โข REST Client โ
โ โข WebSocket โ
โโโโโโโโโโโโโโโโโโโ
- CLI/GUI: Interactive user tools for manual trading
- Algo Engines: Automated trading strategies
- Order Submission: HTTP/JSON via REST API or WebSocket
- REST API Server: Synchronous HTTP requests for order management
- WebSocket API Server: Real-time market data and order updates
- JSON-RPC Parsing: Efficient payload processing
- Order Manager: Order validation and routing
- Risk & Position Manager: Real-time PnL and limit enforcement
- Execution Engine: Deribit API integration
- Market Data Distributor: Real-time tick data processing
- In-Memory Event Bus: High-throughput, lock-free pub/sub
- Time-Series Cache: Lock-free ring buffers for recent data
- REST Client: cURL/Boost.Beast for synchronous operations
- WebSocket Client: Boost.Beast/Websocket++ for streaming
Frequency_Check_Algo/
โโโ src/
โ โโโ Api.cpp/hpp # Main interface layer
โ โโโ Trader.cpp/hpp # Trading logic engine
โ โโโ main.cpp # Application entry point
โ โโโ Boost_WebSocket/ # Boost.Asio WebSocket client
โ โโโ Custom_WebSocket/ # Custom socket implementation
โ โโโ WebSocketpp/ # websocketpp library client
โ โโโ interfaces/ # Abstract interfaces
โ โโโ market_data/ # Market data handling
โ โโโ oms/ # Order management system
โ โโโ risk_management/ # Risk controls
โ โโโ strategies/ # Trading strategies
โโโ test/
โ โโโ test_latency/ # Performance testing
โโโ CMakeLists.txt # Build configuration
โโโ README.md # This file
- Responsibilities: JSON RPC serialization/deserialization
- Features: Client authentication, clean abstraction layer
- Methods: Order placement, cancellation, modification
- Technology: Boost.Asio/Beast implementation
- Features: Production-grade error handling, async I/O
- Use Case: Fallback and test environments
- Technology: websocketpp::config::asio_tls_client
- Features: TLS encryption, thread-safe async handling
- Performance: Sub-millisecond latency optimization
- Order Management: Place, cancel, modify orders
- Market Data: Order book, positions, open orders
- Integration: API and socket layer coordination
- WebSocket Protocol: RFC 6455 with persistent TCP connections
- Zero-Copy Message Retrieval: Direct in-memory buffer processing
- Condition Variable Wakeup: Immediate thread activation
- Result: Sub-millisecond round-trip latency
- Mutex-Guarded Queues: Race condition prevention
- Dedicated Worker Threads: I/O decoupling from business logic
- Producer-Consumer Pattern: High-throughput message processing
- Asynchronous Handshake: Non-blocking TLS setup
- Session Reuse: Connection and TCP session optimization
- Hardware Acceleration: Intel AES-NI and ARMv8 crypto support
- Result: <10% latency overhead with optimized ciphers
- Vertical Scaling: Efficient CPU core utilization
- Horizontal Scaling: Stateless request model for microservices
- Connection Pooling: Extensible for high-load scenarios
Located in test/test_latency/ directory:
- Latency Measurement: Round-trip timing for all operations
- Throughput Testing: Orders per second capacity
- Protocol Comparison: WebSocket++ vs Boost vs Custom implementations
- Async vs Sync: Performance benchmarking of different approaches
- WebSocket++: Outperforms Boost Beast implementation
- Async Calls: Better performance than synchronous counterparts
- Latency: Sub-millisecond performance under optimal conditions
- C++17 compatible compiler
- CMake 3.10+
- Boost libraries
- OpenSSL development libraries
mkdir build && cd build
cmake ..
make -j$(nproc)cd test/test_latency
make
./test_latency- Purpose: Easy adaptation to multiple data sources
- Implementation: Interface-based architecture with runtime loading
- Benefits: Protocol flexibility (Binance, Kraken, custom APIs)
- Message Batching: Periodic chunk transmission
- LRU Cache: Response caching with eviction policies
- Benefits: Reduced downstream load and bandwidth
- ML Anomaly Detection: Filter abnormal market data
- NLP Intent Recognition: Smart command-based interactions
- Benefits: Intelligent, context-aware backend
- Structured Logs: JSON format for easy parsing
- Prometheus Integration: Latency, error rate, fill rate metrics
- Audit Trails: Complete order and execution history
- Grafana Dashboards: Real-time system performance
- Alertmanager Rules: Automated issue detection
- Key Metrics: Latency spikes, risk breaches, connection drops
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Priyanshu Yadav
Final Year BTech ECE
๐ง priyanshs.ece@gmail.com
- Deribit: Exchange API integration
- Boost Libraries: High-performance C++ components
- WebSocket++: WebSocket protocol implementation
- Open Source Community: Tools and libraries that made this possible
โญ Star this repository if you find it helpful!
For questions about architecture, optimizations, or low-latency C++ design, feel free to reach out!