74 lines
3.7 KiB
Python
74 lines
3.7 KiB
Python
"""将轮动执行事实转换为交易员可读的进度,只用于展示。"""
|
|
import re
|
|
|
|
from app.core.execution_policy import local_now, timestamp
|
|
from app.repo import rotation_repo
|
|
|
|
|
|
def wait_text(reason):
|
|
messages = (
|
|
('账户可用现金或全账户仓位预算不足', '可用现金或剩余仓位额度不足'),
|
|
('资金快照', '等待 QMT 更新可用资金'),
|
|
('可卖数量不足', '等待可卖股数足够'),
|
|
('下游已撤单', '委托已撤,继续交易须重新授权'),
|
|
('已冻结或列入黑名单', '个股已禁止买入'),
|
|
('等待策略持仓与QMT对齐', '等待核对持仓数量'),
|
|
('旧委托尚未核实入账', '等待核对上一笔委托和成交'),
|
|
('行情已过期或时间超前', '等待更新行情'),
|
|
('等待核实本交易日的委托价格边界', '等待确认当日涨跌停价'),
|
|
('pms-ws 常驻进程未在线', '等待恢复 QMT 连接'),
|
|
)
|
|
for fragment, label in messages:
|
|
if fragment in reason:
|
|
return label
|
|
if '待重试' in reason or '等待执行:' in reason or '委托未下发' in reason:
|
|
return '本次报单未完成,等待下一次执行'
|
|
return reason
|
|
|
|
|
|
def display_wait(reason):
|
|
code = re.match(r'^(\d{6}\.(?:SH|SZ))(.*)$', reason)
|
|
if code:
|
|
return code[1] + ' ' + wait_text(code[2])
|
|
return wait_text(reason)
|
|
|
|
|
|
def order_wait(row, orders, cache):
|
|
from app.services import intraday_rotation as entry
|
|
|
|
p = row['progress']
|
|
now = local_now()
|
|
if p.get('cancel_requested'):
|
|
return '正在结束指令', '系统正在核对最后一笔委托。'
|
|
end = timestamp(p.get('expires_at'))
|
|
if end and now >= end:
|
|
return '当日授权已到期', '当日不再新增委托。'
|
|
if p.get('ticket') and p.get('deadline') == now.date().isoformat():
|
|
if 'state' not in cache:
|
|
cache['state'] = rotation_repo.get('state:live')[0] or {}
|
|
state = cache['state']
|
|
tick = timestamp(state.get('last_tick'))
|
|
rotation = state.get('rotation') or {}
|
|
if (tick and 0 <= (now-tick).total_seconds() <= 180 and p.get('snapshot_version')
|
|
and p['snapshot_version'] == rotation.get('consumed_entry') and row.get('side') == 'buy'
|
|
and row['ts_code'] in rotation.get('target', [])):
|
|
for reason in reversed(state.get('blocked') or []):
|
|
if reason.startswith(row['ts_code']+'等待执行:') or reason.startswith(row['ts_code']+'等待策略持仓') or reason.startswith(row['ts_code']+'下游已撤单'):
|
|
return wait_text(reason[len(row['ts_code']):]), '最近核对于 '+tick.strftime('%H:%M:%S')+'。当前没有在途委托。'
|
|
if row['status'] == 'WAIT_REVIEW':
|
|
if 'release' not in cache:
|
|
cache['release'] = entry.read_release(now) or {}
|
|
if cache['release'].get('ticket') != p['ticket']:
|
|
return '等待当日建仓放行', '当日指令已登记,尚未向 QMT 报单。'
|
|
if 690 <= now.hour*60+now.minute < 780:
|
|
return '午间休市,下午继续', '当前没有在途委托。下午开市后系统继续处理。'
|
|
if orders:
|
|
state = orders[-1].get('status')
|
|
if state == 'CANCELLED':
|
|
return '上笔已撤,余量未报单', '当前没有在途委托。'
|
|
if state == 'EXPIRED':
|
|
return '上笔已到期,余量未报单', '当前没有在途委托。'
|
|
if state == 'REJECTED':
|
|
return 'QMT 已拒单', '上一笔委托未获受理。'
|
|
return '买单尚未报出' if row.get('side') == 'buy' else '卖单尚未报出', '轮动指令已登记,当前没有在途委托。'
|