ThunderFix is a high-performance, low-latency C++ FIX protocol library designed for high-frequency trading, real-time market data parsing, and order management in financial systems. This library provides a modular design with support for risk management, load balancing, logging, message replay, dynamic resource management, and other advanced features, making it ideal for demanding high-load environments.
- Multi-Version Support: Supports different versions of the FIX protocol (e.g., 4.0, 4.2, 4.4) to accommodate diverse requirements.
- Low-Latency Design: Utilizes
asio
for asynchronous I/O, optimized memory management for efficient message processing. - Modular Structure: Core and extension modules are separated for ease of maintenance and expandability.
- Advanced Risk Management: Includes multi-level risk controls, such as order limits, daily position limits, and loss limits.
- Dynamic Load Management: Multi-session support and load balancing module for efficient resource allocation.
- Logging and Auditing: Supports dynamic logging levels with latency monitoring and audit logs to meet compliance requirements.
- Data Compression: Compression module for low-bandwidth environments.
- Message Replay and Recovery: Ensures message integrity with message replay in cases of disconnection or message loss.
- Configuration Management: Configuration file to define risk control, logging, networking parameters, and more.
In the project root directory, execute the following commands to build the project:
mkdir build
cd build
cmake ..
make
After building the project, you can run the examples found in the examples
folder:
# Basic usage example
./BasicUsageExample
# Advanced usage example with risk control, load balancing, heartbeat, etc.
./AdvancedUsageExample
The config.json
file defines settings for risk management, logging, network connections, rate limiting, and more:
{
"risk": {
"maxOrderAmount": 1000000,
"maxPosition": 5000000,
"maxDailyLoss": 50000
},
"logging": {
"level": 2 // 0=INFO, 1=WARNING, 2=ERROR, 3=DEBUG
},
"connection": {
"host": "example.fixserver.com",
"port": "5000",
"heartbeatInterval": 30
},
"rateLimiter": {
"maxOrdersPerMinute": 60
}
}
- risk: Risk parameters, including order size limits, position limits, and daily loss limit.
- logging: Logging settings, defining the output log level.
- connection: Network parameters, including server address, port, and heartbeat interval.
- rateLimiter: Rate limiting, defining the maximum number of orders allowed per minute.
- FIXParser: Parses and builds FIX messages, extracting fields and verifying format.
- FIXSession: Manages session state, sequencing, and heartbeat, handling message reception and transmission.
- FIXConnection: Responsible for asynchronous communication with the server.
- Logger: Dynamic logging with support for performance monitoring.
- ConfigurationLoader: Loads the
config.json
configuration file and applies settings to modules.
- RiskControl: Ensures trades comply with preset risk limits.
- LoadBalancer: Load balancing across sessions, dynamically choosing the best connection based on latency.
- OrderRateLimiter: Limits order submission rate to avoid exceeding frequency limits.
- MessageReplay: Message replay for session disconnection and message loss.
- AuditLog: Records all significant events and trade information for auditing purposes.
Below is a basic usage example showing how to use the library to parse messages, establish connections, and perform simple risk control.
#include "ThunderFix.h"
#include <iostream>
int main() {
// Initialize configuration and session
ConfigurationLoader configLoader;
configLoader.loadConfig("config/config.json");
FIXSession session(FIXVersion::FIX_4_2, asio::io_context());
session.start();
// Parse a message
FIXParser parser(FIXVersion::FIX_4_2);
parser.parseMessage("8=FIX.4.2|35=D|55=AAPL|54=1|38=100|");
// Extract fields
std::string symbol = parser.getField("55").data();
int side = std::stoi(parser.getField("54").data());
Logger::log(LogLevel::INFO, "Parsed Symbol: " + symbol);
Logger::log(LogLevel::INFO, "Parsed Side: " + std::to_string(side));
return 0;
}
#include "ThunderFix.h"
#include <iostream>
int main() {
// Load configuration
ConfigurationLoader configLoader;
configLoader.loadConfig("config/config.json");
asio::io_context ioContext;
FIXSession session(FIXVersion::FIX_4_2, ioContext);
session.start();
// Set up risk control
RiskControl riskControl;
if (!riskControl.checkOrderLimits(150000)) {
Logger::log(LogLevel::WARNING, "Order amount exceeds limit.");
}
// Rate limiter example
OrderRateLimiter rateLimiter(60);
if (rateLimiter.canSendOrder()) {
Logger::log(LogLevel::INFO, "Order allowed.");
} else {
Logger::log(LogLevel::WARNING, "Order rate limit exceeded.");
}
ioContext.run();
return 0;
}
The tests
directory contains unit tests for each core and extension module. The tests use the Google Test (gtest) framework to ensure reliability.
To run the tests:
# Run in the build directory
make test
- FIXParserTest.cpp: Tests FIX message parsing and field extraction.
- FIXSessionTest.cpp: Tests session management, sequencing, and heartbeat.
To deploy ThunderFix in a production environment, customize the configuration file (config.json
) to match specific operational requirements. The configuration file allows for easy tuning of risk limits, logging levels, connection settings, and more.
Potential future extensions to this library include:
- Smart Order Routing: Implement order routing strategies based on market conditions, liquidity, and execution efficiency.
- Integration with Trading Algorithms: Support trading strategies such as VWAP and TWAP, integrated directly within the FIX sessions.
- Distributed Architecture: Enable distributed session management across nodes for scalability in ultra-high-frequency environments.
- Enhanced Risk Management: Dynamic risk controls based on market volatility and significant events.
This project is licensed under the Apache-2.0 License. See the LICENSE file for details.
Contributions are welcome! Please submit issues, fork the repository, and create pull requests. For significant changes, please discuss with the repository maintainers beforehand to ensure alignment with the project goals.