Files
2026-08-11 21:20:07 +03:00

40 lines
1.9 KiB
Markdown

# Read-Only Performance UI
## Goal
Provide a single read-only page for checking Alpaca paper account performance and recent trading activity without exposing any trading controls.
## Requested Feature List
- Show the last three months of account performance in the header as text, or a shorter range when less data is available.
- Show account value over time as the main body chart.
- Include an S&P 500 comparison line in the chart. The initial implementation uses `SPY` daily candles as the S&P 500 proxy because Alpaca stock market data exposes it through the same API path.
- Show a portfolio table below the chart with cash plus equity positions.
- Show a completed trades table at the end of the page.
- Use Python and `alpaca-py` in the backend.
- Serve the page directly from the backend as a single page with no user options.
- Cache fetched data in SQLite and refresh periodically, initially every 12 hours.
## Design Notes
The UI is intentionally separate from the trading and training modules. It reads account state from Alpaca, stores normalized snapshots in SQLite, and renders HTML from the backend. It does not place, replace, or cancel orders.
The first cache path is `data/ui/performance.sqlite`. On each page request, the server refreshes data only when the cache is older than the configured refresh interval. If Alpaca refresh fails but cached data exists, the page can still render stale data with a warning.
## Backend Data
The dashboard stores:
- account equity history for up to three months;
- normalized S&P 500 proxy values from `SPY`;
- the latest cash and equity holdings snapshot;
- recently closed orders that have a filled quantity.
## Run Command
```sh
mise exec -- uv run python -m trading_bot.ui.dashboard --paper
```
The server defaults to `127.0.0.1:8000` and reads `ALPACA_API_KEY` and `ALPACA_SECRET_KEY` from the environment or local `.env`.