Commit Graph

35 Commits

Author SHA1 Message Date
Harwinder f561311f14 updated guide 2026-05-05 20:25:50 -04:00
Harwinder f5d6d35063 XAU/XAG: 3-TF analysis (M15+H1+H4 resampled) via per-symbol override
- New _PER_SYMBOL_TFS map in signal_aggregator routes gold/silver to
  M15+H1+H4 confirmation; forex pairs untouched.
- H4 for XAU/XAG is resampled from yfinance H1 bars (yfinance has no
  native 4h candle). New _resample_h1_to_h4 helper.
- Batch prefetch unions per-symbol TFs so future per-pair overrides
  work without extra plumbing. XAU/XAG still excluded from Twelve Data
  batch — H4 resample triggers a single yfinance H1 fetch.
- Telegram SCAN_TIMEFRAMES restored to [M15, H1] so /scan emits both
  M15-primary and H1-primary cards. Shared cache means no extra credits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 20:12:22 -04:00
Harwinder 2700b0845d Disable SSL verify for yfinance via curl_cffi session
Live server sits behind a TLS-inspecting proxy that re-signs HTTPS with
an untrusted root CA, breaking yfinance HTTPS calls. yfinance >= 0.2.40
requires a curl_cffi session (rejects requests.Session), so we build
one with verify=False and impersonate=chrome.

Trade-off: yfinance traffic is no longer authenticated against MITM.
Acceptable because the data is public market quotes and an attacker
can at worst inject bad prices. Session is yfinance-only and not reused
for any authenticated traffic.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 20:01:35 -04:00
Harwinder 1100b9eaf2 Tighten signal pipeline: yfinance-only XAU/XAG, leaner Telegram /scan
- XAU/XAG always route to Yahoo Finance and skip Twelve Data entirely
  (excluded from batch prefetch, served per-symbol via yfinance).
- Daily chart cleanly skipped for gold/silver — engine drops it from MTF.
- Telegram /scan limited to EURUSD, USDJPY, GBPUSD, XAUUSD.
- SCAN_TIMEFRAMES reduced to single H1 primary; engine still pulls
  M15+H1+D1 internally via confirmation TFs (halves API credits per scan).
- Default confirmation TFs swapped H4 -> D1 in config and main.py.
- mtf_agreement_threshold kept at 2-of-3.
- CLAUDE.md cleaned up — old XAUUSD/synthetic-data bug reports removed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 19:52:41 -04:00
Harwinder 4c1d839a1a Per-timeframe cache TTLs — D1 cached 4h, H1 30m, M15 5m
A single 5-minute refresh_interval applied to every timeframe wasted
API credits: a daily candle was being refetched every 5 minutes even
though it only changes once per day. Now each TF caches for roughly
its bar interval, so repeat scans within an hour skip D1 entirely
(saves ~60s of throttle wait) and within 30 min also skip H1.

config.py: new cache_ttl_per_tf dict on PlatformConfig with sensible
defaults for every timeframe; refresh_interval kept as fallback.

data_provider.py: _cache_ttl() helper used by both fetch_ohlcv and
prefetch_batch instead of the global refresh_interval.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 14:55:05 -04:00
Harwinder 8a1e57f682 Update USAGE.md to match current behaviour
- main.py: same options, but examples and output reflect today's format
- Telegram: drop nonexistent /tf and /signal-with-TF docs; document
  current commands (/signal, /scan, /help, /start) and the M15+H1
  scan policy with D1 as silent confirmation
- Telegram card format: dotless layout with grade symbols and legend
- Symbols: split forex (Twelve Data live) from metals (yfinance
  fallback); call out GC=F vs spot basis; remove stale synthetic-data
  language since the fallback no longer exists
- API limits: 3 batch calls × 7 pairs = 21 credits per scan, ~2 min
- New Configuration section pointing to the right files for tuning

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 14:45:09 -04:00
Harwinder 6a75ed1ffb Add yfinance fallback for gold/silver + coarse Telegram progress
- yfinance>=0.2.40 added as a hard dependency
- _fetch_yfinance_fallback(): pulls OHLCV from Yahoo for symbols not on
  the Twelve Data free tier (XAUUSD → GC=F, XAGUSD → SI=F)
- Hooked into both batch and single-symbol fetch paths; logs as [yf]
  to distinguish from Twelve Data [live]
- Fail-loud: if both providers return nothing, the pair is skipped with
  the existing "data unavailable" message
- _analyze_all_tfs accepts an async progress callback; both /signal and
  /scan now show coarse milestones via message edits:
    "📡 Fetching market data..."  →  "🧠 Analyzing pairs..."  →  result
- prefetch_batch is now run in a thread so it doesn't block the event loop

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 14:40:19 -04:00
Harwinder 492b39313a Scan only M15 and H1; keep D1 as confirmation, drop W1 entirely
Trades are intraday (M15/H1) only. D1 stays as a confirmation TF
for both so higher-timeframe trend context still gates A/A+ grades.
W1 is no longer used anywhere — removes one batch call.

Scan now: 3 batch calls (M15, H1, D1) × 7 pairs = 21 credits, ~2 min.
Was:      4 batch calls (M15, H1, D1, W1) = 28 credits, ~3 min.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 14:13:44 -04:00
Harwinder 2f6eed7309 Add LOGIC.md — engine decision flow, API call count, indicator weights
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 14:01:48 -04:00
Harwinder 683d070a41 Scan M15/H1/D1/W1 only; grade symbols + legend on all messages
- SCAN_TIMEFRAMES: drop H4, add W1 (4 unique TFs → fewer API calls)
- Confirmations updated to use only the 4 scan TFs (no H4 dependency)
- Add _grade_symbol(): 🔥A+ ✅A 👍B ⚠️C 📉D ❌F
- _GRADE_LEGEND shown on every /signal and /scan message
- 🧠 icon on Signal Analysis and Scan Complete headers
- /help grade guide updated with full symbol legend

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 21:29:48 -04:00
Harwinder 775655e0ac Clean up signal display — remove dots, direction emoji, confidence %
- Drop _grade_dot() and all colored circle emojis
- Remove raw confidence % from signal and scan output
- Signal card: "M15 · SELL · Grade C"
- Scan row: "EUR/USD · SELL · C · M15"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 21:16:40 -04:00
Harwinder 3da68f1433 Remove stale synthetic-data warning on unsupported pairs
The warning predated the synthetic fallback removal. Now that the engine
raises DataUnavailableError for unsupported symbols, the flag was always
wrong for XAU/USD and similar pairs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 20:56:47 -04:00
Harwinder df77e0fb5e Fix concurrent API credit exhaustion — shared prefetch + dedup warnings
- telegram_bot: one ForexDataProvider shared across all SCAN_TIMEFRAMES;
  combined prefetch of all unique TFs up front so the 4 concurrent scans
  hit the warm cache instead of firing simultaneous API calls
- data_provider: skip prefetch_batch for timeframes already in cache
- data_provider: deduplicate "no data" warning per symbol (fires once, not once per TF)
- data_provider: [live] info log on successful fetch; outlier-removal downgraded to debug

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 20:48:25 -04:00
Harwinder 8ca59c6a21 Debug fix 2026-05-04 20:40:40 -04:00
Harwinder e6ef6e8c9d Remove synthetic data fallback; fix concurrent API credit exhaustion
data_provider:
- Remove _generate_synthetic_data entirely — no more fake prices
- Raise DataUnavailableError instead of falling back to synthetic data
  (no API key, daily limit hit, API returns no values, fetch failure)
- Move rate limiter to module-level globals (_rate_lock, _rate_request_times,
  _rate_daily_credits) so all ForexDataProvider instances running in parallel
  threads share the same 8-credit/min and 800-credit/day accounting
- _throttle now raises DataUnavailableError on daily limit (was silent return False)
- Remove _no_api_data tracking, numpy/hashlib imports

telegram_bot:
- Detect F-grade reports caused by data unavailability and show clean
  "Data unavailable" line per TF instead of a garbled zero-price card

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 17:48:20 -04:00
Harwinder c4e1ba5589 Add CLAUDE.md with two known bugs
Bug 1: concurrent TF scans exhaust free-tier API credits (8/min limit)
Bug 2: XAUUSD synthetic fallback uses wrong base price (~1.0 vs ~3300)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 17:42:56 -04:00
Harwinder f053411343 Combine all TF outputs into single message, add EST price timestamp
/signal: one combined message with all 4 TF sections stacked (────── dividers),
  entry/TP/SL always preserved, indicators per TF, MTF folded to one footer line,
  disclaimer once at bottom, news/warnings only when relevant

/scan: single compact message — one header+trade line per pair, full entry/TP/SL
  kept, no indicator list (use /signal to drill in), danger events shown inline

Both commands show price pull time as EST (e.g. 09:42 AM EST · Mon 04 May 2026)
Scanning progress message no longer shows a single TF in parentheses

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 17:39:21 -04:00
Harwinder 0ad741670f Remove TF param — analyze all timeframes automatically
- /signal EURUSD sends one card per timeframe (M15, H1, H4, D1) concurrently
- /scan analyzes all pairs across all TFs, shows best-grade card per pair (B+ only)
- All TFs run in parallel via ThreadPoolExecutor (one worker per TF)
- Remove /tf command and per-chat state — no longer needed
- Executor pool sized to len(SCAN_TIMEFRAMES) for true concurrency

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 17:27:15 -04:00
Harwinder 7bde28c524 Update USAGE.md to reflect rebuilt Telegram bot and current features
- Replace /pair + old /scan docs with new /signal and /scan commands
- Add trade alert card format with dot-grade legend (🟢/🟡/🔴)
- Document /scan grade-B+ filter behaviour and summary header
- Expand signal grades table with score/confidence/MTF thresholds
- Add note that trade setup only generated for Grade B and above
- Add --watch API credit warning; fix Windows token setup syntax

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 17:18:37 -04:00
Harwinder 4aba243472 Rebuild Telegram bot with trade alert template and grade-filtered scan
- Replace /scan+/pair commands with /signal (single pair) and /scan (all pairs, B+ only)
- Implement exact visual template: grade dot (🟢/🟡/🔴), TRADE ALERT header, Entry/TP/SL/R:R block, full indicator list with value + condition
- Grade dot enforced: A/A+=🟢, B=🟡, C/D/F=🔴
- /scan filters to minimum Grade B confidence before sending alerts
- HTML parse mode with html.escape() on all dynamic content
- Per-chat default timeframe state preserved

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 17:16:00 -04:00
Harwinder 94b93cf1e7 Fix XAU/USD display name, pip value, and invalid symbol validation
- config.py: add XAU/USD and XAG/USD to SYMBOL_DISPLAY; add PIP_VALUES
  map for commodities (gold pip = $0.01, not $0.0001)
- data_provider.py: use PIP_VALUES in get_pair_info so gold trade setup
  shows correct pip counts instead of 269,000 pips for a $27 SL
- main.py: validate symbols in symbol_from_name — rejects non-alpha
  inputs like '15M' with a helpful hint to use --timeframe instead

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 15:59:34 -04:00
Harwinder a15fc6db91 Update USAGE.md with Telegram bot, timeframes, and API limits
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 15:54:09 -04:00
Harwinder da6fc5d283 Simplify Telegram bot — mirror main.py output exactly
- Remove /all, /watch, /unwatch, /credits, /status commands
- Keep only /scan, /pair, /tf, /help
- Output exact same format as main.py terminal output (box-drawing
  characters, score bars, table, detail report) inside <pre> blocks
- /help explains all timeframes with recommended use cases
- /scan TF and /pair EURUSD TF accept inline timeframe override
- Auto-split messages at newlines to stay under Telegram 4096-char limit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 15:50:49 -04:00
Harwinder 0e95a34d82 Align with Twelve Data API docs and add Telegram command menu
data_provider:
- Switch to Authorization header (recommended over apikey query param)
- Enforce 800 credits/day daily limit with warning at 80%
- Fall back to synthetic data when daily limit is reached
- Fix null OHLC field handling (API can return null for any field)

telegram_bot:
- Register commands with set_my_commands so Telegram shows / menu
- Add /credits command to show daily API credit usage and limits

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 15:33:32 -04:00
Harwinder 71c3fb6d82 Add Telegram bot and fix excessive API calls
- Add telegram_bot.py: full bot interface with /scan, /signals, /pair,
  /all, /tf, /watch, /unwatch, /status, /help commands; per-chat state;
  background thread pool for analysis; auto message splitting
- Fix data_provider: warn once per symbol with no API data and cache
  synthetic fallback to prevent redundant individual API calls
- Fix signal_aggregator: derive spread estimate from already-fetched
  primary DataFrame instead of making a separate M5 API call per pair
- Add python-telegram-bot[job-queue]>=20.0 to requirements.txt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 15:15:04 -04:00
Harwinder bc1844b233 Add requirements.txt and usage guide
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 10:51:03 -04:00
Harwinder 242df24ca7 Fixed Bugs 2026-05-04 10:51:03 -04:00
harry e4138ee60a Fixed code 2026-05-04 14:29:32 +00:00
harry 1637b93f1c Add script.txt 2026-05-04 04:11:35 +00:00
harry 43319d9a98 Add main.py 2026-05-04 04:10:17 +00:00
harry ce4a12877d Add signal_aggregator.py 2026-05-04 04:10:01 +00:00
harry e08b593a86 Add news_engine.py 2026-05-04 04:09:32 +00:00
harry dacf337e87 Add engine.py 2026-05-04 04:08:58 +00:00
harry 008c21f9c3 Add data_provider.py 2026-05-04 04:08:35 +00:00
harry e39054af02 Add config.py 2026-05-04 04:08:10 +00:00