收盘后禁止生成当日已过期的续单

This commit is contained in:
baobao 2026-10-30 16:19:27 +08:00 committed by Codex deployment
parent 15a4f10ddf
commit 39d209a6e4
4 changed files with 43 additions and 3 deletions

View File

@ -191,7 +191,10 @@ def _qmt_limit(*, side, action, ts_code, now, day, params, is_last_day, urgent,
return result(et.ACT_WAIT, "无有效行情或已停牌,等待核实")
if left <= 0:
return result(et.ACT_WAIT, et.quota_wait_reason(urgent, is_last_day))
if not et.in_session(et.hm_to_min(now)):
now_min = et.hm_to_min(now)
if now_min >= et.CLOSE_MIN:
return result(et.ACT_WAIT, "已收盘,今日不再新增委托")
if not et.in_session(now_min):
return result(et.ACT_WAIT, "非交易时段")
strategy = (prog or {}).get("origin") == "strategy" and (prog or {}).get("stype") in ("GRID", "TRAIL")

View File

@ -367,13 +367,22 @@ def run_tick(*, now=None, dry_run: bool = False) -> dict:
pms_repo.update_instruction(ins["instruction_id"], progress=prog)
continue
dl_min = order_deadline(now, d, ttl_min=order_ttl)
if dl_min <= et.hm_to_min(now):
# 收盘边界可能刚收到旧单终态,不能因此再生成有效期已到的子单。
reason = '已到委托截止时间,今日不再新增委托'
prog['last_decision'] = {'at': now.strftime('%H:%M'), 'action': et.ACT_WAIT, 'reason': reason}
if not dry_run:
pms_repo.update_instruction(ins['instruction_id'], progress=prog)
out['waited'].append({'instruction_id': ins['instruction_id'], 'code': code,
'action': et.ACT_WAIT, 'reason': reason})
continue
if dry_run:
out["fired"].append({"instruction_id": ins["instruction_id"], "code": code,
"qty": qty, "limit": d["limit_price"],
"reason": d["reason"], "dry_run": True})
continue
dl_min = order_deadline(now, d, ttl_min=order_ttl)
# intent / parent_id / note 是 ws 通道要的 (协议 §4.2): intent 只作归类,
# parent_id 让子单能回指父指令, note 原样落到 QMT 侧供人工看盘。
# shadow 模式忽略这三项, 传着不碍事 —— 两种模式共用同一个调用点。

View File

@ -7,7 +7,7 @@
包含 (例数按 2026-10-26 隔离回归实跑校正):
test_batch52_units.py 当日限价、撤单拒绝、迟到成交、发送恢复与真实SQL状态保护 (22例)
test_batch51_units.py 跨日决策复核、撤单回报、数量约束、人工确认与真实SQL事务及完整选股接线 (36例)
test_batch50_units.py QMT限价等待、价格来源故障、用户暂停、配额防重和试算隔离 (14例)
test_batch50_units.py QMT限价等待、价格来源故障、用户暂停、配额防重、试算隔离及收盘边界 (17例)
test_batch49_units.py 持仓分组、同名股票与批次归属、未迁移及缺数展示 (8例)
test_batch48_units.py 策略账本隔离、轮换优先级、交易单位、模拟直接启用、读数及微盘50规则换版 (55例)
test_batch47_units.py 账户资金去重、买入额度与账户展示和策略估值分离 (9 例)

View File

@ -94,6 +94,34 @@ class QmtPriceTests(unittest.TestCase):
self.assertEqual(r['limit_price'], 30.02)
self.assertFalse(r['forced'])
def test_close_boundary_cannot_submit_even_urgent_sell(self):
for now in ('15:00', '15:01', datetime(2026, 10, 28, 15, 0, 16)):
for side in ('buy', 'sell'):
self.assertEqual(self.decide(now=now, side=side, urgent=True)['action'], 'WAIT')
self.assertEqual(self.post.call_count, 0)
self.assertEqual(self.decide(now='14:59')['action'], 'FIRE')
def test_expired_child_at_close_does_not_create_new_outbox(self):
self.parent()
self.fake.params['PMS_EXEC_QMT_DAY_ORDER'] = True
with patch.object(market, 'day_snapshot', return_value={'price': 31.1}):
self.assertEqual(len(executor.run_tick(now=NOW)['fired']), 1)
old = next(iter(self.fake.qmt.orders.values())); old.update(status='EXPIRED', cum_qty=0)
r = executor.run_tick(now=datetime(2026, 10, 28, 15, 0, 16))
self.assertEqual(r['fired'], [])
self.assertIn('已收盘', str(r['waited']))
self.assertEqual(len(self.fake.qmt.orders), 1)
def test_executor_rejects_expired_deadline_even_when_advisor_fires(self):
self.parent()
with patch.object(market, 'day_snapshot', return_value={'price': 31.1}), \
patch.object(ea, 'decide', return_value={'action': 'FIRE', 'qty_hint': 200,
'limit_price': 30.02, 'reason': 'test', 'qmt_price_monitor': True}):
r = executor.run_tick(now=datetime(2026, 10, 28, 15, 0, 16))
self.assertEqual(r['fired'], [])
self.assertIn('截止时间', str(r['waited']))
self.assertEqual(self.fake.qmt.orders, {})
def test_disabled_mode_retains_old_wait(self):
self.fake.params['PMS_EXEC_QMT_PRICE_MONITOR'] = False
self.assertEqual(self.decide(day={'price': 31.1})['action'], 'WAIT')