"""build_full10y_list.py -- [2026-10-24] the user: download the buy/sell flow for the WHOLE 10 years after the tests. Stock-days =
each day's trade-bot picks (v3 top 30) + the Star bot's 9:30 picks (v1 top 50), pm_history 2016-11-25 .. 2024-09-30, only stocks
with bars10y minute bars that day, minus what open_window/flow_tick already has. -> full10y_list.json [[day, sym], ...]"""
import gzip, json
from pathlib import Path
from build_10y_top30 import v3
from star_lists import v1
OW = Path("/var/www/screener/trade/reports/open_window"); HERE = Path(__file__).resolve().parent
lst = []
for f in sorted((OW / "pm_history").glob("20*.json.gz")):
    day = f.name[:10]
    if day > "2024-09-30":
        break
    bf = OW / "bars10y" / day[:4] / f"{day}.json.gz"
    if not bf.exists():
        continue
    have = set(json.load(gzip.open(bf, "rt"))["bars"])
    rows = [r for r in json.load(gzip.open(f, "rt"))["rows"] if r["s"] in have and r.get("prev_close")]
    pick = {r["s"] for r in sorted(rows, key=v3, reverse=True)[:30]} | {r["s"] for r in sorted(rows, key=v1, reverse=True)[:50]}
    lst += [[day, s] for s in sorted(pick) if not (OW / "flow_tick" / day / f"{s}.json").exists()]
    print(day, len(lst), flush=True)
json.dump(lst, open(HERE / "full10y_list.json", "w")); print(f"{len(lst)} stock-days; FULL10Y_LIST_DONE")
