26 lines
1010 B
Python
26 lines
1010 B
Python
|
|
"""执行依据只更新独立JSON字段,避免刷新任务覆盖委托进度。"""
|
|||
|
|
import json
|
|||
|
|
from app.db import session as db
|
|||
|
|
|
|||
|
|
|
|||
|
|
def save_basis(instruction_id, value):
|
|||
|
|
affected = db.execute("UPDATE pms_instruction SET progress_json=JSON_SET("
|
|||
|
|
"COALESCE(progress_json,JSON_OBJECT()),'$.execution_basis_cache',JSON_EXTRACT(:body,'$')) "
|
|||
|
|
"WHERE instruction_id=:iid", {'iid': instruction_id, 'body': json.dumps(value, ensure_ascii=False)})
|
|||
|
|
if not affected:
|
|||
|
|
raise RuntimeError('执行依据缓存没有写入父指令')
|
|||
|
|
|
|||
|
|
|
|||
|
|
def pending_trades(child_ids):
|
|||
|
|
if not child_ids:
|
|||
|
|
return 0
|
|||
|
|
args = {'p': 0, 'orphan': 3}
|
|||
|
|
keys = []
|
|||
|
|
for index, iid in enumerate(child_ids):
|
|||
|
|
key = 'c'+str(index)
|
|||
|
|
args[key] = iid
|
|||
|
|
keys.append(':'+key)
|
|||
|
|
row = db.fetch_one("SELECT COUNT(*) AS n FROM pms_qmt_inbox WHERE msg_type='trade' "
|
|||
|
|
"AND processed IN (:p,:orphan) AND corr_id IN ("+','.join(keys)+')', args)
|
|||
|
|
return int((row or {}).get('n') or 0)
|