# Today Trades (Stage A — shareable dashboard)

Read-only **enter / exit / hold** page you can share with someone else.  
No auto-trading. They place orders in their own brokerage.

| Artifact | Path |
|----------|------|
| UI | `today_trades.html` (repo root) |
| Snapshot | `RenTech/data/logs/today_trades_snapshot.json` |
| Builder | `RenTech/monitor/build_today_trades_snapshot.py` |
| Server | `RenTech/monitor/serve_today_trades.py` |

Schema uses `books[]` + `account_id` so Stage B can add users without rewriting the page.

## Host on a VPS with **auto-refresh** (recommended)

Signals rebuild on the server every ~30 minutes during US market hours. You do **not** run the builder on your laptop.

### One-time setup (DigitalOcean $6 / Hetzner CX22, Ubuntu)

```bash
# on the VPS
sudo apt update && sudo apt install -y git
sudo mkdir -p /opt/rentech && sudo git clone <YOUR_REPO_URL> /opt/rentech/trading_bot
cd /opt/rentech/trading_bot

# edit open dip names (and nav / scale) once
nano RenTech/monitor/config/today_trades_book.json

export TODAY_TRADES_PASSWORD='pick-a-strong-password'
export DEPLOY_USER=root
export REPO_DIR=/opt/rentech/trading_bot
bash deploy/today_trades/bootstrap_vps.sh
```

That installs:

| Piece | What it does |
|-------|----------------|
| `rentech-today-trades.service` | Serves the site on `127.0.0.1:8765` |
| `rentech-today-refresh.timer` | Rebuilds snapshot **Mon–Fri ~every 30m, 9:30–15:55 ET** |

Open `http://VPS_IP:8765/today_trades.html` (open firewall TCP 8765), or put Caddy in front — see `deploy/today_trades/Caddyfile.example`.

### Day-to-day

```bash
# after you open/close dips, update held list then force refresh
nano /opt/rentech/trading_bot/RenTech/monitor/config/today_trades_book.json
sudo systemctl start rentech-today-refresh.service

# check timer / logs
systemctl list-timers rentech-today-refresh.timer
journalctl -u rentech-today-refresh.service -n 50 --no-pager
```

## Host build on a VPS (manual cron only)

Yes — the snapshot is just Yahoo + your held list. Run it on the server.

1. Clone repo on the VPS, create `.venv`, install deps (`yfinance`, `pandas`, etc.).
2. Edit held names once (or when the book changes):

```bash
nano RenTech/monitor/config/today_trades_book.json
```

3. Cron (example: weekdays **9:40 ET** = 13:40 UTC when EDT):

```bash
crontab -e
```

```cron
40 13 * * 1-5 cd /path/to/trading_bot && .venv/bin/python -m RenTech.monitor.refresh_today_trades >> RenTech/data/logs/today_trades_cron.log 2>&1
```

4. Keep the web server running (systemd / screen):

```bash
TODAY_TRADES_PASSWORD='pick-a-password' .venv/bin/python -m RenTech.monitor.serve_today_trades \
  --host 127.0.0.1 --port 8765
```

Put Caddy/nginx + HTTPS in front. After cron runs, the site updates on refresh — you never build on your laptop.

Manual refresh on the VPS anytime:

```bash
.venv/bin/python -m RenTech.monitor.refresh_today_trades
```

## Run (exact) — local

```bash
cd /Users/robzingale/trading_bot

# 1) Build today's tickets (edit --held to match open CM dips)
PYTHONUNBUFFERED=1 .venv/bin/python -m RenTech.monitor.build_today_trades_snapshot \
  --nav 50000 --fund-scale 1.5 \
  --held AMZN,QCOM,AXP,INTC,LRCX,AMAT,MU,AMD,GEV \
  --approx-per-name-mv 2500

# 2) Serve with a share password
TODAY_TRADES_PASSWORD='pick-a-password' .venv/bin/python -m RenTech.monitor.serve_today_trades \
  --host 0.0.0.0 --port 8765
```

Friend opens: `http://YOUR_LAN_IP:8765/today_trades.html` and enters the password.

Local only:

```bash
TODAY_TRADES_PASSWORD='pick-a-password' .venv/bin/python -m RenTech.monitor.serve_today_trades
# → http://127.0.0.1:8765/today_trades.html
```

## Refresh during the day

Re-run the **build** command (step 1), then hit refresh in the browser. The page loads the JSON with cache-busting.

## Notes

- `--approx-per-name-mv 2500` marks the sleeve **over budget** when you sized ~$2.5k/name (skips new entries).
- After exits free capacity, drop that flag or set `--approx-per-name-mv 1275`.
- State file `RenTech/data/live_state/cm_dip_positions.json` is merged when present.
- Disclaimer is embedded in the snapshot footer.
