diff --git a/scripts/watch.py b/scripts/watch.py index 300c67c..3390851 100644 --- a/scripts/watch.py +++ b/scripts/watch.py @@ -147,6 +147,20 @@ def account(): print(f" ⚠ 取不到现价: {', '.join(v['price_missing'][:6])}") +def _left_today(ins: dict, used: int): + """本日剩余额度 = 当日配额 − 今日已投放。用的是执行器那两个纯函数, 口径一致。""" + from app.core import exec_timing as et, tradedays as td + try: + remaining = max(0, int(ins.get("qty") or 0) - int(ins.get("exec_qty") or 0)) + dl = (ins.get("progress") or {}).get("deadline") + left_days = td.trade_days_left(dl, None) if dl else 1 + quota = et.daily_quota(remaining, left_days, + allow_odd_tail=(ins.get("action") == "EXIT")) + return max(0, quota - int(used)) + except Exception: + return "?" + + def instructions(): """今日一栏必须写成「投/余/废」三个数, 不能只印一个剩余量。 @@ -179,8 +193,11 @@ def instructions(): except Exception: used = sum(int(c.get("qty") or 0) for c in kids) void = sum(int(c.get("qty") or 0) for c in kids) - used - left = d.get("qty_hint") - left = "—" if left is None else str(left) + # 「余」必须**现算**, 不能读 last_decision 里的 qty_hint —— 那是执行器上一跳 + # 存下来的快照, 而投/废是此刻现算的。两者取自不同时刻, 会拼出自相矛盾的一行: + # 2026-08-03 实机 002518.SZ 显示 `0/0/200` —— 废了 200 却还说余 0, 因为执行器 + # 那一跳时第二张分片还挂着(算已投), 等 watch 来看时它刚到期。三个数必须同源。 + left = _left_today(r, used) q = f"{used}/{left}/{void}" print(" " + _pad(r["ts_code"], 11) + _pad("买" if r["side"] == "buy" else "卖", 5)