diff --git a/DEVLOG.md b/DEVLOG.md index 14c12b8..c5330cb 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -2127,3 +2127,13 @@ QMT在线、对账无差异。午休任务按原时段跳过,不制造交易 用户确认独立候选区,人工发起。功能03e569e于10:51:01统一重建155四服务,镜像0f298f6d5b997c603b7d57a50223267367e1f7b1112d630b8e6af187e7f711d2,Python指纹83c49a380165。页面ccf194b随后挂载生效,原始记录二级折叠。 48批候选镜像禁网回归、最终三页面守卫和真实登录浏览器核验通过。19参数、23持仓、322批次完全不变,108指令未增减,三条只更新正常等待或拒绝时刻。健康正常、QMT在线、对账diffs=[]。高股息读取0.433秒,不写消费记录;匿名接口401。当前175研究记录、零家可评估,原自主扫描不切换。无真实合格公司,人工准备、采纳与成交未作生产代验。备份、回退及未判收边界见四仓同日交接。 + +## 2026-10-26 · 钧达股份成本口径与父指令重复下发修复 + +在 155 模拟仓只读核对钧达股份 002865.SZ 的持仓、批次、父子指令、18 笔成交回报与容器日志。发现 10 月 23 日追踪止盈父指令目标卖出 600 股,却实际发出两笔各 600 股的子委托。首单于 09:34:58 终态成交,09:35 执行任务先于回放任务运行,把父指令尚未更新的累计成交误当剩余额度,导致重复下发。QMT 确实还持有 100 股。5.053 元能够由累计买入 42,663.04 元、累计卖出 42,157.74 元复算,是摊薄成本,不是买入均价。今天用户已下达清仓 100 股命令,13:40 仍等待价格条件。 + +修改 `executor.py` 增加跨日父指令总量检查,综合父指令入账量、出口累计成交和未终态未成交量限制每次下发,出口读取失败不发新单。页面明确“摊薄成本”与“综合盈亏”的含义。补齐 `test_wiring.py` 出口仓储内存桩,新增并登记第 45 批 16 例回归。修正第 44 批周一因样本生成与核验使用不同日历而失败的测试准备顺序。详细成本计算、交易时间线和当前选股、建仓、退出、策略参数记入 `docs/钧达股份成本与重复下发排查_2026-10-26.md`。 + +开发机在独立 Python 3.12 环境通过 `python scripts/run_tests.py`,配置隔离、禁止联网,49 批、1154 例输出 ALL SUITES PASS。相同新增测试在旧代码上有 13 例失败,修复后 16 例通过,包含真实追踪止盈执行路径。三道页面守卫与差异格式检查通过。 + +调查证据为真机见过。修复运行态与页面视觉验收为未判收。本机会话无可连接浏览器;服务器断网容器回归、重建镜像与四服务 force-recreate 待本次部署确认,没有重启容器、改运行参数、写数据库或操作 188。保留真实持仓与成交,待已有清仓命令成交后正常移出当前持仓,不删账掩盖实际持股。尚欠服务器回归、部署判收与真实执行场景观察,不能把本机通过称作上线恢复完成。 diff --git a/app/services/executor.py b/app/services/executor.py index 162419d..cae9142 100644 --- a/app/services/executor.py +++ b/app/services/executor.py @@ -197,7 +197,10 @@ def run_tick(*, now=None, dry_run: bool = False) -> dict: fresh = pms_repo.get_instruction(ins['instruction_id']) if not fresh or fresh.get('status') not in LIVE: continue + ins = fresh prog = dict(fresh.get('progress') or {}) + children = list(prog.get('children') or []) + remaining = int(ins['qty']) - int(ins.get('exec_qty') or 0) if pms_repo.instruction_buy_stop(ins['instruction_id']) or prog.get('stopped_by_exit'): if not dry_run: cancelled = cancel_instruction(ins['instruction_id'], reason='清仓已终止原买入安排', arbiter='system') @@ -211,6 +214,17 @@ def run_tick(*, now=None, dry_run: bool = False) -> dict: pms_repo.update_instruction(ins['instruction_id'], progress=prog) out['waited'].append({'instruction_id': ins['instruction_id'], 'code': code, 'reason': blocked}) continue + # 回放与下发是两个任务。出口已成交时,exec_qty 可能还没更新, + # 不能把「已终态、不在途」误当成「父指令还有额度」。 + available = _parent_available(ins, children) + if available <= 0: + reason = '父指令额度已由成交或在途委托占用,等待回报入账或撤单确认' + prog['last_decision'] = {'at': now.strftime('%H:%M'), 'action': 'WAIT', 'reason': reason} + if not dry_run: + pms_repo.update_instruction(ins['instruction_id'], progress=prog) + out['waited'].append({'instruction_id': ins['instruction_id'], 'code': code, + 'action': 'WAIT', 'reason': reason}) + continue day = market.day_snapshot(code) pos = _pos_of(view, code) quota = et.daily_quota(remaining, tdays_left, lot=lot_of(code), @@ -224,7 +238,8 @@ def run_tick(*, now=None, dry_run: bool = False) -> dict: # 「当日配额已出完」, 当天不再补单, 连 14:45 强制兜底也被挡在这道判断前面, # 要等次日配额清零才继续。这正是 2026-08-19 紧急清仓剩三支拖到次日早盘的根因。 # 只按在途量扣: 可再投放 = 剩余 − 在途, 永不重复扣, 紧急清仓当天会持续补单, - # 直到卖完或撞上 T+1 可卖为零 (可卖量那道闸在下面单独兜, 不会超卖/重复下单)。 + # 父指令总量另由 _parent_available 限制。可卖量只能保护账户持仓, + # 不能保护某次只卖一半的指令,更不能假定回放已及时更新 exec_qty。 is_urgent = bool(prog.get("urgent")) fired_today = (_inflight_today(children, ymd_today) if (is_urgent or is_last) else _consumed_today(children, ymd_today)) @@ -273,7 +288,7 @@ def run_tick(*, now=None, dry_run: bool = False) -> dict: "action": d["action"], "reason": d["reason"]}) continue - slice_list = et.slice_qty(min(d["qty_hint"], remaining), slices) + slice_list = et.slice_qty(min(d["qty_hint"], remaining, available), slices) qty = slice_list[0] if slice_list else 0 if side == "sell": qty = min(qty, int(pos.get("avail_qty") or 0)) @@ -494,6 +509,49 @@ def _child_id(instruction_id: str, n: int) -> str: return f"{instruction_id}_D{n:02d}" +def _parent_available(ins: dict, children: list) -> int: + """父指令总量减去已成交量与仍可成交量,不把通道回报当作账本入账。 + + 已成交取父指令与全部出口子单累计成交的较大值,兼容任一方暂时领先。 + 在途子单再预留尚未成交的数量;终态只释放未成交部分。必须跨日查询, + 也必须包含已入出口但没写回 progress 的子单。查询失败由调用方报错,禁止下发。 + """ + target = int(ins['qty']) + booked = int(ins.get('exec_qty') or 0) + if dispatcher.mode() != dispatcher.MODE_WS: + return max(0, target - booked) + filled, pending = 0, 0 + seen = set() + for order in qmt_repo.orders_for_parent(ins['instruction_id']): + ref = order['instruction_id'] + if ref in seen: + raise ValueError('同一父指令的出口子单重复,暂停下发') + seen.add(ref) + qty = int(order['qty']) + done = int(order.get('cum_qty') or 0) + if qty <= 0 or done < 0 or done > qty: + raise ValueError('出口委托数量异常,暂停下发') + status = str(order.get('status') or '').upper() + # FILLED 却缺累计成交数属于不完整回报,不能据此释放整笔额度。 + if status == qmt_repo.OS_FILLED: + done = qty + filled += done + if status not in qmt_repo.FINAL: + pending += qty - done + for child in children: + ref = child.get('ref') + if ref in seen: + continue + # 查不到出口的既有下发,或切换模式前的人工委托,保守预留全部数量。 + qty = int(child['qty']) + if qty <= 0: + raise ValueError('既有子单数量异常,暂停下发') + pending += qty + if ref: + seen.add(ref) + return max(0, target - max(booked, filled) - pending) + + def _consumed_today(children: list, ymd_today: int) -> int: """今日已投放量 —— **到期/被撤/被拒且一股没成的分片不算数**。 diff --git a/app/web/static/index.html b/app/web/static/index.html index 0bc1e43..f9b63f1 100644 --- a/app/web/static/index.html +++ b/app/web/static/index.html @@ -991,7 +991,7 @@ body.dock-r:not(.r-fold) .side-r .strip{display:none;}
持仓市值
{{ money(ov.portfolio_mv) }}
仓位上限 {{ pct(ov.portfolio_cap) }}
{{ pct(ov.portfolio_pct) }}
-
浮动盈亏
+
持仓综合盈亏?
{{ money(ov.float_pnl) }} {{ ov.float_pnl_pct==null?'':pct(ov.float_pnl_pct) }}
持仓只数上限 {{ ov.max_names }}
{{ ov.names_count }}
@@ -1010,7 +1010,7 @@ body.dock-r:not(.r-fold) .side-r .strip{display:none;}

持仓 · {{ heldPositions.length }} 只

占比按总操作规模计算。 - ?
+ ?