167 lines
4.9 KiB
Markdown
167 lines
4.9 KiB
Markdown
# 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/
|
||
```
|
||
|
||
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`; the browser polls `/api/state` automatically every 5 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
|
||
|
||
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, entry/exit fields, and scaler versus runner P&L attribution when present in TOOL-001 trade records.
|
||
4. Provenance health: sentinel/default-value counts per provenance 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.
|