tradingSystem/app/core/exit_presentation.py

48 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""退出纪律的只读业务说明;不产生信号、不改变状态或交易条件。"""
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