abyXsmart's picture
Upload 19 files
f74bb64 verified
|
Raw History Blame Contribute Delete
7.84 kB
---
license: mit
title: FVG-Delta Forex Signal Engine v6.0
sdk: docker
emoji: πŸ“ˆ
colorFrom: green
colorTo: yellow
pinned: true
short_description: Forex Futures Signal A.I Bot
---
# FVG-Delta Forex Signal Engine (v6.0)
A production-style **forex** scanner on closed/forming 15m candles across the
global market β€” FX majors & minors, metals (XAU/XAG), energy (oil, natgas) and
the major indices (NAS100, S&P500, Dow, DAX, FTSE, Nikkei, DXY). It runs a
strict, **lock-forward** Smart-Money model (Impulse β†’ FVG β†’ first-liquidity lock
β†’ BoS close β†’ liquidity sweep β†’ FVG interaction β†’ verified entry), delivers
Telegram alerts (screenshot first, message second) enriched with **market-status
and economic-news context**, renders annotated chart screenshots, and serves a
live auto-updating dashboard with an in-memory Trade History.
This is the forex evolution of the FVG-Delta crypto engine: the **strategy and
state machine are identical**, refined and optimised for the speed of the forex
market.
## What this app does
- Scans a **curated, liquidity-screened** forex universe (no illiquid exotics, no
single stocks). Data comes from Yahoo Finance via `yfinance` (real 15m OHLC, no
API key). Every active setup is re-checked each cycle; the whole universe is
scanned each cycle by default.
- Detects high-quality multi-candle **impulse + FVG** structures (not single-candle spikes).
- Enforces a strict, **monotonic** Stage 1 β†’ 2 β†’ 3 β†’ 4 sequence that never silently regresses.
- **Forex-speed execution:** Stage-3 FVG interaction is registered **intrabar**
(on the forming candle) so a fast touch-and-reject still fires an alert;
SL / TP / Break-even are detected **intrabar**, not only on candle close.
- **No TTL on Stage 3 & 4:** once a setup interacts with the FVG it expires only
naturally β€” Stage 3 dies on a *close* through the FVG; Stage 4 only on
SL / TP / Break-even.
- **Forex risk model:** pip distances, lot size (default micro `0.01`), leverage
(`LEVERAGE`, default `500`, margin-only), required margin, and $ risk / reward
(P/L = pips Γ— pip-value Γ— lots β€” not ROI). Spread is factored into the entry and
risk math.
- **Market clock:** a live Open / Closed badge that knows the forex week
(Sun 17:00 β†’ Fri 17:00 New York), weekends and holidays, and renders the
countdown in the **viewer's browser timezone**.
- **Economic news radar:** the free ForexFactory weekly calendar, graded by
impact into a Safe / Caution / No-Trade signal with a short label
(e.g. *News: FOMC*, *News: CPI*, *News: NFP*) and a live countdown. The same
context is attached to every Telegram alert.
- Sends Telegram alerts for **Stage 3 and Stage 4** plus the per-trade lifecycle
(Entry β†’ TP1 β†’ SL / TP2 / Break-even).
## Quickstart
```bash
# 1. credentials (never paste keys in chat β€” use the secure env flow)
cp .env.example .env # set TELEGRAM_BOT_TOKEN + TELEGRAM_CHAT_ID (optional: LEVERAGE, LOT_SIZE)
# 2. local
bash run_one_shot.sh
# 3. docker / Hugging Face Spaces (Docker SDK)
docker build -t fvg-forex . && docker run -p 7860:7860 --env-file .env fvg-forex
```
Endpoints:
- `/` β€” live dashboard
- `/health` β€” service health
- `/api/state` β€” full engine state (config, stages, alerts, history, market, news)
- `/api/market` β€” forex clock (open/closed, sessions, next transition epoch)
- `/api/news` β€” news radar (market safety level + next high-impact event)
- `/api/chart.png?symbol=EUR/USD` β€” annotated live chart
- `/api/trade_chart.png?symbol=XAU/USD&opened_ts=...` β€” closed-trade snapshot
Without Telegram creds the UI still runs; alerts are skipped, logged, and still
shown in the dashboard Alerts feed.
## The universe
Curated in `instruments.py` β€” 100+ instruments (generated):
| Category | Examples |
|---|---|
| FX majors | EUR/USD, GBP/USD, USD/JPY, USD/CHF, USD/CAD, AUD/USD, NZD/USD |
| FX minors | EUR/JPY, GBP/JPY, EUR/GBP, AUD/JPY, EUR/AUD, GBP/CAD, … |
| Metals | XAU/USD (gold), XAG/USD (silver) |
| Energy | WTI, Brent, NatGas |
| Indices | NAS100, S&P500, US30, DAX, FTSE100, Nikkei225, DXY |
Filter by category with `FVG_UNIVERSE_INCLUDE` / `FVG_UNIVERSE_EXCLUDE`.
## Files
- `app.py` β€” the engine (FastAPI service, scanner, strategy, alerts, dashboard)
- `data_feed.py` β€” hardened forex fetcher (curl_cffi + retry; fixes Yahoo JSONDecodeError)
- `persistence.py` β€” restart-safe storage: SQLite Trade History + JSON live state on `/data`
- `history_page.html` β€” standalone Trade-History analytics dashboard (served at `/history`)
- `instruments.py` β€” curated forex universe + pip/digit/spread/contract metadata
- `market_clock.py` β€” forex open/closed clock (sessions, weekend, holidays)
- `economic_calendar.py` β€” ForexFactory news radar + safe-to-trade grading
- `risk_forex.py` β€” pip / lot / leverage / margin / $ risk-reward (spread-aware)
- `Dockerfile`, `start.sh`, `run_one_shot.sh`, `preflight_check.py`, `requirements.txt`
- `STRATEGY_DETAILED_SPEC.txt` β€” exact strategy behavior
- `VARIABLES_AND_SECRETS_GUIDE.txt` β€” every env var, with tuning guidance
- `AGENT.md` β€” maintainer / AI-agent handover guide
- `SKILL.md` β€” Starchild skill manifest
## What's new in v6.0 (forex)
- **Forex data source** β€” Yahoo Finance via `yfinance` (FX, metals, energy,
indices), replacing the crypto exchange feed entirely.
- **Forex risk model** β€” pips / lots / `LEVERAGE` (margin only) / $ risk-reward,
spread-aware. No more ROI / auto-leverage.
- **Intrabar Stage 3 & exits** β€” touch-and-reject registers immediately; SL / TP /
Break-even fire the moment price reaches them.
- **No TTL on Stage 3/4** β€” late-stage setups resolve only on their real triggers.
- **Market clock** β€” browser-timezone-aware Open/Closed badge with countdown.
- **Economic news radar** β€” impact-graded Safe / Caution / No-Trade with event
label + countdown, on the dashboard and inside Telegram alerts.
- **New theme (v6.0)** β€” a modern dark slate / indigo / violet UI (no more green),
recoloured inner tables, a responsive grouped header (logo + title together,
tags below), modern market/news icons, and a uniform animated header sheen.
### v6.0 stability & feature additions
- **Drift-proof state machine** β€” all locked structure (FVG, impulse, liquidity,
BoS, FVG interaction) is anchored to candle TIMESTAMPS and re-resolved every
cycle, so setups no longer corrupt over time. A confirmed Stage 4 stays put and
is removed only on a real SL / TP2 / Break-Even (or invalidation), never by the
sliding data window. Fixes "works after restart, breaks later, scattered lines".
- **Hardened forex feed** β€” `data_feed.py` uses a `curl_cffi` browser-impersonation
session + batch→per-symbol retry with backoff, fixing the Yahoo
`Expecting value: line 1 column 1 (char 0)` JSONDecodeError. Still keyless.
- **Restart-safe persistence** β€” `persistence.py` stores Trade History (SQLite)
and live state / alerts / stats (atomic JSON) on a mounted Hugging Face Storage
Bucket at `/data` (Xet). On boot the engine reloads and reconciles. Mount the
bucket read-write at `/data`; without one it still runs (resets on restart).
- **Fast Stage 3/4 monitor** β€” a dedicated high-frequency loop re-checks only the
active late-stage pairs every few seconds, so touches, confirmations and exits
(and their alerts) fire promptly even for newly-sorted pairs.
- **Trade History dashboard** β€” the "Trade History" title opens `/history`, a full
analytics page (win rate by TP/SL/BE, total trades, most-traded pair & category,
cumulative performance curve, outcome / direction / category charts) with time
filters (15m β†’ All time) and a filterable closed-trades table.
- **Browser notifications** β€” opt-in desktop/mobile alerts for new Stage 3 & 4
signals, alongside Telegram.