Khurram Badar / Archive / Papers / Metals trading desk technical platform guide

Metals trading desk technical platform guide

whitepaper · 2026-05-22 · 2769 words · Khurram Badar

Production whitepaper on COMEX gold and silver trading platform with 15 autonomous agents and Dubai trader workflow integration.

trading · metals · fintech · autonomous-agents · technical

Metals Trading Desk — Technical Whitepaper

**Platform:** metalstradingdesk.com
**Codebase:** titan_trader
**Target user:** COMEX gold/silver swing trader (Dubai, UTC+4)
**Author:** Engineering log, build sessions through 2026-05-22
**Status:** Production on Railway (backend) + Vercel (frontend)

---

1. What this platform is

---

2. Problems solved

---

3. Architecture — one liner per layer

---

4. The signal engine — algorithm

4.1 Inputs (per signal generation cycle)

4.2 Algorithm — step by step

1. **Fetch.** Pull all inputs in parallel; reject any older than the staleness threshold (5 min for prices, 24h for macro).
2. **Validate.** Run data integrity check: gap detection, spike detection, cross-source agreement, null fallback. Health Monitor records failures.
3. **Score per layer.** Each layer outputs a directional score in [-1, +1] with a conviction in [0, 1]:
- Intermarket: weighted vote of 4 inputs (DXY inverse, SPX, US10Y inverse, BTC).
- Macro: real yield direction + inflation surprise.
- Positioning: COT z-score + WoW delta.
- Sentiment: GLD P/C deviation from 0.85 baseline.
- Pattern: closest-match pattern from learning DB with historical win rate.
4. **Session-weight.** Multiply each layer's contribution by the active session weight. COMEX hour weights 1.0; Shanghai 0.4. This means signals generated during Shanghai are softer than COMEX-hour signals.
5. **Aggregate.** Weighted sum → composite conviction in [-100, +100]. Threshold: `|conviction| > 20` to emit BUY/SELL, else FLAT.
6. **Risk levels.** Compute ATR(14) on hourly bars. Entry = current mid. Stop = entry ± 1.5 × ATR. Target = nearest swing high/low with min 1:2 R:R; if no swing, use 2.5 × ATR.
7. **Record.** Write to SQLite signal history with timestamp, all layer scores, ATR, entry/stop/target.
8. **Publish.** Push to Redis `master_signals`; WebSocket to frontend; available via `/api/signals/GOLD`.
9. **Track outcome.** Learning pipeline checks price at +1h, +4h, +24h vs entry/stop/target. Updates pattern win rates.

4.3 Honest constraints baked into the algorithm

---

5. The 15 agents — what each does

| # | Agent | Cadence | Source | What it produces |
|---|---|---|---|---|
| 1 | Master Agent | On demand + every session open | All other agents | Synthesized buy/sell narrative; Haiku-powered chatbot |
| 2 | Session Agent | Real-time | Time-zone math | Which exchange is active, weight, next critical moment |
| 3 | COMEX Hourly Engine | Hourly during COMEX | yfinance GC=F/SI=F 1h | Opening range breakout signals, hourly H/L tracking |
| 4 | Intermarket Signal | Every 30 min | yfinance DXY/SPX/US10Y/BTC | 4/4 voting composite STRONG SELL → STRONG BUY |
| 5 | COT Positioning | Friday + ad hoc | CFTC SODA API | Managed money net, z-score, WoW delta |
| 6 | Options Sentiment | Daily | AlphaQuery GLD P/C | Put/call ratio + interpretation |
| 7 | BLS Economic | Daily + release days | BLS API | CPI, PPI, NFP, Unemployment + release calendar |
| 8 | Fed / Warsh | Daily | FRED API | Real yield, Fed Funds, FOMC calendar, Chair-watch |
| 9 | Trump PhD | Every 4 hours | CNN archive + Federal Register + WH briefings | Posts, executive orders, frequency, language patterns |
| 10 | LME Warehouse | Daily | LME Excel + yfinance fallback | Warehouse stock levels for gold/silver |
| 11 | Shanghai Premium | Shanghai open | 518880.SS ETF + USD/CNY | Physical demand proxy via Huaan Gold ETF vs COMEX |
| 12 | Health Monitor | Every 5 min | Internal checks | Null detection, auto-fix, staleness alerts |
| 13 | Diagnostics | Continuous | Health Monitor reports | 24h rolling history, uptime %, worst feeds ranked |
| 14 | Signal Recorder + Learning | Every signal | SQLite | Records signals, tracks 1h/4h/24h outcomes, 9 patterns |
| 15 | Social Media Intelligence | Each session open + every 4h | X RSS, YouTube RSS, Chinese sites | Multilingual narrative layer with bullish/bearish tally |

---

6. Agent workflow — what they actually do

6.1 A normal Dubai day

6.2 Per-agent micro-workflow

---

7. The signal pipeline — end to end

```
[ yfinance ] [ FRED ] [ CFTC ] [ BLS ] [ AlphaQuery ] [ LME ] [ Chinese sites ] [ X/YouTube RSS ] [ CNN ] [ Federal Register ]
│ │ │ │ │ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Per-agent fetch + validate │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Health Monitor (5 min) ─── catches NULLs, staleness, cross-source disagreement ─── auto-fixes when possible │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Layer scoring: Intermarket / Macro / Positioning / Sentiment / Pattern ─── each outputs [-1, +1] + conviction │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Session weighting (Shanghai 0.4 / LME 0.6 / COMEX 1.0 / Globex 0.3) │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Composite conviction → BUY / SELL / FLAT + ATR-based Entry / Stop / Target │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Signal Recorder (SQLite) → Learning pipeline tracks 1h / 4h / 24h outcomes vs 9 patterns │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ REST + WebSocket → /agents dashboard, Master Agent context, signal cards │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

---

8. Constraints we worked under

---

9. Platform vs alternatives

9.1 vs TradingView

| Dimension | TradingView | Metals Trading Desk |
|---|---|---|
| Charting | Industry leader, full Pine Script ecosystem | Lightweight Charts v4 + KlineChart fallback — basic |
| Asset coverage | Every market on earth | Gold/silver + 18 watchlist instruments |
| Data feeds | Real-time on paid tiers | ~15 min delayed (yfinance free) |
| Custom signals | User-built indicators only | 15 autonomous agents pre-built + Master Agent synthesis |
| Macro context | Manual; user reads news | Automated BLS, Fed, COT, options, Trump, Chinese sentiment integrated into signal |
| Session awareness | Manual time-zone math | Built in (Dubai-anchored, COMEX-priority) |
| Narrative layer | User reads news themselves | Social Media Intelligence agent in 3 languages |
| Trade journal | Yes, paid | Signal Recorder + Learning Pipeline, free |
| Mobile | Best-in-class app | Web only, mobile-responsive |
| Community | Millions of users | Single-user product |
| **Honest verdict** | **Better for charting, breadth, real-time data, community.** | **Better for COMEX-specific autonomous synthesis and decision support.** |

9.2 vs other platforms

---

10. What's running every day

---

11. Daily debugging — what we monitor and why

---

12. Engines running on this platform

---

13. What enhances value next

---

14. Verification artifacts (latest live numbers)

---

15. Closing — honest self-assessment

← System architecture visualization for fintech platformsKhan TED Institute: future of higher education →
Two years of working thought, indexed.
Ask me to present it in your conference room — WhatsApp +971 55 623 9111
Book Session →