ConTrade is a modular, config-driven trading platform designed for rapid prototyping and deployment of machine learning based trading strategies. It allows users to define everything from a single config file and easily run:
- ML training pipeline
- Historical validation backtests
- Live trading via Alpaca
ConTrade is language-decoupled, real-time capable, and architected for both experimentation and deployment without ever touching core logic, only config files.
For more detailed information about ConTrade, visit the docs
- One config file defines everything: features, signals, ML settings, Live Settings, and more
- Used for all services: Training, Backtesting, and Live Execution
- This eliminates config drift and ensures alignment for all services
- Supports
- 12 Scikit-learn models
- XGBoost
- LightGBM
- Train Models with
- Multiple assets
- Intervals from minutes to days
- TA-Lib derived features supporting most technicals found here
- Custom labelling logic (crossover, thresholds, weights, persistence windows)
- Hyperparameter tuning
- Easily extensible to support more features, labels, and ML frameworks
- CLI powered historical testing on asset strategies
- Simulate commission, slippage, latency
- Quickly obtain profit/loss metrics
- Serve ML models via FastAPI
- Real time trading with Alpaca (paper or live accounts)
- High performance via
- TA-Lib integration w/ custom C wrapper via
cgo - Async ML prediction microservice via FastAPI + WebSockets
- TA-Lib integration w/ custom C wrapper via
- ~190 concurrent asset tracking @ 60s intervals (on Alpaca free tier)
- 500ms floor for cycle times, supporting mid frequency trading
- Exposed API for trade monitoring and internal logging
- Easily call commands and interact with ConTrade's features via the CLI
- Training
- Backtesting
- Live Deployment
- Tests
- Live TUI dashboard
- View live:
- Logging Information
- Technical Data for all tickers
- View live:
- Unit tested across Python and Go
- Github Actions CI for automated checks
Project size is ~11000 total lines of code across ~50 files.
| Feature | Language | Libraries/Frameworks | External APIs |
|---|---|---|---|
| Config Files | JSON | - | - |
| ML Training Pipeline | Python | Pandas, NumPy, Scikit-learn, XGBoost, LightGBM, TA-Lib | YFinance |
| Backtesting Engine | Python | - | YFinance |
| Runtime Engine | Go, Python | FastAPI, Gorilla WebSocket, TA-Lib, cgo |
Alpaca Market |
| Risk Engine (WIP) | Go | - | Alpaca Account |
| CLI | Python | - | - |
| TUI | Python | Textual | Internal Runtime Engine API |
| Testing & CI | Go, Python, YAML | Pytest, go test, Github Actions |
- |
- Python handles ML and backtesting
- Go handles real-time data and broker execution
- Python and Go communicate only through WebSockets (no shared code)
- The JSON config acts as the single source of truth for all services
- No repeated logic and no mismatch between what's trained and what's deployed
To support both low (minutes) and mid (seconds) frequency trading strategies Go provided a fair trade between speed and complexity
Here are alternatives and why they were not chosen:
Python: GIL overhead and interpreted, not ideal for concurrencyJava: Harder to iterate with compared toGo's module system and single compiled binaryC++: too complex (for this project), complicating concurrency, API calls, and other things for ultra low latency which is not the goal of this project
Go is fast enough to support both types of frequency strategies while allowing for faster iteration of code with simple concurrency and low latency
To use this program you will need to follow these steps
- Clone this repository
- Set up the market data and broker API
- Register for an Alpaca Account (Free)
- Once signed in there will be both API keys and an API secret
- At the root is a
.env.examplefile, put the API key and secret in their proper places, and rename the file to.env - If you wish to test only, make sure you are using paper money
- Download
TA-Libdependencies - Create the virtual environment for
Python(Python3)- If on the bash shell run these commands
python3 -m venv venv(Creates the virtual environment folder)pip install -r requirements.txt(Install Python dependencies)source venv/bin/activate(Shorthand to start the virtual environment)
- If on the bash shell run these commands
- Configuration
- Ingestion of delayed data
Alpacafree tier market API uses delayed data by default- Can be overcome with a higher tier
Alpacaaccount
- Forced burn-in Period
- During live execution we need to burn-in data
Alpacadoes not provide after hours market data- To prevent major jumps from market close to market open, burn in is forced (or override for debug purposes)
- 60 second floor for live execution cycle rate
Alpacamarket API +YFinanceAPI induced limitationAlpacadata only updates every minute, so polling market data within the same minute dilutes feature valuesYFinanceonly has historical data down to a minute, so ML models cannot be trained on faster intervals- Therefore unless you can provide a higher tier
Alpacaaccount AND higher frequency trained model, keep thecycle_ratein the JSON config>=60
- CONFIG - Learn the ConTrade custom JSON schema
- ENV - Environment settings details
- CLI - How to use the ConTrade CLI
Disclaimer: This project is provided for educational and research purposes only. It is not financial advice. Use it at your own risk. The author is not responsible for any financial losses or damages resulting from the use of this software, including but not limited to trading with real money.