Trading bot: /metrics endpoint + roll-doubling hazard documentation #1

Merged
pook merged 2 commits from feat/trading-observability into master 2026-08-12 10:47:29 -04:00
Owner

Summary

Two commits that complete the trading bot's observability wiring and contain a stop-the-bleeding fix for the roll-doubling hazard discovered mid-session.

Commits

  • disable daily cycle + document roll-doubling hazard (dashboard/crontab, strategies/pmcc.py)

    • The PMCC roll path emits ENTER-style orders under _StubChainFetcher's fixed-strike symbols (SPY_L630/SPY_S14): no close-then-open semantics, no expiration-unique OCC symbols, no expired-contract filter in JournalPositionProvider. Net effect: position doubles each cycle once DTE goes negative.
    • Disable the daily cron entry to stop the bleeding.
    • Add a ponytail: ceiling comment in _should_roll_short naming the three-step upgrade path: (1) close legs in _roll_signal via the existing build_exit_order pattern, (2) filter expired contracts in _aggregate_net, (3) expiration-unique OCC-like symbols in _StubChainFetcher.
    • VPS DBs flattened (trading.db wiped; paper_trading.db cash reset to initial $100K, positions/orders/fills wiped) so the dashboard shows clean state.
  • /metrics route for Prometheus scrape (dashboard/app.py)

    • Hand-rolled Prometheus text exposition (stdlib only — avoids adding prometheus_client dependency + container rebuild). Eight gauges cover dashboard-observable state:
      • trading_dashboard_up (liveness)
      • trading_dashboard_trading_db_present / paper_db_present
      • trading_dashboard_cash / initial_capital / open_positions
      • trading_dashboard_trades_total
      • trading_dashboard_cycle_status (1=complete, 0=started, -1=none/error)
    • Scraped by VPS Prometheus via https://trades.viztekpro.com/metrics (robust to container IP changes via Traefik). Federated up to BatKave via the existing federation-vps job.

Test plan

  • dashboard/app.py /metrics route verified locally via FastAPI TestClient — valid Prometheus exposition, correct content-type.
  • Deployed to VPS trading-dashboard container; curl https://trades.viztekpro.com/metrics returns the 8 gauges.
  • VPS Prometheus target shows trading-dashboard → https://trades.viztekpro.com/metrics | up.
  • PromQL verified: trading_dashboard_up = 1, trading_dashboard_cash = 100000.
  • DB state on VPS post-flatten: trading.db 0 rows in all tables, paper_trading.db 1 paper_account row with cash=initial=$100K, 0 positions/orders/fills.
  • Daily cron entry confirmed disabled in container crontab.

Cross-repo coordination

This PR is one of three merge units for the trading-bot-to-observability wiring. See pook/engineer-team PR #5 for the central alertmanager/Prometheus config changes, and pook/batkave-home PR (pending) for the ntfy + alertmanager-webhook bind fixes.

🤖 Generated with Claude Code

## Summary Two commits that complete the trading bot's observability wiring and contain a stop-the-bleeding fix for the roll-doubling hazard discovered mid-session. ### Commits - **disable daily cycle + document roll-doubling hazard** (`dashboard/crontab`, `strategies/pmcc.py`) - The PMCC roll path emits ENTER-style orders under `_StubChainFetcher`'s fixed-strike symbols (SPY_L630/SPY_S14): no close-then-open semantics, no expiration-unique OCC symbols, no expired-contract filter in `JournalPositionProvider`. Net effect: position doubles each cycle once DTE goes negative. - Disable the daily cron entry to stop the bleeding. - Add a `ponytail:` ceiling comment in `_should_roll_short` naming the three-step upgrade path: (1) close legs in `_roll_signal` via the existing `build_exit_order` pattern, (2) filter expired contracts in `_aggregate_net`, (3) expiration-unique OCC-like symbols in `_StubChainFetcher`. - VPS DBs flattened (`trading.db` wiped; `paper_trading.db` cash reset to initial $100K, positions/orders/fills wiped) so the dashboard shows clean state. - **`/metrics` route for Prometheus scrape** (`dashboard/app.py`) - Hand-rolled Prometheus text exposition (stdlib only — avoids adding `prometheus_client` dependency + container rebuild). Eight gauges cover dashboard-observable state: - `trading_dashboard_up` (liveness) - `trading_dashboard_trading_db_present` / `paper_db_present` - `trading_dashboard_cash` / `initial_capital` / `open_positions` - `trading_dashboard_trades_total` - `trading_dashboard_cycle_status` (1=complete, 0=started, -1=none/error) - Scraped by VPS Prometheus via `https://trades.viztekpro.com/metrics` (robust to container IP changes via Traefik). Federated up to BatKave via the existing `federation-vps` job. ## Test plan - [x] `dashboard/app.py` `/metrics` route verified locally via FastAPI TestClient — valid Prometheus exposition, correct content-type. - [x] Deployed to VPS `trading-dashboard` container; `curl https://trades.viztekpro.com/metrics` returns the 8 gauges. - [x] VPS Prometheus target shows `trading-dashboard → https://trades.viztekpro.com/metrics | up`. - [x] PromQL verified: `trading_dashboard_up = 1`, `trading_dashboard_cash = 100000`. - [x] DB state on VPS post-flatten: `trading.db` 0 rows in all tables, `paper_trading.db` 1 paper_account row with cash=initial=$100K, 0 positions/orders/fills. - [x] Daily cron entry confirmed disabled in container crontab. ## Cross-repo coordination This PR is one of three merge units for the trading-bot-to-observability wiring. See `pook/engineer-team` PR #5 for the central alertmanager/Prometheus config changes, and `pook/batkave-home` PR (pending) for the ntfy + alertmanager-webhook bind fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The roll path emits ENTER-style orders under _StubChainFetcher's
fixed-strike symbols (SPY_L630/SPY_S14): no close-then-open, no
expiration-unique OCC symbols, no expired-contract filter in
JournalPositionProvider. Net effect: position doubles each cycle
once DTE goes negative.

Disable the cron entry to stop the bleeding; add a ponytail ceiling
comment naming the three-step upgrade path (close legs in _roll_signal,
filter expired contracts in _aggregate_net, expiration-unique symbols
in _StubChainFetcher). DBs flattened on VPS so dashboard shows clean
$100K / no-position state.
Hand-rolled Prometheus text exposition (stdlib only — avoids adding
prometheus_client dependency + container rebuild). Eight gauges
cover dashboard-observable state:

  - trading_dashboard_up (liveness)
  - trading_dashboard_trading_db_present / paper_db_present
  - trading_dashboard_cash / initial_capital / open_positions
  - trading_dashboard_trades_total
  - trading_dashboard_cycle_status (1=complete, 0=started, -1=none)

Scraped by VPS Prometheus via https://trades.viztekpro.com/metrics
(robust to container IP changes via Traefik). Federated up to BatKave
via the existing federation-vps job.

ponytail: stdlib over prometheus_client — RFC-correct text format in
~30 lines, no new dep, no rebuild.
pook merged commit 2db7bdd7d5 into master 2026-08-12 10:47:29 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/trading-intelligence!1
No description provided.