85a5ba09b8
- webapp/: deployable LAMP app for /var/www/ — ingest.php (token-gated writes), api.php (public read-only), schema.sql (live_price + signal_reports), vanilla-JS dashboard with plain-English indicator readings, .htaccess, deploy README - web_publisher.py: fire-and-forget publisher (bounded queue + daemon thread) with plain-English payload builder; public API contractually never raises; disabled unless WEBAPP_INGEST_URL/TOKEN are set - telegram_bot.py: publish hooks (tick in WS loop, report in _update_level_cache); _candle_loop per-iteration guard so a failing scan can never kill an auto-scan loop; quiet heartbeat teardown - test_all.py: Module 13 — 6 resilience tests (never-raise contract, worker survival, candle-loop survival); suite 189/189 - .gitignore: webapp/config.php (server-side secrets) Verified end-to-end on a scratch MariaDB 10.11 + PHP 8.3 built-in server incl. headless-Firefox render of the live page. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KYNEHBuwwy6sgRM9f9sPx5
2.4 KiB
2.4 KiB
ForexBot2 web dashboard (LAMP)
Numbers-only live dashboard: latest XAU/USD price plus each timeframe's signal, indicator values, and a plain-English reading of every one.
How it flows
telegram_bot.py (owns the single Twelve Data WebSocket)
├─ every tick ──► POST ingest.php ──► MySQL live_price (throttled 1/s)
└─ every scan ──► POST ingest.php ──► MySQL signal_reports
│
browser ──► index.html + app.js ──► GET api.php ┘
(price poll 2 s · reports poll 15 s)
The dashboard needs no Python on the web server — only PHP + MySQL. The bot can run anywhere with outbound HTTPS to the site.
Server setup (once)
- Copy this directory to the web root, e.g.
/var/www/html/webapp/. - Create DB + tables:
mysql -u root -p < schema.sql(also create the app user — commands at the bottom of schema.sql). cp config.sample.php config.phpand fill in DB credentials and a freshingest_token(openssl rand -hex 32).- Apache must allow
.htaccess(AllowOverride FileInfo LimitorAll) so config/schema stay unreachable — or copy those deny rules into the vhost. Verify:curl -I https://site/webapp/config.phpmust return 403.
Bot setup
Set two environment variables where telegram_bot.py runs:
export WEBAPP_INGEST_URL="https://your-site/webapp/ingest.php"
export WEBAPP_INGEST_TOKEN="<same token as config.php>"
Unset = publishing is disabled and the bot behaves exactly as before. Publishing is fire-and-forget (bounded queue + daemon thread): a dead web server can never block or slow the bot.
Security notes (public access)
api.phpis read-only and public by design;ingest.phprequires the shared token (use HTTPS so it isn't sent in the clear).config.php/schema.sqlare denied by.htaccess.- Optional hardening: rate-limit
api.php(mod_evasive/fail2ban), and restrictingest.phpto the bot host's IP in the vhost.
Data growth
live_price: 1 row per symbol (upserted in place).signal_reports: ~400 rows/day for XAU (M5+M15+H1+H4) — ~150k rows/year, no retention job needed. It doubles as a durable log of every signal the engine produced (thepayloadcolumn holds the full report JSON).
Local smoke test (no Apache needed)
php -S 127.0.0.1:8090 -t webapp/ # then open http://127.0.0.1:8090/