This commit is contained in:
2026-09-07 21:22:51 +08:00
parent 9778d54f3d
commit ba61ed5de7
28 changed files with 303 additions and 64 deletions

View File

@@ -1,7 +1,5 @@
"""策略共用委托簿。"""
from __future__ import annotations
import secrets
from dataclasses import dataclass
from datetime import datetime, timedelta
@@ -69,17 +67,19 @@ class OrderBook:
canceled = 0
for item in orders:
status = str(item.order_status)
# 不处理状态不对的
if str(item.order_status) not in TRACKED_STATUSES:
if status not in TRACKED_STATUSES:
continue
if str(item.order_status) in BUSY_STATUSES:
if status in BUSY_STATUSES:
busy_keys.add(self._busy_key(item.side, item.stock_code))
# 清理过期的
created_at = item.created_at
if (
item.created_at is not None
created_at is not None
and item.local_order_id.startswith(f"{self.order_prefix}-")
and str(item.order_status) in CANCELABLE_STATUSES
and current - item.created_at > self.cancel_timeout_sec
and status in CANCELABLE_STATUSES
and current - created_at > self.cancel_timeout_sec
):
try:
client.cancel_by_id(item.order_sys_id)