Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Real-time risk monitoring system for XAU/USD (Gold) trading signals. Connects to your gold-confirm and main signal bots, tracks positions, scores risk, and sends Telegram alerts when risk escalates.
🔗 Live Dashboard: https://risk-guardian.val.run/
- Live Gold Price — fetches XAU/USD spot price + DXY from multiple free APIs
- Signal Polling — auto-discovers signal APIs from gold-confirm + main signal bots
- Webhook Receiver — external bots can POST signals directly to
/api/signals/webhook - Risk Scoring Engine — 0–100 score based on SL distance, TP distance, momentum, DXY, P&L
- Demo Paper Trading — auto-opens/closes trades, tracks balance, equity, win rate
- Telegram Alerts — new positions, risk escalations, and position closures
- Dashboard UI — live risk cards, stats bar, alert feed, demo account panel
- Cron Monitor — runs every 15 min to poll signals, assess risk, and update demo
Rendering mermaid diagram...
index.ts ← Hono API server (all routes)
cron.ts ← Interval cron (auto-monitor every 15 min)
lib/
types.ts ← Shared TypeScript interfaces
db.ts ← SQLite database layer
risk.ts ← Risk scoring engine (0–100)
price.ts ← XAU/USD + DXY price feeds
telegram.ts ← Telegram alert sender + formatters
signal-poller.ts ← Multi-source signal polling + webhook
demo.ts ← Paper trading engine (auto open/close)
frontend/
index.html ← HTML shell (Twind + React)
index.tsx ← React entrypoint
components/
App.tsx ← Root dashboard (tabs + live data)
RiskCard.tsx ← Per-position risk card with score bar
StatsBar.tsx ← Summary stats row
AlertFeed.tsx ← Alert history list
DemoPanel.tsx ← Demo account + trade tables
| Method | Path | Description |
|---|---|---|
| GET | /api/health | Health check |
| GET | /api/stats | Dashboard summary stats |
| GET | /api/price | Live gold price + DXY |
| GET | /api/risk | Live risk assessment for all active positions |
| GET | /api/risk/history | Recent risk history entries |
| GET | /api/risk/:id | Risk history for specific position |
| GET | /api/positions | All positions |
| GET | /api/positions/active | Active (watching) positions only |
| GET | /api/alerts | Recent alerts |
| GET | /api/demo | Demo account stats |
| GET | /api/demo/trades | All demo trades |
| GET | /api/demo/open | Open demo trades |
| POST | /api/poll | Manually trigger signal polling |
| POST | /api/signals/webhook | Receive signals from external bots |
| POST | /api/signals/inject | Manually inject a signal |
| POST | /api/monitor | Full monitor cycle (poll + risk + demo) |
POST to /api/signals/webhook:
{ "signal_id": "sig-2024-001", "direction": "LONG", "entry_price": 2380.50, "sl_price": 2370.00, "tp_price": 2400.00, "invalidation_level": 2365.00, "status": "confirmed", "timestamp": "2024-07-01T12:00:00Z" }
| Key | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN | No* | Telegram bot token for alerts |
TELEGRAM_CHAT_ID | No* | Telegram chat ID for alerts |
*Without Telegram credentials, alerts are logged but not sent.
👉 Add TELEGRAM_BOT_TOKEN here: https://www.val.town/x/Hunter5/risk-guardian/environment-variables?key=TELEGRAM_BOT_TOKEN 👉 Add TELEGRAM_CHAT_ID here: https://www.val.town/x/Hunter5/risk-guardian/environment-variables?key=TELEGRAM_CHAT_ID
| Score | Level | Meaning |
|---|---|---|
| 0–34 | 🟢 Safe | Position is healthy |
| 35–59 | 🟡 Caution | Monitor closely |
| 60–79 | ⚠️ Danger | Consider action |
| 80–100 | 🚨 Critical | Immediate attention needed |
Factors: SL distance (40pts), momentum (25pts), DXY correlation (15pts), unrealized P&L (15pts), invalidation proximity (10pts), TP proximity (-15pts).