补齐复核等待任务的命令撤销与策略追踪
This commit is contained in:
parent
5a3d29a2d3
commit
12b9c22e2a
|
|
@ -27,7 +27,7 @@ from app.services import industry, param_store, portfolio
|
|||
logger = logging.getLogger("pms.command")
|
||||
|
||||
# 在途 (可被撤销/冲突判定) 的指令状态
|
||||
LIVE_INSTR = ("PROPOSED", "RULE_PASSED", "JUDGE_PASSED", "DISPATCHED")
|
||||
LIVE_INSTR = ("PROPOSED", "RULE_PASSED", "JUDGE_PASSED", "DISPATCHED", "WAIT_REVIEW")
|
||||
|
||||
STOCK_PARAM_TYPES = ("FREEZE_STOCK", "UNFREEZE_STOCK", "T0_ENABLE", "T0_DISABLE",
|
||||
"SET_STOP_PRICE", "SET_TARGET_PRICE", "BLACKLIST_ADD", "BLACKLIST_REMOVE",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,15 @@ def applies(ins):
|
|||
and (ins.get('progress') or {}).get('execution_profile') != 'rotation')
|
||||
|
||||
|
||||
def _command_blocker(ins):
|
||||
cid = (ins.get('progress') or {}).get('command_id')
|
||||
if cid:
|
||||
cmd = pms_repo.get_command(cid)
|
||||
if not cmd or cmd['status'] not in ('EXECUTING', 'PARTIAL'):
|
||||
return '来源命令已经结束,不能恢复旧买入安排'
|
||||
return None
|
||||
|
||||
|
||||
def blocker(ins, *, now=None):
|
||||
if not applies(ins):
|
||||
return None
|
||||
|
|
@ -29,6 +38,9 @@ def blocker(ins, *, now=None):
|
|||
return '跨日买入尚未完成当日决策复核'
|
||||
if not param_store.get_bool('PMS_DAILY_BUY_REVIEW', False):
|
||||
return None
|
||||
stopped = _command_blocker(ins)
|
||||
if stopped:
|
||||
return stopped
|
||||
today = _day(now or datetime.now())
|
||||
prog = ins.get('progress') or {}
|
||||
if prog.get('deadline') and _day(prog['deadline']) < today:
|
||||
|
|
@ -134,6 +146,8 @@ def _invalidate_confirmation(ins, p, now):
|
|||
|
||||
|
||||
def _approve(ins, result, now, *, proposal=None, arbiter='system', reason=None):
|
||||
if _command_blocker(ins):
|
||||
return False
|
||||
rows, filled = _orders(ins)
|
||||
if any(r['status'] not in qmt_repo.FINAL for r in rows) or filled != int(ins.get('exec_qty') or 0):
|
||||
return False
|
||||
|
|
@ -212,6 +226,11 @@ def process(*, now=None):
|
|||
out['waiting'].append(iid) # 等回放,不将通道累计数写成账本成交。
|
||||
continue
|
||||
prog = row.get('progress') or {}
|
||||
stopped = _command_blocker(row)
|
||||
if stopped:
|
||||
if _end(row, stopped, now):
|
||||
out['ended'].append(iid)
|
||||
continue
|
||||
if (prog.get('deadline') and _day(prog['deadline']) < _day(now)) or prog.get('origin') == 'strategy':
|
||||
if _end(row, '昨日买入安排结束;后续按当日策略重新生成', now):
|
||||
out['ended'].append(iid)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from app.repo import pms_repo, qmt_repo, rotation_repo as store
|
|||
from app.services import param_store, portfolio, market
|
||||
|
||||
TZ = ZoneInfo('Asia/Shanghai')
|
||||
LIVE = ('PROPOSED', 'RULE_PASSED', 'JUDGE_PASSED', 'DISPATCHED')
|
||||
LIVE = ('PROPOSED', 'RULE_PASSED', 'JUDGE_PASSED', 'DISPATCHED', 'WAIT_REVIEW')
|
||||
TERMINAL = qmt_repo.FINAL
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -852,7 +852,7 @@ def _has_pending(st) -> bool:
|
|||
ins = pms_repo.get_instruction(iid)
|
||||
except Exception: # noqa: BLE001
|
||||
return False
|
||||
return bool(ins and ins.get("status") in ("PROPOSED", "RULE_PASSED", "DISPATCHED"))
|
||||
return bool(ins and ins.get("status") in ("PROPOSED", "RULE_PASSED", "DISPATCHED", "WAIT_REVIEW"))
|
||||
|
||||
|
||||
def _snap(a, hv, p) -> dict:
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ from app.services import market, param_store, portfolio
|
|||
logger = logging.getLogger("pms.strategy")
|
||||
|
||||
# 指令在途 (未终态) 的状态集 —— 与 executor.LIVE 一致; 本层据此判断「上一笔还没走完, 先别再发」。
|
||||
LIVE_INS = ("PROPOSED", "RULE_PASSED", "DISPATCHED")
|
||||
LIVE_INS = ("PROPOSED", "RULE_PASSED", "DISPATCHED", "WAIT_REVIEW")
|
||||
|
||||
# 批次动作 (与 recon.ACTION_TO_LOT 对齐)
|
||||
A_T0 = "T0_ROUND" # 做T 买入与卖出 → T0 批次
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@
|
|||
|
||||
## 验证与发布记录
|
||||
|
||||
开发机增加33项专项测试,包括真实SQLite单表事务回滚、撤单未终态、迟到成交、数量预留、用户撤销并发、人工确认与完整选股接线。全量断网回归及页面三道护栏经隔离入口执行。页面1440及390宽浏览器重放验证复核状态、实际委托限价、标签切换和撤单弹窗关闭,写请求为0;属于开发机复现,不是交易员实际登录验收。
|
||||
开发机增加36项专项测试,包括真实SQLite单表事务回滚、撤单未终态、迟到成交、数量预留、用户撤销并发、人工确认与完整选股接线。全量断网回归及页面三道护栏经隔离入口执行。页面1440及390宽浏览器重放验证复核状态、实际委托限价、标签切换和撤单弹窗关闭,写请求为0;属于开发机复现,不是交易员实际登录验收。
|
||||
|
||||
发布、155当日自然复核及QMT恢复证据在完成后追加。未用真实测试委托制造通过。
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
运行: docker compose run --rm pms-web python scripts/run_tests.py
|
||||
|
||||
包含 (例数按 2026-10-26 隔离回归实跑校正):
|
||||
test_batch51_units.py 跨日决策复核、撤单回报、数量约束、人工确认与真实SQL事务及完整选股接线 (33例)
|
||||
test_batch51_units.py 跨日决策复核、撤单回报、数量约束、人工确认与真实SQL事务及完整选股接线 (36例)
|
||||
test_batch50_units.py QMT限价等待、价格来源故障、用户暂停、配额防重和试算隔离 (14例)
|
||||
test_batch49_units.py 持仓分组、同名股票与批次归属、未迁移及缺数展示 (8例)
|
||||
test_batch48_units.py 策略账本隔离、轮换优先级、交易单位、模拟直接启用、读数及微盘50规则换版 (55例)
|
||||
|
|
|
|||
|
|
@ -137,6 +137,12 @@ class DailyReviewTests(unittest.TestCase):
|
|||
self.assertEqual(self.run_review()['ended'], ['P']); self.assertEqual(self.parent()['exec_qty'], 100)
|
||||
self.assertIn('排名', self.parent()['progress']['daily_review']['reason'])
|
||||
|
||||
def test_source_command_cancelled_during_review_cannot_resume(self):
|
||||
row = self.parent(); row['progress']['command_id'] = 'CMD'
|
||||
pms_repo.update_instruction('P', progress=row['progress'])
|
||||
self.use(pms_repo, 'get_command', return_value={'status': 'CANCELLED'})
|
||||
self.assertEqual(self.run_review()['ended'], ['P']); self.scan.assert_not_called()
|
||||
|
||||
def test_expired_command_does_not_keep_buying_as_partial(self):
|
||||
row = self.parent(); row['progress']['deadline'] = '2026-10-29'
|
||||
pms_repo.update_instruction('P', progress=row['progress'])
|
||||
|
|
@ -284,6 +290,21 @@ class ScanIntegrationTests(unittest.TestCase):
|
|||
self.assertIsNotNone(r['review'], r); self.assertFalse(r['review']['auto_exec'])
|
||||
self.assertTrue(separate.called)
|
||||
|
||||
def test_cancel_entire_command_also_cancels_review_waiting_child(self):
|
||||
from app.services import command_service
|
||||
self.fake.commands['CMD'] = {'command_id': 'CMD', 'cmd_class': 'task', 'status': 'EXECUTING'}
|
||||
self.fake.insert_plans([{'command_id': 'CMD', 'plan_id': 'plan', 'status': 'EXECUTING', 'qty': 600}])
|
||||
with patch.object(dispatcher, 'cancel', return_value={'ok': True}):
|
||||
r = command_service.cancel('CMD')
|
||||
self.assertTrue(r['ok'], r); self.assertEqual(r['cancelled'], ['P'])
|
||||
self.assertEqual(self.fake.get_instruction('P')['status'], 'CANCELLED')
|
||||
|
||||
def test_strategy_and_rotation_continue_tracking_review_waits(self):
|
||||
from app.services import rotation_service, strategy_runner, strategy_advisor
|
||||
self.assertIn('WAIT_REVIEW', rotation_service.LIVE)
|
||||
self.assertIn('WAIT_REVIEW', strategy_runner.LIVE_INS)
|
||||
self.assertTrue(strategy_advisor._has_pending({'state': {'pending': {'iid': 'P'}}}))
|
||||
|
||||
def test_prepared_verdict_path_does_not_call_model(self):
|
||||
r = ps.scan_and_route(now=NOW, review_instruction=copy.deepcopy(self.parent),
|
||||
prepared_verdict={'verdict': 'PASS', 'reason': '今日已准备', 'degraded': False})
|
||||
|
|
|
|||
Loading…
Reference in New Issue