补齐轮换暂停撤单与全账户净值范围

This commit is contained in:
baobao 2026-10-27 13:08:54 +08:00
parent e13740e85e
commit c00df0c139
5 changed files with 76 additions and 4 deletions

View File

@ -111,6 +111,16 @@ def _fee_map() -> dict:
def compute_snapshot() -> dict:
# 公示净值属于全账户;策略归属启用后,不能只计默认的原策略。
from config.settings import settings
from app.core import strategy_book as books
if settings.INFRA_STRATEGY_BOOK_SCHEMA:
with books.scope('all'):
return _compute_snapshot()
return _compute_snapshot()
def _compute_snapshot() -> dict:
"""组装公示快照: 持仓明细 / 平仓明细 / 汇总 / 当日净值。全部只读。"""
today = date.today()
scale = _nav_scale()

View File

@ -54,7 +54,9 @@ def activation_errors():
evidence, _ = store.get('validation:'+core.RULE)
evidence = evidence or {}
required = ('backtest', 'capacity', 'fees', 'board_permissions', 'migration', 'regression', 'browser', 'fill_attribution', 'fund_reservation')
errors = [k+'尚未验收' for k in required if not evidence.get(k)]
labels = dict(backtest='回测', capacity='成交容量', fees='交易费用', board_permissions='板块权限',
migration='策略账本迁移', regression='回归测试', browser='页面检查', fill_attribution='成交归属', fund_reservation='资金占用')
errors = [labels[k]+'尚未验收' for k in required if not evidence.get(k)]
observed = store.recent('observed_day', 1000)
paper = store.recent('paper_day', 1000)
dates = sorted({r['value']['date'] for r in observed if r['value'].get('rule_version') == core.RULE})
@ -123,9 +125,32 @@ def control(*, mode=None, action=None, actor='user'):
result = param_store.set_param('PMS_ROTATION_CONTROL', action, actor)
if not result.get('ok'):
raise RuntimeError('控制保存失败')
if settings.INFRA_STRATEGY_BOOK_SCHEMA and configuration()['mode'] == 'auto':
cancel_control_orders(action)
return status()
def cancel_control_orders(action):
"""先保存暂停,再撤已发出的轮换委托;失败保留暂停并由调度重试。"""
if action not in ('pause_all', 'pause_new', 'exit_disable'):
return
from app.services import executor
with books.scope('all'):
rows = pms_repo.list_instructions(statuses=LIVE, limit=10000)
failed = []
for row in rows:
if (row.get('progress') or {}).get('execution_profile') != 'rotation':
continue
if action != 'pause_all' and row['side'] != 'buy':
continue
with books.scope(row['book_id']):
result = executor.cancel_instruction(row['instruction_id'], reason='用户轮换控制:'+action, arbiter='user')
if not result.get('ok'):
failed.append(row['instruction_id'])
if failed:
raise RuntimeError('已停止新增指令,部分既有委托尚未完成撤销')
def positions(book):
with books.scope(book):
return pms_repo.list_positions(only_open=True)
@ -192,6 +217,8 @@ def _tick(now=None):
now = now.replace(tzinfo=TZ)
config = configuration()
day = now.date().isoformat()
if settings.INFRA_STRATEGY_BOOK_SCHEMA and config['mode'] == 'auto':
cancel_control_orders(config['control'])
if config['mode'] == 'auto' and settings.INFRA_STRATEGY_BOOK_SCHEMA and now.hour*60+now.minute >= 600:
from app.services.rotation_execution import cancel_expired
cancel_expired(now)
@ -420,6 +447,7 @@ def on_user_command(cmd_type, command_id, issued_by):
result = param_store.set_param('PMS_ROTATION_CONTROL', 'pause_all', issued_by)
if not result.get('ok'):
raise RuntimeError('用户命令冲突暂停未保存')
cancel_control_orders('pause_all')
store.put_once('conflict:'+command_id, 'command_conflict', {'command_id': command_id, 'reason': '用户命令优先,轮换已暂停'})

View File

@ -34,6 +34,12 @@ migrate_strategy_books.py给命令、方案、指令、持仓、批次、提议
## 验证记录
开发机经断网护栏运行scripts/run_tests.py,全部批次通过。新增微盘批次35项通过。页面三道静态护栏通过。桌面与390像素窄屏浏览器已检查30行名单、缺数据提示、控制请求和自动档禁用,无页面脚本错误。
开发机经断网护栏运行scripts/run_tests.py,全部批次通过。新增微盘批次38项通过。页面三道静态护栏通过。桌面与390像素窄屏浏览器已检查30行名单、缺数据提示、控制请求和自动档禁用,无页面脚本错误。
155隔离迁移、匹配镜像回归及观察功能真机结果将在本次部署后追加。自动交易与纸面交易日验收尚未完成。
155使用专属内部Docker网络和独立MariaDB容器,合成数据演练迁移。迁移前后原字段哈希一致,重复迁移、同名股票分账、30股批量委托、重复委托、超买拦截、成交故障原子回滚、重复回报及子事务回滚均通过。未连接QMT或业务库。生产代理库的事务与保存点兼容性仍须在隔离记录上单独判收。
155镜像pms:micro30-e13740e在无网络一次性容器运行scripts/run_tests.py,结果ALL SUITES PASS。后续补充了暂停撤单和全账户净值范围,开发机全量回归再次通过,部署镜像仍需按最终提交复核。
155独立监控镜像bionic-micro30:7a0df88已运行。2026-10-26数据对应2026-10-27执行日,信号与30股名单均就绪,无数据错误。该版本在08:50后生成,只用于展示,不计合格观察日。此前678个交易日的信号、20340条成员记录与冻结研究结果逐项一致。
观察功能页面与接口的真机结果在部署后追加。自动交易与纸面交易日验收尚未完成。现有交易进程在盘中保持运行,交易账本开关保持关闭。

View File

@ -5,7 +5,7 @@
运行: docker compose run --rm pms-web python scripts/run_tests.py
包含 (例数按 2026-10-26 隔离回归实跑校正):
test_batch48_units.py 策略账本隔离、微盘轮换优先级、真实交易单位及纸面账本 (35例)
test_batch48_units.py 策略账本隔离、微盘轮换优先级、真实交易单位及纸面账本 (38例)
test_batch47_units.py 账户资金去重、买入额度与账户展示和策略估值分离 (9 例)
test_batch46_units.py 质地排序切换、档位准入、命令分配与白名单优先 (11 例)
test_batch45_units.py 父指令总量:回放延迟、部分成交、跨日预留、故障守成与影子模式 (16 例)

View File

@ -7,6 +7,7 @@ import json
from pathlib import Path
import sys
import unittest
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from app.core import strategy_book as b, micro_rotation as m
@ -143,6 +144,33 @@ class RotationTests(unittest.TestCase):
class BoundaryTests(unittest.TestCase):
def test_pause_cancels_only_rotation_orders(self):
from app.services import rotation_service as s, executor
rows = [{'instruction_id': 'micro_buy', 'book_id': 'micro30', 'side': 'buy', 'progress': {'execution_profile': 'rotation'}},
{'instruction_id': 'fund_sell', 'book_id': 'original', 'side': 'sell', 'progress': {'execution_profile': 'rotation'}},
{'instruction_id': 'user_buy', 'book_id': 'original', 'side': 'buy', 'progress': {}}]
with patch.object(s.pms_repo, 'list_instructions', return_value=rows), patch.object(executor, 'cancel_instruction', return_value={'ok': True}) as cancel:
s.cancel_control_orders('pause_new')
self.assertEqual([c.args[0] for c in cancel.call_args_list], ['micro_buy'])
cancel.reset_mock()
s.cancel_control_orders('pause_all')
self.assertEqual([c.args[0] for c in cancel.call_args_list], ['micro_buy', 'fund_sell'])
def test_failed_cancel_does_not_allow_continue(self):
from app.services import rotation_service as s, executor
rows = [{'instruction_id': 'micro_buy', 'book_id': 'micro30', 'side': 'buy', 'progress': {'execution_profile': 'rotation'}}]
with patch.object(s.pms_repo, 'list_instructions', return_value=rows), patch.object(executor, 'cancel_instruction', return_value={'ok': False}):
with self.assertRaises(RuntimeError):
s.cancel_control_orders('pause_all')
self.assertEqual(b.CURRENT.get(), 'original')
def test_publish_nav_reads_whole_account_after_migration(self):
from app.services import publish_export as p
from config.settings import settings
with patch.object(settings, 'INFRA_STRATEGY_BOOK_SCHEMA', True), patch.object(p, '_compute_snapshot', side_effect=lambda: {'scope': b.CURRENT.get()}):
self.assertEqual(p.compute_snapshot()['scope'], 'all')
self.assertEqual(b.CURRENT.get(), 'original')
def test_restart_does_not_reconsume_entry(self):
snap=snapshot(low=True)
a=m.transition(m.initial_state(),snap,micro_qty=0,original_qty=0,budget=100000)