Files
nt8-sdk/tools/dashboard/README.md
mo d84949caa3 chore: checkpoint remaining pre-gate worktree changes
- governance: stage v7.0 review prompts, run book, roadmap/current-status/decision updates, and sprint board state

- adapters: capture DASH/trailing-drawdown/state-telemetry strategy work already present in the worktree

- tools: capture dashboard console/KPI parser updates, logtriage notes, and runnersweep output

Build: previously clean | Tests: previously 511 passing | Includes all open staged files
2026-08-21 14:53:15 -04:00

177 lines
5.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# dashboard
`dashboard` is a standalone read-only dashboard for TOOL-001 JSON output and live local NT8 SDK log artifacts.
Implementation choice: static HTML + vanilla JavaScript plus an optional dependency-free Python localhost server. The server reads files only, binds to `127.0.0.1`, has no write/POST endpoints, and can optionally send outbound notifications through Apprise.
## Safety Properties
- Read-only browser UI
- No NinjaTrader assembly references
- No writes to any NinjaTrader directory
- No network dependency or CDN usage
- No package install required
- Can run directly from disk or on localhost only
- Server binds only to `127.0.0.1`; `0.0.0.0` is rejected in code
- Server implements only `GET`, `HEAD`, and `OPTIONS`; `POST`, `PUT`, `PATCH`, and `DELETE` return `405 Method Not Allowed`
- Runtime state is written only to `tools/dashboard/dashboard_state.json` by default to avoid duplicate notifications after restart
## Generate Input JSON
From the repo root:
```powershell
python tools/logtriage/logtriage.py --json | Out-File -Encoding utf8 triage.json
```
For an archive directory:
```powershell
python tools/logtriage/logtriage.py "C:\logs\nt8-sdk-archive" --json | Out-File -Encoding utf8 triage.json
```
PowerShell 5.1 `>` redirection writes UTF-16LE by default. Use `Out-File -Encoding utf8` so the browser can parse the JSON file.
## Launch
Direct file launch:
```powershell
Start-Process .\tools\dashboard\index.html
```
Static localhost-only launch:
```powershell
python -m http.server 8765 --bind 127.0.0.1 --directory tools/dashboard
```
Then open:
```text
http://127.0.0.1:8765/
```
The alternate trading-terminal view is available at:
```text
http://127.0.0.1:8765/console.html
```
Live read-only server launch:
```powershell
Copy-Item .\tools\dashboard\config.example.json .\tools\dashboard\config.json
python .\tools\dashboard\server.py --config .\tools\dashboard\config.json
```
Then open:
```text
http://127.0.0.1:8765/
```
## Usage
1. Generate `triage.json` from TOOL-001.
2. Open the dashboard.
3. Click `Select triage.json` and choose the generated file.
4. Review the five views.
For live mode, launch `server.py`; `index.html` polls `/api/state` automatically every 5 seconds and `console.html` polls every 2 seconds.
## Live Server Config
`config.example.json`:
```json
{
"host": "127.0.0.1",
"port": 8765,
"log_dir": "%USERPROFILE%\\Documents\\NinjaTrader 8\\log\\nt8-sdk",
"state_file": "dashboard_state.json",
"polling": {
"session_log_seconds": 2,
"trades_seconds": 10,
"provenance_seconds": 10
},
"notifications": {
"enabled": false,
"targets": [],
"events": {
"submit": true,
"fill": true,
"breakeven": true,
"connection": true,
"daily_pnl_milestones": true
},
"daily_pnl_milestones": [100, 250, 500, -100, -250, -500]
}
}
```
`%USERPROFILE%` is expanded with Python environment-variable expansion, not a hardcoded username.
Polling defaults:
- newest session log tail: `2` seconds
- trades JSONL table: `10` seconds
- provenance/settings panel: `10` seconds
## Notifications
Install optional Apprise support:
```powershell
python -m pip install -r .\tools\dashboard\requirements.txt
```
Add Apprise URLs to `config.json`:
```json
"notifications": {
"enabled": true,
"targets": [
"discord://webhook_id/webhook_token",
"ntfy://ntfy.sh/your-topic"
]
}
```
Notification triggers:
- `SUBMIT`
- `FILL`
- `BREAKEVEN`
- `CONNECTION LOST`
- `CONNECTION RESTORED`
- `PNL_UPDATE` crossing configured daily P&L milestones
Daily P&L milestone tracking resets only on session rollover via `SESSION START`, not on position-flat. This intentionally mirrors the corrected MaxDailyTrades behavior: position-flat does not re-arm daily state.
Offset and dedup state persist to `tools/dashboard/dashboard_state.json` by default. This prevents a mid-day server restart from re-firing the entire day’s notification history. If that file is deleted, the server starts at the current end of the already-existing newest session log to avoid historical notification replay.
Webhook/notification failures are logged to stderr and never crash or block the dashboard poller.
## Views
`index.html` is the triage board for deciding whether a silent session was a strategy decision or an operational defect.
`console.html` is the alternate trading-console page. It consumes the same read-only `/api/state` payload and shows live strategy status, session readiness, provenance-backed trade rows, count-only grade distribution, PNL_UPDATE curve data, real FactorType score breakdowns, and raw log tail data. Fields that are not emitted by the runtime, such as entry/exit price and per-trade P&L, are explicitly marked unavailable instead of being inferred.
1. Gate progress: trades banked against the 20-trade minimum, elapsed session days, current traded-session streak, and diagnostic count.
2. Daily timeline: one row per session, color-coded as traded, silent, or config violation.
3. Trade detail: grade, score, and provenance fields when present in TOOL-001 trade records.
4. Provenance health: sentinel/default-value counts per field across trade records.
5. Config integrity: `ConfigHash` and `CodeVersion` timeline with drift markers.
## Data Contract
The dashboard consumes TOOL-001 JSON with these top-level fields:
- `rows`: session summaries
- `diagnostics`: diagnostics emitted by TOOL-001
- `trade_records`: per-trade JSONL records enriched with `date`, `path`, and `line`
The UI is tolerant of missing fields and displays `-` when a requested value is absent.