diff --git a/CLAUDE.md b/CLAUDE.md index d67a6b7..c8025cb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,6 +1,6 @@ # ForexBot2 -XAU/USD signal intelligence platform. Analyzes gold across multiple timeframes using 9 technical indicators with regime-adaptive weights, news sentiment, and economic calendar data. Delivers signals via Telegram with full trade setups (entry, SL, TP). +Multi-pair signal intelligence platform (XAU/USD + EUR/USD). Analyzes each pair across multiple timeframes using 9 technical indicators with regime-adaptive weights, news sentiment, and economic calendar data. Delivers signals via Telegram with full trade setups (entry, SL, TP). ## Architecture @@ -13,26 +13,31 @@ Twelve Data REST API + WebSocket | signal_aggregator.py (MTF agreement + news + final signal + trade setup) | + pair_signals/ (per-pair config factories: xauusd.py, eurusd.py) + | +-----+--------+ | | telegram_bot.py main.py -(Telegram alerts, (CLI single-pair +(Telegram alerts, (CLI per-pair auto-scanner, analysis) WS monitor) ``` +**Per-pair modularity:** each pair registers a `make_config(primary_tf, confirmation_tfs) -> PlatformConfig` factory in `pair_signals/`. `PlatformConfig.scan_pairs` is the single switch for which pairs the bot scans (single- or multi-pair). Market constants (pip value, price precision, backtest default spread) live in `PAIR_INFO`; strategy knobs live in per-pair dataclasses (`XauStrategyConfig`, `EurUsdStrategyConfig`). All XAU-specific gates in the aggregator are display-gated — nothing gold-calibrated touches the EUR path, and vice versa (enforced by pair-isolation tests + a pinned-window XAU regression CSV). + ## Core Files | File | Purpose | |------|---------| -| `config.py` | All configuration dataclasses, XAU/USD pair definition, strategy config | +| `config.py` | All configuration dataclasses, `PAIR_INFO` registry, per-pair strategy configs | | `data_provider.py` | Twelve Data SDK wrapper with in-memory cache and rate limiting | | `engine.py` | `TechnicalEngine` — computes EMA, RSI, BB, ADX, ATR, MACD, ROC, Keltner, divergences, candlestick patterns, swing S/R | | `signal_aggregator.py` | `SignalAggregator` — MTF analysis, news integration, diminishing penalty cap, trade setup generation | | `news_engine.py` | Economic calendar (Forex Factory JSON) + RSS sentiment (keyword-based) | | `telegram_bot.py` | Async Telegram bot with auto-scanner (M5/M15/H1/H4), WebSocket price monitor | -| `main.py` | CLI entry point for XAU/USD analysis | -| `test_all.py` | Comprehensive QA suite (~137 tests, no live API needed) | +| `pair_signals/` | Per-pair producer registry (`PAIR_PRODUCERS`) + config factories | +| `main.py` | CLI entry point (`--pair XAUUSD\|EURUSD`) | +| `test_all.py` | Comprehensive QA suite (~176 tests, no live API needed) | ## Key Concepts @@ -60,9 +65,9 @@ ROC is directionally redundant with MACD/Keltner/EMA (0.8–0.94 correlation) bu ## How to Run ```bash -# CLI (XAU/USD analysis) -python main.py # H1 default -python main.py --timeframe M15 --detail --json +# CLI +python main.py # XAU/USD H1 default +python main.py --pair EURUSD --timeframe M5 --detail # Telegram bot (auto-scanner) TELEGRAM_TOKEN= TELEGRAM_CHAT_ID= python telegram_bot.py @@ -70,8 +75,9 @@ TELEGRAM_TOKEN= TELEGRAM_CHAT_ID= python telegram_bot.py # Tests python test_all.py -# Backtest +# Backtest (spread defaults per pair: XAU $0.30, EUR 0.0001 — see PAIR_INFO) python backtest/gpu_backtest.py --pair XAUUSD --days 365 +python backtest/gpu_backtest.py --pair EURUSD --primary-tf 5min --confirm-tfs 15min,1h --days 365 ``` ## Environment Variables @@ -92,7 +98,7 @@ python backtest/gpu_backtest.py --pair XAUUSD --days 365 - **Rate limit:** 55 credits/min (Grow plan), enforced by sliding-window throttle - **Cache:** In-memory dict, TTL = candle duration of the timeframe - **Validation:** Drops NaN rows, forward-fills gaps (limit 3), fixes OHLC inconsistencies, removes outliers (>10σ), strips future timestamps, deduplicates -- **WebSocket:** XAU/USD only +- **WebSocket:** subscribes every pair in `scan_pairs` ## Telegram Bot @@ -105,7 +111,7 @@ python backtest/gpu_backtest.py --pair XAUUSD --days 365 The `backtest/` directory contains `gpu_backtest.py` — a GPU-accelerated backtester (CuPy with NumPy fallback) that replays historical OHLCV through the real SignalAggregator. Pre-computes all indicator series including ROC, Keltner, ADX slope for 100x+ speedup. Uses parquet caching for data persistence. -Fill realism: charges a round-trip spread per trade (`--spread`, default $0.30 for XAU), fills gap-through SL/TP at the bar open, and resolves trades against the RAW price path (the parquet cache stores raw bars; validation/cleaning runs on load — signals see cleaned data, trade resolution sees real spikes). Entry is at the next bar's open after the signal bar. Weekend/session filters evaluate bar-close (decision) time to match the live bot's wall clock. +Fill realism: charges a round-trip spread per trade (`--spread`; defaults to the pair's `default_spread` in PAIR_INFO), fills gap-through SL/TP at the bar open, and resolves trades against the RAW price path (the parquet cache stores raw bars; validation/cleaning runs on load — signals see cleaned data, trade resolution sees real spikes). Entry is at the next bar's open after the signal bar. Weekend/session filters evaluate bar-close (decision) time to match the live bot's wall clock. GPU note: CuPy needs the NVIDIA runtime pip wheels (`nvidia-cuda-runtime-cu12`, `nvidia-cuda-nvrtc-cu12`, `nvidia-curand-cu12`, `nvidia-nvjitlink-cu12`) or it silently falls back to NumPy — check the "Backend:" line in the run log. The bar-replay loop itself is single-threaded Python either way (~340 bars/s); GPU only accelerates indicator precompute and SL/TP scanning.