From dfdf539d7d0587f2aa4f31ae4153d98823ea5fa0 Mon Sep 17 00:00:00 2001 From: baobao Date: Mon, 16 Nov 2026 12:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=8C=81=E4=BB=93=E9=80=80?= =?UTF-8?q?=E5=87=BA=E8=AF=B4=E6=98=8E=E4=B8=8E=E5=BD=93=E5=89=8D=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E4=BE=9D=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/exit_presentation.py | 47 ++ app/services/risk_exit.py | 25 +- app/web/main.py | 11 +- app/web/static/index.html | 35 +- docs/退出等待展示与失效比较准备_2026-11-16.md | 37 + .../exit_invalidation_20261116/PROTOCOL.md | 42 ++ research/exit_invalidation_20261116/README.md | 26 + .../audit_coverage.py | 63 ++ .../exit_invalidation_20261116/coverage.json | 145 ++++ .../holding_snapshot.json | 646 ++++++++++++++++++ scripts/test_batch49_units.py | 48 ++ scripts/test_risk_exit.py | 90 +++ 12 files changed, 1194 insertions(+), 21 deletions(-) create mode 100644 app/core/exit_presentation.py create mode 100644 docs/退出等待展示与失效比较准备_2026-11-16.md create mode 100644 research/exit_invalidation_20261116/PROTOCOL.md create mode 100644 research/exit_invalidation_20261116/README.md create mode 100644 research/exit_invalidation_20261116/audit_coverage.py create mode 100644 research/exit_invalidation_20261116/coverage.json create mode 100644 research/exit_invalidation_20261116/holding_snapshot.json diff --git a/app/core/exit_presentation.py b/app/core/exit_presentation.py new file mode 100644 index 0000000..3a1a676 --- /dev/null +++ b/app/core/exit_presentation.py @@ -0,0 +1,47 @@ +"""退出纪律的只读业务说明;不产生信号、不改变状态或交易条件。""" +from app.core import risk_exit as rules, timing_fusion_contract as fusion + +LABELS = {'STOP_BUY': '只卖不买', 'EXIT_PENDING': '等待清仓', + 'EXITING': '清仓中', 'MANUAL': '退出待处理', 'CLOSED': '退出待核实'} +GROUP_NAMES = {'qrs': '量化择时', 'main_fund': '主力资金', 'v3f': '资金异动'} + + +def view(state, current=None, *, fusion_enabled=False, now=None): + phase = state.get('phase') + if phase not in LABELS: + return None + result = {'status': LABELS[phase], 'reason': state.get('reason') or '退出纪律已生效,停止新增买入'} + first = next(iter(state.get('events') or []), {}) + at = rules.stamp(first.get('at')) + if at: + result.update(first_at=at.strftime('%Y-%m-%d %H:%M:%S'), first_reason=first.get('reason') or '首次清仓信号已确认') + if phase != 'STOP_BUY': + result['next'] = { + 'EXIT_PENDING': '已有清仓安排,等待撤单与持仓核对;可卖部分按原安排处理。', + 'EXITING': '按已有清仓安排继续处理;未成交和当日不可卖部分保留跟踪。', + 'MANUAL': '自动退出暂不能完成,请核对上方原因并处理已有清仓安排。', + 'CLOSED': '退出记录已结束但仍有持仓,请先核对成交与持仓归属。', + }[phase] + return result + result['next'] = '继续暂停新增买入,正常卖出照常;第二次独立清仓信号或正式评级下调触发退出。原有止盈止损、目标价与用户清仓命令仍按各自规则处理。' + if fusion_enabled: + result['next'] += ' 合成择时的再次确认须有至少两组新的独立看空证据,重复读取不计数。' + event = fusion.valid(current, now) + if not event: + result['current'] = '当前没有有效择时结论,不能据此确认退出或恢复买入。' + return result + parts = [GROUP_NAMES[name] + ('暂不可用' if group['state'] == 'UNKNOWN' else + {-1: '看空', 0: '中性', 1: '看多'}[group['direction']]) + for name, group in event['groups'].items()] + if event['action'] == 'SELL': + conclusion = ('看空依据尚不足以构成第二次独立信号' if fusion.duplicate(state.get('events') or [], event) + else '已收到新的独立看空结论,等待退出纪律处理') + elif event['action'] == 'BUY': + conclusion = '当前择时看多,恢复买入仍待既定条件核验' + else: + conclusion = '尚未形成有效看空或看多结论' + result['current'] = '、'.join(parts) + ';' + conclusion + '。' + result['current_at'] = rules.stamp(event['verified_at']).strftime('%Y-%m-%d %H:%M:%S') + else: + result['current'] = ('当前择时' + ('看空,等待独立性核验。' if current.get('action') == 'SELL' else '看多,恢复买入仍待既定条件核验。')) if current else '当前没有有效择时结论,不能据此确认退出或恢复买入。' + return result diff --git a/app/services/risk_exit.py b/app/services/risk_exit.py index 1fddb6a..f341704 100644 --- a/app/services/risk_exit.py +++ b/app/services/risk_exit.py @@ -37,20 +37,35 @@ def buy_blocker(code): return None -def decorate_positions(rows): +def decorate_positions(rows, *, now=None): """只读展示退出纪律,非方案持仓也不能把停买误写成等待补仓。""" if not supported(): return - labels = {'STOP_BUY': '只卖不买', 'EXIT_PENDING': '等待清仓', - 'EXITING': '清仓中', 'MANUAL': '退出待处理', 'CLOSED': '退出待核实'} + from app.core import exit_presentation + from app.services import timing_state, timing_fusion + now = now or datetime.now() for row in rows: if int(row.get('total_qty') or 0) <= 0 or not _code_ok(row.get('ts_code')): continue try: state, _ = rotation_repo.get(_key(row['ts_code'])) - if state and (enabled() or state.get('user_stop')) and state.get('phase') in labels: - row['exit_status_text'] = labels[state['phase']] + if state and (enabled() or state.get('user_stop')) and state.get('phase') in exit_presentation.LABELS: + row['exit_status_text'] = exit_presentation.LABELS[state['phase']] row['exit_status_reason'] = state.get('reason') or '退出纪律已生效,停止新增买入' + # 只读本地已保存的择时,不请求上游、不推进退出状态。 + current = None + fusion_on = False + timing_failed = False + if state['phase'] == 'STOP_BUY': + try: + fusion_on = timing_fusion.enabled() + current = timing_state.latest(row['ts_code'], now) + except Exception: + timing_failed = True + detail = exit_presentation.view(state, current, fusion_enabled=fusion_on, now=now) + if timing_failed: + detail['current'] = '当前择时读取失败,维持原停买安排;请刷新核对。' + row['exit_detail'] = detail except Exception: row['exit_status_text'] = '退出状态待核实' row['exit_status_reason'] = '暂时无法读取退出纪律,请稍后刷新' diff --git a/app/web/main.py b/app/web/main.py index 679ee62..8b7c647 100644 --- a/app/web/main.py +++ b/app/web/main.py @@ -409,12 +409,15 @@ def api_positions(): logic_state_service.decorate_positions(v["positions"]) except Exception as e: # noqa: BLE001 logger.warning("[持仓] 入场论点与逻辑状态两栏取不到: %s", e) - # 技术面立场 (2026-09-11): 每行挂 tech(看多/看空/中性/无读数),只是显示,取不到不塌。 + # 展示与个股详情共用有效日线,不让较旧扫描映射覆盖当前结论。 + display_tech = {} try: from app.services import tech_service - tech_service.attach(v["positions"]) + display_tech = tech_service.read_states_for([r['ts_code'] for r in v['positions']]) except Exception as e: # noqa: BLE001 logger.warning("[持仓] 技术面立场挂不上: %s", e) + for r in v['positions']: + r['tech'] = display_tech.get(r['ts_code']) # 综合分析三票 (2026-09-15): 每行挂 dims = {fund, tech, timing, fund_fact, tech_phase, nightly}, # 供持仓表「综合分析」列三枚维度标签用。与扫描同一套装配 (consensus_service.decorate_positions: # 基本面从逻辑状态映射的买方评析算, 技术面用早上映射, 择时用昨夜定性); 只是显示, 取不到不塌。 @@ -422,11 +425,11 @@ def api_positions(): from app.services import consensus_service _lmap = logic_state_service.state_map() or {} _crs = {code: (st or {}).get("company_review") for code, st in _lmap.items()} - consensus_service.decorate_positions(v["positions"], company_reviews=_crs) + consensus_service.decorate_positions(v["positions"], company_reviews=_crs, tech_states=display_tech) for r in v["positions"]: b = r.pop("consensus_blocks", None) or {} fund, tech, tm = b.get("fund") or {}, b.get("tech") or {}, b.get("timing") or {} - # 技术面优先用 tech_service.attach 挂的那份 (同一映射, 已带相位与理由) + # 与详情使用同一有效日线结果;读取失败不能退回旧扫描映射。 t = r.get("tech") or tech r["dims"] = {"fund": fund.get("stance"), "fund_fact": fund.get("fact") or fund.get("no_read_why"), "tech": t.get("stance"), "tech_phase": t.get("phase"), diff --git a/app/web/static/index.html b/app/web/static/index.html index 23cad9c..509b852 100644 --- a/app/web/static/index.html +++ b/app/web/static/index.html @@ -2543,7 +2543,6 @@ body.dock-r:not(.r-fold) .side-r .strip{display:none;}
判断依据读取失败:{{ techFeedErr }}重试
该股票暂无判断依据。
-