diff --git a/DEVLOG.md b/DEVLOG.md index 46fd872..ce086a2 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -3053,3 +3053,7 @@ a44c994于10:53:29仅发布155的web,镜像pms:proposal-copy-a44c994。开发 ## 2026年11月12日12:00 提议与执行面板按交易员视角复核 结合11:10只读样本和代码确认:提议扫描与研究详情的技术取数及有效期处理不同;择时等待、无有效事件和分析不可用缺少完整区分;人工采纳实际批准条件计划,页面却没有清楚交代后续限制。纯合议检查证明补入技术看多可能改变原人工确认去向,不能只替换标签。已提出统一当前依据、重新核对建议、主界面表达实际操作结果、历史按需追溯的方案,保留已有规则与授权边界。仅分析及文档,未改业务代码、未部署、未读取新的真机快照。详见[审视记录](docs/交易员视角下的提议与执行面板审视_2026-11-12.md)。 + +## 2026年11月12日12:21 提议当前分析与确认含义修复 + +按用户指令统一普通候选、关注和详情的有效技术依据,待确认提议附当前分析,实质变化交正常扫描重评并在确认接口拦旧依据。页面去除“当时未取得”“待信号”,保留真实中性,分别解释买入依据不足与多空分歧;确认操作说明条件计划含义,执行等待原因按实际情况拆开。读取故障不退旧建仓路径,原始历史与已采纳计划不重写。开发机85组全量、17专项、页面三护栏和1440/390隔离浏览器通过;候选断网和发布结果见[发布接续](docs/提议当前分析与交易员表达修复_2026-11-12.md)。 diff --git a/app/core/plan_revision.py b/app/core/plan_revision.py index ad4ee14..976ecde 100644 --- a/app/core/plan_revision.py +++ b/app/core/plan_revision.py @@ -60,7 +60,9 @@ def needs_new_judgement(hard, previous): def confirmation_revision(qty, hard, verdict): """确认针对可见的建议内容;后台检查时间、名次及无关版本不让确认失效。""" + from app.core.proposal_analysis import decision_basis return fingerprint({'qty': qty, 'basis': hard.get('plan_basis'), + 'analysis': decision_basis(hard), 'advice': hard.get('advice'), 'reason': hard.get('reason'), 'verdict': verdict.get('verdict'), 'judge_reason': verdict.get('reason'), 'confidence': verdict.get('confidence')}) diff --git a/app/core/proposal_analysis.py b/app/core/proposal_analysis.py new file mode 100644 index 0000000..e4eab9e --- /dev/null +++ b/app/core/proposal_analysis.py @@ -0,0 +1,32 @@ +"""提议当前分析的业务表达与实质变化判断,不改变合议规则。""" + + +def timing_view(timing): + t = timing or {} + stance = t.get('stance') + event = t.get('event') or t.get('intraday_event') or {} + if stance in ('看多', '看空', '中性'): + return {'label': stance, 'reason': event.get('reason') or { + '看多': '当前择时支持买入,仍需满足限价和资金条件', + '看空': '当前择时不支持买入', '中性': '暂无明确多空倾向'}[stance]} + signs = {g.get('direction') for g in (event.get('groups') or {}).values() + if g.get('state') == 'VALID'} + if 1 in signs and -1 in signs: + return {'label': '多空分歧', 'reason': '有效看多与看空证据并存,当前不支持买入'} + return {'label': '买入依据不足', 'reason': '有效择时证据尚不足以支持买入'} + + +def decision_basis(hard): + """只比较影响建议的判断,不因证据刷新时间或事件标识变化反复打断确认。""" + h = hard or {} + con, tech, timing = h.get('consensus') or {}, h.get('tech') or {}, h.get('timing') or {} + votes = con.get('votes') or {} + return {'fund': (h.get('fund_stance') or {}).get('stance') or votes.get('fund'), + 'tech': {k: tech.get(k) for k in ('stance', 'phase', 'data_date', 'sar_side')}, + 'timing': timing.get('stance') or votes.get('timing'), + 'timing_label': timing_view(timing)['label'], + 'consensus': {k: con.get(k) for k in ('direction', 'strength', 'route', 'route_reason')}} + + +def changed(old, current): + return decision_basis(old) != decision_basis(current) diff --git a/app/services/consensus_service.py b/app/services/consensus_service.py index b695aa3..004bb07 100644 --- a/app/services/consensus_service.py +++ b/app/services/consensus_service.py @@ -110,7 +110,8 @@ def hard_keys(blocks) -> dict: "tech": tech, "tech_text": tech.get("reason") or tech.get("no_read_why"), "timing": {"stance": tm["stance"], "nightly": tm.get("nightly"), - "flip_at": tm.get("intraday_flip_at"), "event": tm.get('intraday_event')}, + "flip_at": tm.get("intraday_flip_at"), "event": tm.get('intraday_event'), + "fresh": tm.get('fresh'), "no_read_why": tm.get('no_read_why')}, "consensus": {"direction": con["direction"], "votes": con["votes"], "strength": con.get("strength"), "reason": con.get("reason"), "route": con.get("route"), "route_reason": con.get("route_reason")}, @@ -127,6 +128,33 @@ def state_map(): return {} +def decorate_proposals(rows, now=None): + """只读当前分析,旧提议审计保持原样;判断改变时关闭旧确认入口,交自然扫描更新。""" + from datetime import datetime + from app.core import proposal_analysis + from app.services import proposal_service + pairs = [] + for row in rows: + h = row.get('hard_numbers') or {} + if (row.get('status') == 'WAIT_USER' and row.get('action') == 'OPEN' + and h.get('kind') not in ('strategy', 'daily_review') and h.get('consensus')): + candidate = dict(h.get('plan_basis') or h, ts_code=row['ts_code']) + pairs.append((row, candidate)) + if not pairs: + return + proposal_service._attach_consensus([c for _, c in pairs], now=now or datetime.now()) + for row, candidate in pairs: + analysis = candidate.get('consensus_hard') + row['analysis'] = analysis or {} + if not analysis: + row.update(accept_ready=False, prepare_reason='分析暂不可用,当前建议不能确认') + else: + row['analysis_changed'] = proposal_analysis.changed(row['hard_numbers'], analysis) + row['timing_view'] = proposal_analysis.timing_view(analysis.get('timing')) + if row['analysis_changed']: + row.update(accept_ready=False, prepare_reason='当前分析已变化,正在重新评估建仓建议') + + def holding_buy_consensus(code, *, now=None): """自动网格新增买入也使用持仓的现行三源意见,不由吸筹标签单独开关。""" from app.services import logic_state_service diff --git a/app/services/execution_basis.py b/app/services/execution_basis.py index 9837694..bd7f59a 100644 --- a/app/services/execution_basis.py +++ b/app/services/execution_basis.py @@ -22,8 +22,15 @@ def cache_reason(progress, now=None): if timing_fusion.enabled(): basis = cache.get('basis') or {} state = timing_state.latest((basis.get('timing_fusion') or {}).get('ts_code', ''), now) - if not state or state['action'] != 'BUY' or state['key'] != basis.get('timing_version'): - return '合成择时未转多或执行依据版本已变化,等待刷新' + if not state: + return '有效择时证据不足,暂不买入;条件满足后按限价执行' + if state['action'] != 'BUY': + from app.core.proposal_analysis import timing_view + if state['action'] == 'SELL': + return '当前择时看空,暂停买入' + return timing_view({'event': state})['reason'] + ';条件满足后按限价执行' + if state['key'] != basis.get('timing_version'): + return '择时已转多,正在核对最新买入条件,核对完成前不下单' return policy.basis_reason(cache.get('basis'), now, max_source_days=max(0, param_store.get_int('PMS_EXEC_BASIS_SOURCE_MAX_DAYS', 7))) diff --git a/app/services/plan_recheck.py b/app/services/plan_recheck.py index 0de3b42..6ee7e4f 100644 --- a/app/services/plan_recheck.py +++ b/app/services/plan_recheck.py @@ -44,6 +44,14 @@ def current_basis(hard, code, proposal_id=None, *, record=True): changed = {'research_changed': result == 'material', 'params_changed': hard.get('scan_params_hash') != ph, 'portfolio_changed': hard.get('portfolio_context_hash') != context} + if hard.get('consensus'): + from app.core import proposal_analysis + # 与自然扫描使用同一分析路径;仅读已有资料,不发模型请求、不落指令。 + ps._attach_consensus([current], now=datetime.now()) + analysis = current.get('consensus_hard') + if not analysis: + return {'ok': False, 'error': '分析暂不可用,当前建议不能确认', 'stage': 'source'} + changed['analysis_changed'] = proposal_analysis.changed(hard, analysis) material = any(changed.values()) return {'ok': not material, 'material': material, **changed, 'error': '建议依据已变化,后台正在更新' if material else None, @@ -161,8 +169,8 @@ def before_accept(p, expected_revision): return _failed_recheck(p, {'rejected': [{'by': 'qualification', 'why': check['error']}]}) if not check.get('view'): return _pending_response(p, check.get('error') or '建议资料暂不可用', check.get('stage', 'source')) - if check.get('research_changed') or check.get('params_changed') or hard.get('last_accept_check'): - return _pending_response(p, '建议依据已变化,后台更新完成后可确认', 'changed') + if check.get('research_changed') or check.get('params_changed') or check.get('analysis_changed') or hard.get('last_accept_check'): + return _pending_response(p, '当前分析已变化,建仓建议更新后再确认', 'changed') reason = fast_checks(p, check) if reason: return _pending_response(p, reason, 'execution') @@ -227,7 +235,7 @@ def refresh_one(p, *, now=None, deadline=None): if not check.get('view'): return _pending_response(p, check.get('error') or '建议资料暂不可用', check.get('stage', 'source')) if ((hard.get('preparation') or {}).get('status') == 'ready' and not hard.get('last_accept_check') - and not check.get('research_changed') and not check.get('params_changed')): + and not check.get('research_changed') and not check.get('params_changed') and not check.get('analysis_changed')): # 其他持仓/现金读数变化不等于本建议失效。原数量仍满足当前闸门就保留, # 否则报价写进新扫描的说明会让相同500股每分钟变成另一份待确认内容。 if check.get('ok') or not fast_checks(p, check): @@ -237,7 +245,7 @@ def refresh_one(p, *, now=None, deadline=None): and hard.get('consumption_id') and hard.get('proposal_revision') and hard.get('prepared_judgement') and hard.get('plan_basis') is not None and not hard.get('last_accept_check') and not check.get('research_changed') - and not check.get('params_changed') and not fast_checks(p, check)): + and not check.get('params_changed') and not check.get('analysis_changed') and not fast_checks(p, check)): restored = ready_hard(hard, _judgement(p), now) candidate = {'qty': p['qty'], 'hard_numbers': restored} if pms_repo.publish_prepared_proposal(p, candidate, _judgement(p)): diff --git a/app/services/proposal_service.py b/app/services/proposal_service.py index b9e1b68..e9c72c5 100644 --- a/app/services/proposal_service.py +++ b/app/services/proposal_service.py @@ -577,7 +577,7 @@ def _attach_consensus(cands, out=None, now=None) -> None: consensus_blocks —— 四块意见 (fund / tech / timing / consensus), scan_open 定档时取 fund/tech 喂 advise_v2; consensus_hard —— 提议硬数字六键 (方案附录丁), 进评审账本与提议卡, 不进送研判名单。 批量取一次昨夜定性与技术面映射; 盘中转多留痕从候选自带的 sig_buy 取时刻。任何一步失败都不抛 —— - 装不上就当这只票没有合议 (scan_open 里 con 为 None 自然退回旧路), 合议是加不改。 + 取数或计算失败则保留观察,不因技术故障退回旧建仓路径。 盘中确认 (2026-09-14 盘中确认包): 装配完四块后, 若总闸开着且传了 now, 对收口等待/开口向上的 候选跑一遍 intraday_confirm —— 收口突破改立场重新合议, 开口未确认/时段外把路由改观察带 wait_confirm。 @@ -592,13 +592,14 @@ def _attach_consensus(cands, out=None, now=None) -> None: try: codes = [c.get("ts_code") for c in cands if c.get("ts_code")] nightly = consensus_service.nightly_map(codes) - tech_states = consensus_service.state_map() - missing_user = [r['ts_code'] for r in cands if r.get('user_candidate') and r['ts_code'] not in tech_states] - if missing_user: - from app.services import tech_service - tech_states = dict(tech_states, **tech_service.read_states_for(missing_user)) + # 所有候选使用相同的已有日线与有效期;盘前映射不能遗漏盘中新入榜的普通候选。 + from app.services import tech_service + tech_states = tech_service.read_states_for(codes) except Exception as e: # noqa: BLE001 logger.warning("[合议] 批量取数失败, 本轮候选不装配合议: %s", e) + for c in cands: + c['consensus'] = {'direction': None, 'route': '观察', + 'route_reason': '分析暂不可用,暂不建仓'} return icfg = _intraday_cfg() if now is not None else None icache: dict = {} @@ -628,6 +629,8 @@ def _attach_consensus(cands, out=None, now=None) -> None: seen.append(rec) except Exception as e: # noqa: BLE001 logger.warning("[合议] 装配失败 %s (本票按无合议): %s", code, e) + c['consensus'] = {'direction': None, 'route': '观察', + 'route_reason': '分析暂不可用,暂不建仓'} # 候选一只都不剩时, 这一栏要说清是被哪几道筛掉的。键名是代码里的, 翻成人话再显示。 diff --git a/app/services/tech_service.py b/app/services/tech_service.py index 7ed2559..be37448 100644 --- a/app/services/tech_service.py +++ b/app/services/tech_service.py @@ -410,18 +410,12 @@ def research_feed(ts_code: str) -> dict: return {"tech": None, "error": "代码认不出"} if not enabled(): return {"tech": None, "note": "PMS_TECH_ENABLED 关着"} - p = _params() try: - dd = tech_repo.latest_date() - since = tradedays.ymd(tradedays.prev_trade_day(dd, tech_rules.CHOPPY_WINDOW + 5)) if dd else 0 - rows = tech_repo.history(code, since=since, limit=tech_rules.CHOPPY_WINDOW + 5) + tech = read_states_for([code]).get(code) except Exception as e: # noqa: BLE001 - return {"tech": None, "error": f"{type(e).__name__}: {e}"} - if not rows: - return {"tech": None, "note": "这只票没有技术面读数"} - st = tech_rules.synthesize(rows, params=p["rules"]) - return {"tech": {**_compact(st), "latest": _row_view(rows[-1]), - "flips": tech_rules.count_sar_flips(rows), "bars": len(rows)}} + logger.warning('技术分析读取失败 %s: %s', code, type(e).__name__) + return {"tech": None, "error": "技术分析暂不可用"} + return {"tech": tech, "note": None if tech else "缺少有效日线,暂不能确认技术方向"} def status() -> dict: @@ -447,8 +441,9 @@ def status() -> dict: def read_states_for(codes): - """盘中新加入的股票读取已有日线,按原规则合成立场,不重算行情或改写整份映射。""" - codes = list(dict.fromkeys(codes)) + """扫描与详情共同读取已有日线;沪深范围、日期与时效标准一致,不调用模型。""" + codes = list(dict.fromkeys(normalize_code(c) for c in codes)) + codes = [c for c in codes if c and c.endswith(('.SH', '.SZ'))] if not codes or not enabled(): return {} p = _params() @@ -457,5 +452,7 @@ def read_states_for(codes): return {} since = tradedays.ymd(tradedays.prev_trade_day(dd, tech_rules.CHOPPY_WINDOW + 5)) history = tech_repo.history_multi(codes, since=since) - return {code: _compact(tech_rules.synthesize(rows, params=p['rules'])) - for code, rows in history.items() if rows and int(rows[-1].get('data_date') or 0) == dd} + return {code: {**_compact(tech_rules.synthesize(rows, params=p['rules'])), + 'latest': _row_view(rows[-1]), 'flips': tech_rules.count_sar_flips(rows), 'bars': len(rows)} + for code, rows in history.items() + if code in codes and rows and int(rows[-1].get('data_date') or 0) == dd} diff --git a/app/web/main.py b/app/web/main.py index 92ac7ed..b9b9a9d 100644 --- a/app/web/main.py +++ b/app/web/main.py @@ -518,6 +518,8 @@ def api_proposals(status: str = Query("WAIT_USER"), limit: int = 100, preparation = h.get('preparation') or {} row['accept_ready'] = preparation.get('status') == 'ready' and bool(h.get('consumption_id')) row['prepare_reason'] = preparation.get('reason') or '建议正在准备,完成后可采纳' + from app.services import consensus_service + consensus_service.decorate_proposals(rows) return rows return ok(_list) @@ -997,15 +999,17 @@ def api_research(ts_code: str): # 合议也用现读的这份 (2026-09-15): 早上映射只覆盖相关票, 不在映射里的票合议会按技术面无读数算, # 而抽屉又显示现读的立场, 两处对不上 (实见 300750: 技术面看空却判「只有基本面一路看多」)。 # 扫描那条路仍用映射, 这里只管显示自洽。 - if tfeed.get("tech"): - tech_states = {**(tech_states or {}), code: tfeed["tech"]} + # 详情与提议采用同一有效期;不能在现读已过期时退回旧映射。 + tech_states = {code: tfeed['tech']} if tfeed.get('tech') else {} blocks = consensus_service.assemble({"ts_code": code, "company_review": cr}, nightly=nightly, tech_states=tech_states) tech = tfeed.get("tech") or blocks["tech"] tm = blocks["timing"] timing = {"stance": tm.get("stance"), "nightly": tm.get("nightly"), "trade_date": (nightly or {}).get("trade_date"), - "flip_at": tm.get("intraday_flip_at")} # 转多时刻点击不回扫, 留昨夜定性带的 + "flip_at": tm.get("intraday_flip_at"), "event": tm.get('intraday_event')} + from app.core.proposal_analysis import timing_view + timing['view'] = timing_view(tm) fund = blocks["fund"] sources = { "company": ("ok" if company else ("无读数" if src != "none" else "不在持仓也不在候选")), diff --git a/app/web/static/index.html b/app/web/static/index.html index 776d01b..85a86aa 100644 --- a/app/web/static/index.html +++ b/app/web/static/index.html @@ -1371,7 +1371,7 @@ body.dock-r:not(.r-fold) .side-r .strip{display:none;} · {{ proposals.length }} 条{{ sectClosed.prop?'▸':'▾' }}
{{ propTimingReason(propDetailP) }}