接入三组证据择时与恢复退出闭环

This commit is contained in:
baobao 2026-11-11 15:50:39 +08:00
parent 00a7159bc9
commit 9dbdd84c41
18 changed files with 464 additions and 15 deletions

View File

@ -2987,3 +2987,7 @@ PMS最终代码56db0fd已推送,155 web/WS/beat为execution-2b1c447,worker
### 2026-11-09 14:25 持仓盈亏只读核验
雷赛1500股网格余量已于13:20:39自然成交,51.75元,13:21:05入账,余100股BASE。当前14:23行情52.67元,剩余浮盈438元、已实现6797元、综合7235元,费用未知。负摊薄成本被旧逻辑截为零再存NULL,导致个股收益率显示“—”,顶部金额也少计1968元。数量现金对账一致,确认1736013、pending/orphan为0。本次仅核实并记录,未改公式或服务;详见[盈亏核验](docs/持仓盈亏与零成本边界核验_2026-11-09.md)。
## 2026年11月11日 多源择时实施
按用户授权修复上游QRS缓存并接入三组等预算。PMS新增合成契约、周期采纳、恢复和二次清仓去重。执行依据与异步请求携带同一择时版本;轮询续期不额外触发模型。第三方分钟数据仅核验、列出缺口,不回填。开发机新增13项专项通过;完整回归和定向发布结果见后续接续。

3
Dockerfile.timing-fusion Normal file
View File

@ -0,0 +1,3 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
COPY . /app

View File

@ -516,3 +516,5 @@ docker compose --profile ws up -d pms-ws && docker compose logs -f pms-ws
### ETF观测与关注信号
`pms-observation`独立消费正式ETF观测,持久化后确认。页面经`GET /api/etf/observation`读取,两个独立Redis连接仅由私有环境注入。`PMS_ETF_OBSERVATION_ENABLED`控制观测消费与显示,`PMS_SIGNAL_FOCUS_ENABLED`控制持仓及关注真实信号补留,均经ParamStore读取。ETF不参与交易执行。详见[实施及发布状态](docs/自选股补显与ETF观测实施_2026-11-05.md)。
三组证据合成择时的边界与验证见[实施规格](docs/多源择时实施规格_2026-11-11.md)。开关经ParamStore配置,默认关闭;生产者为Bionic,PMS只采纳版本化结论及管理执行账本。

View File

@ -0,0 +1,71 @@
"""核验决策系统合成结果的契约,不在PMS重算择时。"""
import math
from app.core import risk_exit as rules
from app.core.command_spec import is_stock_code
VERSION = 'timing_fusion_v1'
GROUPS = ('qrs', 'main_fund', 'v3f')
def valid(value, now, *, since=None):
if not isinstance(value, dict) or value.get('version') != VERSION or value.get('source') != 'timing_fusion':
return None
code = str(value.get('ts_code') or '')
if not is_stock_code(code) or not code.endswith(('.SH', '.SZ')):
return None
at, verified, expiry, now = map(rules.stamp, (value.get('at'), value.get('verified_at'), value.get('expires_at'), now))
if not all((at, verified, expiry, now)) or not at <= verified <= now < expiry or verified.date() != now.date():
return None
if (now-verified).total_seconds() > 120 or (expiry-verified).total_seconds() > 120:
return None
if since is not None:
start = rules.stamp(since)
if not start or at < start:
return None
key = value.get('key', '')
if len(key) != 64 or any(c not in '0123456789abcdef' for c in key):
return None
groups = value.get('groups')
if not isinstance(groups, dict) or set(groups) != set(GROUPS):
return None
try:
for name, group in groups.items():
if abs(float(group['weight'])-1/3)>1e-9 or group['direction'] not in (-1, 0, 1):
return None
if group['state'] not in ('VALID','UNKNOWN') or bool(group['evidence']) != (group['state']=='VALID'):
return None
if group['state']=='UNKNOWN' and group['direction'] != 0:
return None
for e in group['evidence']:
start, end = rules.stamp(e['at']), rules.stamp(e['expires_at'])
if (e['group'] != name or e['ts_code'] != code or not start or not end
or not start <= now < end or start.date() != now.date() or not e['identity']):
return None
sign = 1 if value.get('action') == 'BUY' else -1 if value.get('action') == 'SELL' else 0
if value.get('action') not in ('BUY','SELL','WAIT'):
return None
if not math.isfinite(float(value['score'])):
return None
if sign and (sum(g['direction']==sign for g in groups.values()) < 2
or float(value['score'])*sign < 2/3-1e-8):
return None
except (KeyError, TypeError, ValueError):
return None
return value
def duplicate(events, event):
"""重复读取不能形成第二次清仓;支持组需有新的独立观察。"""
for old in events:
if old.get('key') == event.get('key'):
return True
if old.get('source') == 'timing_fusion':
old_time = rules.stamp(old.get('at'))
fresh_groups = sum(g['direction'] == -1 and bool(g['evidence'])
and all(rules.stamp(e['at']) > old_time and e['identity'] not in
{x['identity'] for before in old.get('groups', {}).values() for x in before['evidence']}
for e in g['evidence'])
for g in event['groups'].values())
if fresh_groups < 2:
return True
return False

View File

@ -80,8 +80,11 @@ def assemble(row, *, nightly=None, tech_states=None, flip_at=None, params=None,
# 新模式只采用带原始时间和期限的最新方向,不再把旧 BUY 留痕当作全天看多。
tm = _timing_stance(nightly, today_ymd=tradedays.ymd(), stale_tdays=p['timing_stale_tdays'])
event = timing_state.valid(intraday_event, now) if intraday_event is not None else timing_state.latest(code, now)
from app.services import timing_fusion
if timing_fusion.enabled():
tm = {'stance': '无读数', 'fresh': False, 'no_read_why': '合成择时缺失或过期,等待新证据'}
if event:
tm.update(stance='看多' if event['action'] == 'BUY' else '看空', fresh=True,
tm.update(stance='看多' if event['action'] == 'BUY' else '看空' if event['action'] == 'SELL' else '无读数', fresh=True,
intraday_flip_at=event['at'] if event['action'] == 'BUY' else None,
intraday_event=event, no_read_why=None)
# 合议参与分流的开关关掉时, 基本面无读数不由合议这层拦 (回到只按判决分流)
@ -90,6 +93,9 @@ def assemble(row, *, nightly=None, tech_states=None, flip_at=None, params=None,
fund_required=(p["fund_required"] and p["consensus_route"]),
weak_confirm=p.get("weak_confirm", True),
timing_dissent=p.get("timing_dissent", "confirm"))
from app.services import timing_fusion
if timing_fusion.enabled() and tm['stance'] == '无读数' and con.get('route') == '放行':
con.update(route='观察', route_reason='等待新的有效合成择时', disp='wait_timing')
return {"fund": fund, "tech": tech, "timing": tm, "consensus": con}

View File

@ -77,6 +77,8 @@ def _post(url: str, payload: dict, timeout: int) -> dict:
import requests
# 独立执行依据刷新直接读取仓储,成本与参考位可能仍为 Decimal。
# 复用研判接口的明确类型转换,未知类型和非有限数仍由 JSON 编码拒绝。
from app.services import timing_fusion
payload = {**payload, **timing_fusion.request_fields()}
r = requests.post(url, json=judge.jsonable(payload), timeout=timeout)
r.raise_for_status()
return r.json() or {}

View File

@ -18,6 +18,12 @@ def uses_basis(parent):
def cache_reason(progress, now=None):
cache = (progress or {}).get('execution_basis_cache') or {}
from app.services import timing_fusion, timing_state
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 '合成择时未转多或执行依据版本已变化,等待刷新'
return policy.basis_reason(cache.get('basis'), now,
max_source_days=max(0, param_store.get_int('PMS_EXEC_BASIS_SOURCE_MAX_DAYS', 7)))

View File

@ -250,6 +250,11 @@ def request(candidate: dict, context: dict = None, *, timeout: int = None,
# 现在候选卡的理由随硬数字送了过去, 问题就有了具体的靶子, 由 PMS 点名要它逐条回答。
"must_answer": must_answer_for(action),
}
from app.services import timing_fusion, timing_state
if timing_fusion.enabled():
payload.update(timing_fusion.request_fields())
event = timing_state.latest(candidate.get('ts_code'))
payload['timing_fusion'] = {k:v for k,v in (event or {}).items() if k not in ('verified_at','expires_at')}
if force:
payload["force_refresh"] = True
if reask_text:

View File

@ -39,7 +39,10 @@ def identity(candidate, payload):
'action_qty': candidate.get('qty') if payload.get('action') != 'OPEN' else None}
event = (hard.get('timing') or {}).get('event')
if event:
material['timing_event'] = {k: event.get(k) for k in ('key', 'action', 'at', 'expires_at')}
keys = ('key', 'action', 'at') if event.get('source') == 'timing_fusion' else ('key', 'action', 'at', 'expires_at')
material['timing_event'] = {k: event.get(k) for k in keys}
if payload.get('timing_fusion_scope'):
material['timing_fusion'] = (payload.get('timing_fusion') or {}).get('key')
return digest(material)

View File

@ -46,6 +46,8 @@ def _valid_limit_flag(value):
# 运行态开关: key -> (默认值, 类型, 说明)
RUNTIME_EXTRA = {
'PMS_TIMING_FUSION_ENABLED': (False, bool, '采纳决策系统三组等预算择时,旧模型广播不另计买卖票'),
'PMS_TIMING_FUSION_START_AT': ('', str, '合成择时启用时刻,不回放启用前证据'),
'PMS_SIGNAL_RECOVERY_ENABLED': (False, bool, '使用最新有效盘中方向;三源重新放行后可解除首次系统停买,不解除人工暂停或已启动清仓'),
'PMS_SIGNAL_RECOVERY_START_AT': ('', str, '方向更新与首次停买恢复的实际启用时刻,不回补旧信号'),
"PMS_SIGNAL_FOCUS_ENABLED": (False, bool, "持仓与有效关注共用完整信号读取,不扩大交易资格"),

View File

@ -138,10 +138,17 @@ def on_signal(sig, *, now=None, dry_run=False):
if not enabled():
return None
now = now or datetime.now()
event, why = rules.signal_event(sig, now=now,
since=param_store.get('PMS_RISK_EXIT_START_AT', ''),
threshold=param_store.get_float('PMS_SIGNAL_AUTO_EXIT_CONF', .85),
max_age=param_store.get_int('PMS_RISK_SIGNAL_MAX_AGE_SEC', 300))
from app.services import timing_fusion
from app.core import timing_fusion_contract
if timing_fusion.enabled():
event = timing_fusion_contract.valid(sig, now, since=param_store.get('PMS_TIMING_FUSION_START_AT', ''))
event = event if event and event['action'] == 'SELL' else None
why = '没有有效的合成看空结论'
else:
event, why = rules.signal_event(sig, now=now,
since=param_store.get('PMS_RISK_EXIT_START_AT', ''),
threshold=param_store.get_float('PMS_SIGNAL_AUTO_EXIT_CONF', .85),
max_age=param_store.get_int('PMS_RISK_SIGNAL_MAX_AGE_SEC', 300))
if not event:
return {'accepted': False, 'reason': why}
code = sig['ts_code']
@ -161,8 +168,8 @@ def on_signal(sig, *, now=None, dry_run=False):
opened = rules.stamp(pos.get('opened_date'))
if opened and rules.stamp(event['at']) < opened:
return {'accepted': False, 'reason': '信号早于当前持仓轮次'}
duplicate = rules.duplicate(state['events'], event,
mirror_seconds=param_store.get_int('PMS_RISK_SIGNAL_MIRROR_SEC', 120))
duplicate = (timing_fusion_contract.duplicate(state['events'], event) if timing_fusion.enabled() else
rules.duplicate(state['events'], event, mirror_seconds=param_store.get_int('PMS_RISK_SIGNAL_MIRROR_SEC', 120)))
if not duplicate and state['phase'] not in ('EXIT_PENDING', 'EXITING', 'CLOSED', 'MANUAL'):
state['events'].append(event)
state['count'] = int(state.get('count') or 0) + 1
@ -183,7 +190,8 @@ def recover_on_buy(code, event, *, now=None):
wait = {'recovered': False}
if (not enabled() or not timing_state.enabled() or not _code_ok(code)
or not timing_state.valid(event, now) or event.get('action') != 'BUY'
or float(event.get('confidence') or 0) < param_store.get_float('PMS_SIGNAL_AUTO_EXIT_CONF', .85)):
or (event.get('source') != 'timing_fusion' and
float(event.get('confidence') or 0) < param_store.get_float('PMS_SIGNAL_AUTO_EXIT_CONF', .85))):
return wait
if any(param_store.get_bool(k, False) for k in ('PMS_GLOBAL_BUY_HALT', 'PMS_GLOBAL_EXEC_HALT')):
return wait
@ -202,8 +210,10 @@ def recover_on_buy(code, event, *, now=None):
current = timing_state.latest(code, now)
if not current or current['key'] != event['key']:
return wait
if (state.get('phase') != 'STOP_BUY' or state.get('count') != 1
or state.get('review_exit') or state.get('exit_iid')):
first_stop = state.get('phase') == 'STOP_BUY' and state.get('count') == 1
legacy_warning = (event.get('source') == 'timing_fusion' and
state.get('phase') == 'WATCH' and state.get('count') == 0)
if (not (first_stop or legacy_warning) or state.get('review_exit') or state.get('exit_iid')):
return wait
pos, lots = _holding(code)
if (not lots or not set(state.get('lot_ids') or []) & lots
@ -221,11 +231,12 @@ def recover_on_buy(code, event, *, now=None):
return wait
pause = strategy_service.buypause_map().get(code) or {}
sources = pause.get('sources') or ({pause['source']: pause} if pause.get('source') else {})
allowed = {'risk_exit', 'intraday', 'risk_sell', 'accum'}
allowed = {'intraday', 'risk_sell'} if legacy_warning else {'risk_exit', 'intraday', 'risk_sell', 'accum'}
if (not sources or set(sources) - allowed
or any(not rules.stamp(v.get('at')) or rules.stamp(v['at']) >= at for v in sources.values())):
return wait
reason = '新的有效看多信号通过三源合议,解除首次系统停买'
reason = ('新的有效看多信号通过三源合议,解除历史信号预警停买' if legacy_warning
else '新的有效看多信号通过三源合议,解除首次系统停买')
evidence = {'round_id': state['round_id'], 'event': event,
'previous_events': list(state.get('events') or []),
'consensus': consensus_service.hard_keys(blocks), 'sources': sorted(sources)}

View File

@ -105,6 +105,13 @@ def consume(*, batch: int = 50, dry_run: bool = False) -> dict:
except Exception as e:
return {**out, "ok": False, "errors": [f"读账本失败: {type(e).__name__}: {e}"]}
from app.services import timing_fusion
if timing_fusion.enabled():
try:
out['timing_fusion'] = timing_fusion.refresh(dry_run=dry_run)
except Exception as exc:
out['errors'].append('合成择时未更新: '+type(exc).__name__)
prm = {"sell_conf_min": param_store.get_float("PMS_SIGNAL_SELL_CONF_MIN", 0.75),
"auto_exit_conf": param_store.get_float("PMS_SIGNAL_AUTO_EXIT_CONF", 0.85),
"trim_ratio": param_store.get_float("PMS_SIGNAL_TRIM_RATIO", 1 / 3)}
@ -143,6 +150,11 @@ def consume(*, batch: int = 50, dry_run: bool = False) -> dict:
def _handle(sig, view, prm, seen, ymd, dry_run, out, strat_codes=frozenset()):
from app.services import timing_fusion
if timing_fusion.enabled():
# 广播仍由独立信息流展示;不再重复触发另一票或旧暂停链。
out['ignored'] += 1
return
code = sig.get("ts_code")
pos = _pos_of(view, code) if code else None
d = sr.digest(sig, pos, prm)

View File

@ -0,0 +1,63 @@
"""周期采纳Bionic合成方向,原始证据随状态和账本留存。"""
from datetime import datetime
from config.settings import settings
from app.core import timing_fusion_contract as contract, risk_exit as rules, strategy_book as books
from app.repo import rotation_repo, pms_repo
from app.services import param_store
def enabled():
return (settings.INFRA_STRATEGY_BOOK_SCHEMA and not settings.PMS_TABLE_PREFIX
and param_store.get_bool('PMS_TIMING_FUSION_ENABLED', False))
def request_fields():
return {'timing_fusion_scope': 'pms-sim-155'} if enabled() else {}
def refresh(*, now=None, dry_run=False):
if not enabled():
return {'enabled': False}
import requests
from app.services import exec_advisor, timing_state, risk_exit
now = now or datetime.now()
response = requests.get(exec_advisor.base_url()+'/api/intraday/timing_fusion', timeout=(2,5))
response.raise_for_status()
data = response.json()
if data.get('version') != contract.VERSION or data.get('enabled') is not True:
raise ValueError('合成择时来源未就绪')
states = data.get('states')
if not isinstance(states, list) or len(states)>6000:
raise ValueError('合成择时响应超过完整读取边界')
out = {'enabled': True, 'accepted': 0, 'invalid': 0, 'source_errors': data.get('errors', []), 'actions': []}
for state in states:
event = contract.valid(state, now, since=param_store.get('PMS_TIMING_FUSION_START_AT', ''))
if not event:
out['invalid'] += 1
continue
code = event['ts_code']
if dry_run:
out['accepted'] += 1
continue
with rotation_repo.account_guard(), rotation_repo.locked(timing_state.key(code), timing_state.KIND, {}) as current:
if current and rules.stamp(current.get('verified_at') or current.get('at')) > rules.stamp(event['verified_at']):
continue
changed = current.get('key') != event['key']
current.clear()
current.update(event)
if changed:
with books.scope(books.ORIGINAL):
if pms_repo.insert_ledger(ts_code=code, action='SIGNAL', arbiter='system', verdict='NOTE',
price_at=0, hard_numbers={'timing_direction':event}, reason=event['reason'],
ref_id=event['key'][:64]) != 1:
raise RuntimeError('合成择时依据未成功入账')
out['accepted'] += 1
if event['action'] == 'BUY':
result = risk_exit.recover_on_buy(code, event, now=now)
elif event['action'] == 'SELL':
result = risk_exit.on_signal(event, now=now)
else:
continue
out['actions'].append({'ts_code':code, 'action':event['action'], 'result':result})
return out

View File

@ -10,7 +10,8 @@ KIND = 'timing_direction'
def enabled():
return settings.INFRA_STRATEGY_BOOK_SCHEMA and param_store.get_bool('PMS_SIGNAL_RECOVERY_ENABLED', False)
from app.services import timing_fusion
return timing_fusion.enabled() or settings.INFRA_STRATEGY_BOOK_SCHEMA and param_store.get_bool('PMS_SIGNAL_RECOVERY_ENABLED', False)
def key(code):
@ -18,6 +19,10 @@ def key(code):
def valid(value, now=None):
from app.services import timing_fusion
if timing_fusion.enabled():
from app.core import timing_fusion_contract
return timing_fusion_contract.valid(value, now or datetime.now())
if not value:
return None
now = rules.stamp(now or datetime.now())
@ -35,7 +40,8 @@ def latest(code, now=None):
def record(sig, now=None):
if not enabled():
from app.services import timing_fusion
if not enabled() or timing_fusion.enabled():
return None
now = now or datetime.now()
max_age = param_store.get_int('PMS_RISK_SIGNAL_MAX_AGE_SEC', 300)

View File

@ -0,0 +1,120 @@
# 分钟行情缺口核验清单
核验时间:2026-11-11T15:43:36.863832,北京时间。只读208 Redis db13现存数据,未补齐、未写回。
范围为当天量化实际评估的110只沪深股票。统一检查14:25至14:54的30个分钟时点,110只少于分钟QRS要求的20条有效记录。缺少表示当前键中没有该分钟的正成交量记录,不代表停牌。第三方约每15分钟采集,可能延迟补齐;本清单仅描述上述核验时点。
分钟QRS未被纳入本次独立权重预算,缺口不能由降阈值或插值补造。请第三方核对历史分钟是否完整归并、失败重试是否覆盖遗漏区间。
| 股票代码 | 当天记录数 | 14:25至14:54有效条数 | 缺少分钟 |
| --- | ---: | ---: | --- |
| 000007.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 000021.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 000657.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 000720.SZ | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 000811.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 001389.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002008.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002045.SZ | 171 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002049.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002126.SZ | 174 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002139.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002205.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:47、14:49、14:51、14:52、14:53 |
| 002245.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002281.SZ | 173 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002340.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 002384.SZ | 174 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002460.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:47、14:49、14:51、14:52、14:53 |
| 002463.SZ | 176 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002472.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002518.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002535.SZ | 175 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002594.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:47、14:49、14:51、14:52、14:53 |
| 002661.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 002850.SZ | 189 | 12 | 14:26、14:28、14:31、14:32、14:34、14:36、14:37、14:38、14:40、14:42、14:43、14:44、14:46、14:48、14:50、14:52、14:53、14:54 |
| 002852.SZ | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 002865.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002911.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 002913.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 002916.SZ | 178 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 002920.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 002965.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:48、14:49、14:51、14:52、14:53 |
| 002979.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 300001.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 300003.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 300014.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300054.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 300073.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 300118.SZ | 180 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300124.SZ | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 300274.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 300308.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300340.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:42、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300398.SZ | 182 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300475.SZ | 182 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300476.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300502.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300567.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300620.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300627.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:48、14:49、14:51、14:52、14:53 |
| 300638.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300660.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:48、14:49、14:51、14:52、14:53 |
| 300684.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:48、14:49、14:51、14:52、14:53 |
| 300693.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300724.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 300731.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300750.SZ | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 300776.SZ | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 300870.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300891.SZ | 187 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300956.SZ | 189 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 300990.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 301018.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 301037.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 301115.SZ | 192 | 12 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53 |
| 301205.SZ | 190 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 301232.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 301326.SZ | 188 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 301358.SZ | 183 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 301363.SZ | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 301395.SZ | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:48、14:49、14:51、14:52、14:53 |
| 600016.SH | 189 | 12 | 14:26、14:28、14:31、14:32、14:34、14:36、14:37、14:38、14:40、14:42、14:43、14:44、14:46、14:48、14:50、14:52、14:53、14:54 |
| 600123.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 600183.SH | 165 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 600281.SH | 166 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 600590.SH | 165 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 600828.SH | 189 | 12 | 14:26、14:28、14:31、14:32、14:34、14:36、14:37、14:38、14:40、14:42、14:43、14:44、14:46、14:48、14:50、14:52、14:53、14:54 |
| 600941.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 601126.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 601727.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 601777.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 603113.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 603228.SH | 166 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 603259.SH | 192 | 12 | 14:25、14:27、14:30、14:31、14:32、14:35、14:36、14:38、14:39、14:41、14:42、14:44、14:45、14:47、14:49、14:51、14:52、14:53 |
| 603578.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 603659.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 603667.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 603893.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 605598.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 688006.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 688012.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 688018.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 688025.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688036.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688100.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 688112.SH | 184 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688183.SH | 166 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688223.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 688275.SH | 166 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688279.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 688283.SH | 165 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688301.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 688333.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 688337.SH | 192 | 11 | 14:25、14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:41、14:42、14:43、14:45、14:47、14:49、14:51、14:52、14:53、14:54 |
| 688469.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 688472.SH | 191 | 12 | 14:26、14:29、14:31、14:32、14:34、14:36、14:37、14:39、14:40、14:42、14:43、14:45、14:46、14:49、14:50、14:52、14:53、14:54 |
| 688556.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688580.SH | 189 | 10 | 14:26、14:29、14:31、14:32、14:33、14:34、14:36、14:37、14:38、14:40、14:42、14:43、14:44、14:46、14:47、14:48、14:50、14:52、14:53、14:54 |
| 688676.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:33、14:35、14:36、14:38、14:39、14:41、14:43、14:44、14:46、14:48、14:49、14:51、14:52、14:54 |
| 688719.SH | 170 | 12 | 14:25、14:28、14:30、14:32、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |
| 688778.SH | 191 | 12 | 14:25、14:27、14:30、14:31、14:34、14:35、14:37、14:38、14:40、14:41、14:43、14:44、14:46、14:48、14:50、14:51、14:53、14:54 |

View File

@ -0,0 +1,17 @@
# 多源择时与数据修复实施规格
用户于2026年11月11日批准先修数据、检验,再按独立性研究的权重更新系统。只更新155模拟PMS的采纳功能。188真实PMS不操作,旧消费者接口语义保持兼容。
技术QRS、主力资金、v3f异动各占三分之一。资金流强度、资金分布及其合并报文共享一个预算。Bionic负责合成并解释,不将模型结论重复计为第四票。原发布阈值不降低,权重不代表交易成功概率。
修复日线缓存跨日失效,并检查分钟QRS的输入窗口。原始历史不改写、不重发。日线QRS必须对应上一实际交易日,缺数据与未触发阈值分开。北交所证券在入口排除。
合成只采纳可追溯、未过期的证据。每组使用最新观察时刻,同一观察的重复发布不增加权重。组内相反方向抵消;缺失不放大其他组,异常或失联不是中性。两组同向且净分达到三分之二才输出明确方向,冲突输出等待。QRS有效至当日收盘,盘中事件按来源节奏限时有效,午间休市不扣交易分钟。生产时间与数据时间独立核验,不用Redis流ID作为行情时间。
PMS经现有周期任务读取Bionic的版本化合成结果。不额外调用模型,不直接读取来源后自建研判。开启后旧模型广播保留展示,但不再次触发独立买卖票。缺失或过期不得回退到旧夜间方向。三源合议的基本面、技术面以及评级下调退出规则保留。
首次有效转弱停止买入。第二次需有更新的同向证据,原有全部支持组均有新观察,不能仅凭重复消费、模型重算或同源镜像触发清仓。重新转强只有三源重新放行、无人工限制且尚未启动清仓时才恢复。执行依据携带相同择时版本,旧离场判断不得覆盖新的有效转强。价格来源校验、合法涨跌停及资金数量约束不变。
所有新开关默认关闭,通过实际参数启用。先做开发机隔离测试,再做候选镜像断网回归,提交后定向发布。保留共享目录私有环境与其他容器,保留唯一QMT连接。验证包括数据日期、去重、缺失、冲突、过期、转弱、恢复、二次退出、评级下降和旧接口兼容。自然请求或真实成交未发生时明确记录未判收,不能制造事件验收。
分钟行情由第三方每约15分钟维护。用户明确本项目不做补齐;当前缺口已形成逐票清单。分钟QRS不参与本版权重,不能降阈值掩盖不足。主力资金新增原始观察时间,合成按观察时间去重与过期,不把重复发布续命。历史普通信号预警停买也可在新合成看多、三源放行且无人工限制时解除;评级退出和已启动清仓不恢复。

View File

@ -202,6 +202,7 @@ HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
# 退出纪律专项:两次独立清仓信号、评级下降、事务、双策略隔离及撤单收尾。
SUITES = [
"test_timing_fusion.py", # 三组证据契约、二次清仓与恢复(13例)
"test_signal_recovery.py", # 最新方向、停买恢复、网格合议、关注入口与负净成本(16例)
"test_grid_execution.py",
"test_broad_funds.py", "test_etf_observation.py", "test_risk_exit.py", "test_rotation_accounting_units.py", "test_cost_precision.py", "test_execution_basis_decimal.py",

View File

@ -0,0 +1,115 @@
"""合成择时消费与退出恢复:隔离SQLite,不联网、不伪造真机验收。"""
import unit_test_guard
import copy
import datetime as dt
import unittest
from unittest.mock import patch
import test_risk_exit as base
import test_signal_recovery as recovery
from app.core import timing_fusion_contract as contract, risk_exit as rules
from app.services import timing_fusion, timing_state, risk_exit, consensus_service, signal_service
from app.repo import rotation_repo
def fused(action='SELL', at=base.NOW, n=1):
sign=1 if action=='BUY' else -1 if action=='SELL' else 0
end=at+dt.timedelta(seconds=100)
groups={}
for group in contract.GROUPS:
evidence=[] if group=='qrs' else [{'ts_code':base.CODE,'group':group,'direction':sign,
'at':at.isoformat(),'expires_at':(at+dt.timedelta(minutes=45)).isoformat(),
'identity':rules.digest([group,n]),'source':group}]
groups[group]={'weight':1/3,'direction':sign if evidence else 0,
'state':'VALID' if evidence else 'UNKNOWN','evidence':evidence}
return {'version':contract.VERSION,'source':'timing_fusion','ts_code':base.CODE,'key':rules.digest([action,n]),
'action':action,'score':sign*2/3,'coverage':2,'groups':groups,'at':at.isoformat(),
'verified_at':at.isoformat(),'expires_at':end.isoformat(),'reason':'隔离测试证据'}
class ContractTests(unittest.TestCase):
def test_valid_not_a_model_probability(self):
value=fused();self.assertNotIn('confidence',value);self.assertIsNotNone(contract.valid(value,base.NOW))
def test_invalid_boundaries(self):
v=fused()
for changes in [{'ts_code':'920000.BJ'},{'source':'intraday'},{'version':'old'},
{'verified_at':(base.NOW+dt.timedelta(seconds=1)).isoformat()},
{'expires_at':base.NOW.isoformat()},{'key':'x'},{'score':-.3}]:
self.assertIsNone(contract.valid({**v,**changes},base.NOW))
self.assertIsNone(contract.valid(v,base.NOW,since=''))
self.assertIsNone(contract.valid(v,base.NOW+dt.timedelta(seconds=101)))
def test_transport_refresh_not_new_signal(self):
a=fused();b={**a,'verified_at':(base.NOW+dt.timedelta(seconds=30)).isoformat()}
self.assertTrue(contract.duplicate([a],b))
def test_only_one_new_group_cannot_confirm_second_exit(self):
a=fused();b=fused(at=base.NOW+dt.timedelta(minutes=5),n=2)
b['groups']['main_fund']=copy.deepcopy(a['groups']['main_fund'])
self.assertTrue(contract.duplicate([a],b))
def test_two_new_groups_confirm_second_exit(self):
self.assertFalse(contract.duplicate([fused()],fused(at=base.NOW+dt.timedelta(minutes=5),n=2)))
class ServiceTests(recovery.DirectionTests):
# 只运行本类专用测试,沿用已有SQLite双策略和持仓桩。
def setup_fusion(self):
now=self.setup_direction()
self.params.update(PMS_TIMING_FUSION_ENABLED=True,PMS_TIMING_FUSION_START_AT=base.START.isoformat())
return now
def save(self,event):
with rotation_repo.locked(timing_state.key(base.CODE),timing_state.KIND,{}) as current:
current.clear();current.update(event)
def test_fusion_first_stop_replay_then_second_exit(self):
now=self.setup_fusion();a=fused(at=now);self.save(a)
self.assertEqual(risk_exit.on_signal(a,now=now)['count'],1)
self.assertEqual(risk_exit.on_signal(a,now=now)['count'],1)
b=fused(at=now+dt.timedelta(minutes=5),n=2);self.save(b)
self.assertEqual(risk_exit.on_signal(b,now=now+dt.timedelta(minutes=5))['count'],2)
self.assertEqual(len(self.instructions()),1)
def test_fusion_new_buy_recovers_without_confidence_fabrication(self):
now=self.setup_fusion();a=fused(at=now);self.save(a);risk_exit.on_signal(a,now=now)
later=now+dt.timedelta(minutes=5);b=fused('BUY',later,2);self.save(b)
self.assertTrue(risk_exit.recover_on_buy(base.CODE,b,now=later)['recovered'])
self.assertEqual(self.state()['phase'],'WATCH');self.assertEqual(self.instructions(),[])
def test_fusion_expired_cannot_revert_to_nightly_buy(self):
now=self.setup_fusion();a=fused(at=now);self.save(a)
blocks=consensus_service.assemble({'ts_code':base.CODE,'company_review':base.review()},
nightly={'verdict':'BUY'},tech_states=consensus_service.state_map(),now=now+dt.timedelta(minutes=3))
self.assertEqual(blocks['timing']['stance'],'无读数');self.assertNotEqual(blocks['consensus']['route'],'放行')
def test_fusion_old_model_broadcast_never_double_counts(self):
now=self.setup_fusion();a=fused(at=now);self.save(a);risk_exit.on_signal(a,now=now)
out={'ignored':0}
signal_service._handle(base.signal(2),{}, {},{},20261105,False,out)
self.assertEqual(self.state()['count'],1);self.assertEqual(out['ignored'],1)
def test_old_warning_pause_recovers_but_manual_pause_does_not(self):
from app.services import strategy_service
now=self.setup_fusion()
risk_exit.observe_review(base.CODE,base.review(),now=now)
strategy_service.pause_buy(base.CODE,source='intraday',reason='历史预警')
b=fused('BUY',now+dt.timedelta(minutes=5),2);self.save(b)
self.assertTrue(risk_exit.recover_on_buy(base.CODE,b,now=now+dt.timedelta(minutes=5))['recovered'])
def test_polling_lease_does_not_enqueue_new_model_task(self):
from app.services import judge_async
a=fused('BUY');b={**a,'expires_at':(base.NOW+dt.timedelta(seconds=110)).isoformat()}
x={'hard_numbers':{'timing':{'event':a}}};y={'hard_numbers':{'timing':{'event':b}}}
payload={'action':'OPEN','timing_fusion_scope':'pms-sim-155','timing_fusion':{'key':a['key']}}
self.assertEqual(judge_async.identity(x,payload),judge_async.identity(y,payload))
def test_refresh_is_idempotent_and_preserves_state_on_replay(self):
from types import SimpleNamespace
now=self.setup_fusion();a=fused(at=now)
response=SimpleNamespace(raise_for_status=lambda:None,json=lambda:{'version':contract.VERSION,'enabled':True,'states':[a]})
with patch('requests.get',return_value=response):
self.assertEqual(timing_fusion.refresh(now=now)['accepted'],1)
self.assertEqual(timing_fusion.refresh(now=now)['accepted'],1)
self.assertEqual(self.state()['count'],1)
self.assertEqual(timing_state.latest(base.CODE,now)['key'],a['key'])
def test_fusion_manual_halt_not_recovered(self):
now=self.setup_fusion();a=fused(at=now);self.save(a);risk_exit.on_signal(a,now=now)
self.params['PMS_GLOBAL_BUY_HALT']=True
later=now+dt.timedelta(minutes=5);b=fused('BUY',later,2);self.save(b)
self.assertFalse(risk_exit.recover_on_buy(base.CODE,b,now=later)['recovered'])
# 基类既有用例由原批次运行,避免本批重复计数。
for name in list(recovery.DirectionTests.__dict__):
if name.startswith('test_') and name not in ServiceTests.__dict__:
setattr(ServiceTests,name,None)
if __name__=='__main__': unittest.main()