在父指令所属策略账本登记撤换请求
This commit is contained in:
parent
314466183e
commit
7d738e97f0
|
|
@ -216,6 +216,10 @@ def request_replace(parent_id, reason, now=None):
|
|||
progress = dict(parent.get('progress') or {})
|
||||
if not progress.get('replacement_requested'):
|
||||
progress['replacement_requested'] = {'at': policy.local_now(now).isoformat(), 'reason': reason}
|
||||
book = parent.get('book_id') if settings.INFRA_STRATEGY_BOOK_SCHEMA else books.ORIGINAL
|
||||
if book not in (books.MICRO, books.ORIGINAL):
|
||||
raise ValueError('父指令所属策略无法核实')
|
||||
with books.scope(book):
|
||||
if not pms_repo.update_instruction(parent_id, progress=progress):
|
||||
raise RuntimeError('撤换请求没有写入父指令')
|
||||
result = dispatcher.cancel(instruction_id=parent_id, dispatch_ref=parent.get('dispatch_ref'))
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ HERE = os.path.dirname(os.path.abspath(__file__))
|
|||
ROOT = os.path.dirname(HERE)
|
||||
# 退出纪律专项:两次独立清仓信号、评级下降、事务、双策略隔离及撤单收尾。
|
||||
SUITES = [
|
||||
'test_intraday_rotation.py', # 单日轮动授权、50个席位和委托出口(7例)
|
||||
'test_intraday_rotation.py', # 单日轮动授权、50个席位、撤换和委托出口(8例)
|
||||
"test_business_evidence.py", # 历史准备覆盖与嵌套业务失败(21例)
|
||||
"test_signal_health.py", # 资金监测可用性与交易员提示,7例
|
||||
"test_proposal_trader_view.py", # 当前分析、数据库读数保存及旧确认保护(21例)
|
||||
|
|
|
|||
|
|
@ -111,6 +111,29 @@ class IntradayEntry(TestCase):
|
|||
self.order['qty']=40
|
||||
self.assertFalse(entry.blocker(self.parent,self.order,self.now))
|
||||
|
||||
def test_replace_writes_only_own_book_before_cancel(self):
|
||||
from app.core import strategy_book as books
|
||||
from app.services import dispatcher
|
||||
self.mock(eo,'account_guard',side_effect=nullcontext)
|
||||
self.mock(eo.pms_repo,'get_instruction',return_value=self.parent)
|
||||
writes=[]
|
||||
def save(iid,progress):
|
||||
sql = books.scoped_sql("UPDATE pms_instruction SET progress_json=:progress WHERE instruction_id=:iid")
|
||||
writes.append(sql)
|
||||
self.assertIn('replacement_requested',progress)
|
||||
return 1
|
||||
self.mock(eo.pms_repo,'update_instruction',side_effect=save)
|
||||
cancel=self.mock(dispatcher,'cancel',return_value={'ok':True})
|
||||
self.mock(eo,'replacement_state',return_value={'ready':False})
|
||||
result=eo.request_replace('p','报价过期',self.now)
|
||||
self.assertFalse(result['ready'])
|
||||
self.assertIn("book_id = 'micro30'",writes[0])
|
||||
cancel.assert_called_once()
|
||||
self.parent['book_id']='unknown'
|
||||
with self.assertRaises(ValueError):
|
||||
eo.request_replace('p','报价过期',self.now)
|
||||
self.assertEqual(cancel.call_count,1)
|
||||
|
||||
def test_ban_removal_does_not_remove_other_ban(self):
|
||||
rows=self.mock(entry.repo.db,'fetch_all',return_value=[{'cmd_type':t} for t in
|
||||
('UNFREEZE_STOCK','BLACKLIST_ADD','FREEZE_STOCK')])
|
||||
|
|
|
|||
Loading…
Reference in New Issue