This project demonstrates a basic implementation of an automated trading engine using the FIX (Financial Information eXchange) protocol. It's designed as an educational resource to show how one can interact with FIX protocol streams in a hands-on way, particularly useful for those interested in building their own trading systems.
When building my first automated S&P500 terms trading engine, it was really hard to find live examples on how to work with the FIX streaming protocol using in automated trading. This code, or rather parts of it has been used in live certified production in later projects and business ventures. Figured it's time to pay things forward, and share my bits and bobs. The code is not pretty, efficent or "propper" in any way, nor is it supposed to. When I sketch out key functions, I prefer them self contained. But, it's functional code, a mvn clean build will work, "all" you need is a testing/ demo account with a clearing house to try it out with. ;)
Important Note: This code is meant for educational purposes and demonstration only. It is not production-ready and should not be used in live trading environments without significant improvements.
- Basic FIX protocol message handling
- Integration with Excel for trade management
- Real-time order processing
- Simple automated trading logic
- FIX message construction and parsing
- Database integration for trade tracking
Handles outgoing FIX messages and manages the connection to the FIX server. Shows basic message construction and session management.
Processes incoming FIX messages, demonstrating how to parse and handle various FIX message types.
Monitors Excel files for new orders and translates them into FIX messages. Shows how to integrate external data sources with FIX trading.
Maintains session state and global configurations. Demonstrates basic state management in a FIX trading system.
The project uses MySQL to store:
- Order status and history
- Trade execution details
- System logs
- Collateral information
- Trade orders are read from Excel files
- Format: Symbol, Quantity, Price, Side (Buy/Sell)
- System monitors for file changes
- Orders are converted to FIX messages
- Java Development Kit (JDK)
- MySQL Database or any other relational database
- Microsoft Excel
- FIX Protocol counterparty (broker/exchange connection)
- Database setup (tables for orders, executions, logs)
- FIX session parameters (in configuration file)
- Excel template setup
- Logging configuration
This project helps understand:
- FIX Protocol basics
- Message flow in trading systems
- Order lifecycle management
- Integration of multiple components
- Real-time data processing
- Not optimized for high-frequency trading
- Basic error handling
- Limited risk management
- Simplified authentication
- No market data handling
- Basic order types only
- Learning FIX protocol implementation
- Understanding trading system architecture
- Testing FIX connectivity
- Prototyping trading strategies
- Educational demonstrations
- Communication Layer (FIX handling)
- Business Logic (order processing)
- Data Access (database operations)
- Utility Classes (helpers and tools)
- Database settings
- FIX session parameters
- Logging preferences
- Excel file locations
- Code prioritizes readability over efficiency
- Comments explain FIX-specific concepts
- Simple implementations for learning purposes
- Demonstrates basic patterns in trading systems
Feel free to:
- Submit issues and suggestions
- Propose improvements
- Share learning experiences
- Suggest better practices
This code is:
- NOT production-ready
- NOT optimized for performance
- NOT secure for real trading
- FOR EDUCATIONAL PURPOSES ONLY
- A DEMONSTRATION of concepts
- FIX Protocol Specification
- Common message types
- Session management
- Message construction
- Order types
- Trade lifecycle
- Risk management
- Market connectivity
Potential areas for enhancement:
- Better error handling
- More order types
- Market data processing
- Risk checks
- Performance optimization
Feel free to reach out for:
- Questions about FIX implementation
- Trading system architecture
- Learning resources
- Collaboration opportunities
Remember: This is a learning tool to understand FIX protocol and trading system basics. Use it to explore and understand, but build proper safeguards and optimizations for any production system.
- Create a MySQL database and run these SQL commands:
MariaDB Commands:
CREATE DATABASE trader;
USE trader;
CREATE TABLE collateral (
id INT AUTO_INCREMENT PRIMARY KEY,
CollRptID VARCHAR(255),
TotalNetValue DECIMAL(15,2),
MarginExcess DECIMAL(15,2),
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE trader_order_status_log (
id INT AUTO_INCREMENT PRIMARY KEY,
trade_order_id VARCHAR(255),
status VARCHAR(255),
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE trader_sequence_log (
id INT AUTO_INCREMENT PRIMARY KEY,
mysequence INT,
message_was TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE live_trades (
ID VARCHAR(255) PRIMARY KEY,
SYMBOL VARCHAR(50),
QUANTITY INT,
SIDE VARCHAR(10),
STATUS VARCHAR(50),
VARDE DECIMAL(15,2),
COMMISSION DECIMAL(15,2),
TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);- Clone the repository:
git clone [repository-url]
cd trader
- Build the project:
mvn clean install
- The build will create two JAR files in the target directory:
- trader-1.0-SNAPSHOT.jar (without dependencies)
- trader-1.0-SNAPSHOT-jar-with-dependencies.jar (complete runnable jar)
- Create a config.ini file in the project root:
[DATABASE] url=jdbc:mysql://localhost:3306/trader username=your_username password=your_password
[FIX] sendercompid=YOUR_SENDER_ID targetcompid=YOUR_TARGET_ID password=YOUR_FIX_PASSWORD host=fix.example.com port=9878
[EXCEL] tradefile=C:/trading/orders.xlsx interval=5000
- Prepare Excel Trade File:
- Create an Excel file as specified in your config
- Required columns: Symbol, Quantity, Price, Side
Method 1: Using JAR directly
java -jar target/trader-1.0-SNAPSHOT-jar-with-dependencies.jar
Method 2: Using Maven
mvn exec:java -Dexec.mainClass="trader.RunMe"
-
Check Logs:
- Application should create log files in the specified directory
- Database tables should start populating with sequence logs
-
Monitor Database:
- Use MySQL client to monitor tables:
SELECT * FROM trader_sequence_log ORDER BY timestamp DESC LIMIT 10;
SELECT * FROM live_trades WHERE STATUS = 'New';
- Excel Integration:
- Add a test order in the Excel file
- System should detect and process within configured interval
Common Issues:
-
Database Connection:
- Verify MySQL is running
- Check credentials in config.ini
- Ensure database and tables exist
-
FIX Connection:
- Verify FIX server is accessible
- Check firewall settings
- Validate FIX credentials
-
Excel File:
- Verify file path in config
- Ensure file isn't open/locked
- Check file permissions
- Java 11 or higher
- MySQL 5.7 or higher
- Maven 3.6 or higher
- Microsoft Excel
- Minimum 4GB RAM
- Storage space for logs and database
Optional but recommended:
- JAVA_HOME: Pointing to JDK installation
- MAVEN_HOME: Pointing to Maven installation
- TRADER_CONFIG: Custom path to config.ini
For IDE users:
IntelliJ IDEA:
- File -> Open
- Select the pom.xml
- Enable Auto-Import for Maven
- Run/Debug configuration for RunMe class
Eclipse:
- File -> Import
- Maven -> Existing Maven Projects
- Select the project root
- Create Run Configuration for RunMe class
Default logging configuration creates:
- Application logs
- FIX message logs
- Error logs
- Database operation logs
/Stefan Månsby