"""本日盘中授权的一篮子保护限价委托。每笔独立核对后交唯一QMT执行。""" from decimal import Decimal from app.core import strategy_book as books from app.repo import pms_repo, qmt_repo, rotation_repo as store from app.services import intraday_rotation as entry, param_store def policy_for(progress): ticket = progress.get('ticket') if not ticket: return None policy, _ = store.get('qmt-day-orders:'+ticket) if not policy: return None if policy['binding'] != entry.metadata(progress) or policy.get('account') != '155模拟': raise ValueError('委托执行方式与盘中授权不一致') return policy def protected_price(parent, line, limits): """核对已授权价格边界与当日涨跌停。原价仅作保护,不作实时行情。""" if any(parent[k] != line[k] for k in ('ts_code','book_id','side','qty')): raise ValueError('保护限价与原指令不匹配') price = Decimal(str(line['price'])) low = Decimal(str(limits.get('down_limit') or 0)) high = Decimal(str(limits.get('up_limit') or 0)) if (not all(v.is_finite() for v in (price,low,high)) or not 0 < low <= price <= high or price != price.quantize(Decimal('.01'))): raise ValueError('保护限价或当日价格上下限不可核实') boundary = (parent.get('progress') or {}).get('user_limit_price') or parent.get('limit_price') if boundary is not None: limit = Decimal(str(boundary)) if not limit.is_finite() or (parent['side']=='buy' and price>limit) or (parent['side']=='sell' and price