This repository implements a modular framework for researching and deploying quantitative trading strategies in real-time environments. The design separates research, productionization, and runtime system architecture into clearly defined layers.
Below is the updated architecture of the codebase:
This diagram illustrates the flow from strategy research to event-driven integration and validation.
Add the keys in the gateways/binance/vault/binance_keys file
Run the run_binance.py
Add the telegram keys in engine/vault/telegram_keys
Run the main.py
Execute the run.bat
Exploratory and experimental phase where strategies are initially tested in a vectorized notebook format using historical data.
research/datasets/: Raw historical price/time-series dataresearch/: Strategy prototyping and analysis
Bridges research models into real-time production-ready event-driven strategies.
- Implement a class that inherits from the base
Strategyand wraps vectorized logic. - Use
MarketDataClientandCandleAggregatorto simulate or stream tick-level market data. - Compare vectorized vs real-time strategy signals via the
ValidationTestingSuite ~ model_integration/tests.
System design for executing trades in a live setting using real-time data and event streams.
Exchange
↓
MarketDataClient (e.g. CCXT, RemoteFeed)
↓
CandleAggregator → MidPriceCandle → Strategy
↓
→ StrategyManager → on_signal()
↓
→ TradeExecutor → RiskManager.validate_order()
↓
→ OrderExecutor → OrderStore
↓
→ AccountStateStore → MarginCalc → NotificationCenter
| Component | Description |
|---|---|
| MarketDataClient | Streams raw order book data from an exchange. |
| CandleAggregator | Constructs event-driven candles from raw ticks. |
| Strategy | Real-time strategy class (e.g., SMACrossoverInflectionStrategy). |
| StrategyManager | Manages strategy lifecycle and dispatches signals. |
| TradeExecutor | Listens to strategy signals and sends validated orders to executor. |
| RiskManager | Validates signals and orders against capital and risk rules. |
| OrderExecutor | Places or cancels orders through broker or mock client. |
| OrderStore | Tracks live and historical orders. |
| AccountStateStore | Updates current positions, PnL, and available balance. |
| MarginCalculator | Computes margin usage for active trades. |
| NotificationCenter | Pushes alerts to the notification platform. |
Strategies are validated against TradingView Pine Script reference trades to confirm execution timing and signal logic are identical.
The backtest engine runs execution_timing = next_bar_open:
orders queued on signal bar → filled at next bar's open (matches Pine's
process_orders_on_close = false, calc_on_every_tick = false).
| Strategy | Parity | Status |
|---|---|---|
| CCI | 100% | ✅ |
| ROC | 100% | ✅ |
| ULTOSC | 100% | ✅ |
| TRIX | 99.9% | ✅ |
| BBAND | 99.8% | ✅ |
| CMO | 99.7% | ✅ |
| RSI | 99.5% | ✅ |
| PPO | 97.5% | ✅ |
| MOM | 6.6% | ❌ systematic 1-bar max-hold offset (Pine internals) |
See engine/backtest/PYTHON_PINE_COMPARISON.md
for detailed root cause analysis and planned fixes.
cd engine
python -m backtest.validate_runner --config backtest/configs/validate_pine_parity.json- Research a new idea in notebooks using historical datasets.
- Productionize the idea by wrapping logic in a real-time
Strategyclass. - Use the Validation Suite to ensure fidelity between vectorized and live logic.
- Plug the new strategy into the Runtime Engine for simulation or live deployment.
