22 lines
1.0 KiB
Python
22 lines
1.0 KiB
Python
"""网格库存从原策略真实批次读取;不靠触发价或委托数量推定成交。"""
|
|
from app.core import grid_inventory as core, strategy_book as books
|
|
from app.repo import pms_repo
|
|
|
|
|
|
def snapshot(strategy, position):
|
|
with books.scope('original'):
|
|
lots = pms_repo.list_lots(strategy['ts_code'], limit=10001)
|
|
if len(lots) >= 10001:
|
|
raise ValueError('网格批次数超过核验上限')
|
|
parents = {}
|
|
for lot in lots:
|
|
if int(lot.get('qty') or 0) > 0 and lot.get('lot_type') == 'ADD':
|
|
iid = lot.get('instruction_id')
|
|
if iid not in parents:
|
|
parents[iid] = pms_repo.get_instruction(iid) if iid else None
|
|
result = core.project(strategy, lots, parents)
|
|
actual = sum(r['qty'] for r in result['filled_levels'].values())
|
|
if actual != int(position.get('add_qty') or 0) or actual > int(position.get('total_qty') or 0):
|
|
raise ValueError('网格批次数量与持仓增量不一致,等待正常成交入账或对账')
|
|
return result
|