Restore source files from Google Drive backup

This commit is contained in:
Aryan Singh committed 2026-10-27 12:34:02 -05:00
1 parent 7635a8529f
commit 0ca8c65c9e
5 files changed
+477

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
# scripts/
Local operational scripts for the paper-trading agent. This machine holds the
Alpaca keys and the Gmail app password (`.env`) — none of that ever leaves it.
## export_public.py — sanitized public snapshot
Produces `trading-public.json`, the ONLY artifact the public dashboard
(`sites/apps/trading`) is allowed to read. It is fully decoupled: the hosted app
reads a file, it never touches this DB or any key.
```bash
python3 scripts/export_public.py \
--db state/trading.db \
--out trading-public.json
```
Stdlib only (no `uv`/venv needed). Flags:
- `--db` path to the SQLite DB (default `state/trading.db`)
- `--out` output JSON path (default `./trading-public.json`)
- `--output-dir` nightly committee dir holding `<date>/_committee.json`
(default `<db_dir>/output`)
### What it emits / strips
- EMITTED: per-persona **percent** returns, **base-100** normalized (coarse/sample)
equity curves, thesis cards, committee verdicts, trade markers, and positions
as (symbol + side + **relative** weight).
- STRIPPED: absolute `$` equity / cash / buying-power, Alpaca account IDs, Alpaca
order IDs, per-share prices and market values.
A self-check scans the emitted JSON for `$`, UUID id patterns, and raw
account-level dollar figures and **aborts** on any hit, so a sanitization
regression can never ship. The script only prints percentages and counts.
## Scheduling (launchd / cron)
Run it right after the nightly research + morning execution have written the DB
and committee JSON, so the public snapshot reflects the latest close.
launchd (matches the existing `launchd/ai.tradingagent.*.plist` style) — a
daily job after the 08:30 CT execution, e.g. a wrapper `scripts/export.sh`:
```bash
#!/usr/bin/env bash
cd /Users/aryan/Documents/GitHub/trading-agent
python3 scripts/export_public.py --db state/trading.db --out state/trading-public.json
# then sync to wherever the app reads it (see below)
```
cron equivalent (09:15 local, after execution settles):
```cron
15 9 * * 1-5 cd /Users/aryan/Documents/GitHub/trading-agent && \
/usr/bin/python3 scripts/export_public.py --out state/trading-public.json >> state/logs/export_public.log 2>&1
```
## Syncing to the app
The dashboard reads the file at the path in `TRADING_DATA_PATH`
(default: its bundled `data/trading-public.json`). Point the app at the exported
file, or copy the export into place after each run:
```bash
# option A — copy into the app's data dir (rebuild/redeploy picks it up)
cp state/trading-public.json /path/to/sites/apps/trading/data/trading-public.json
# option B — write to a shared volume the running app reads via TRADING_DATA_PATH
cp state/trading-public.json /srv/trading-data/trading-public.json
# app env: TRADING_DATA_PATH=/srv/trading-data/trading-public.json
```
The app `revalidate`s hourly, so a fresh file is served within the hour with no
redeploy. (Hosting/transport is handled separately — this script only writes a
local file.)