fix bug
This commit is contained in:
@@ -10,15 +10,13 @@ from threading import Lock
|
||||
from typing import Iterable
|
||||
|
||||
from sdk import OrderItem, PositionItem
|
||||
from .order import BUSY_STATUSES, COMPLETED_STATUSES
|
||||
|
||||
|
||||
# 委托状态:无操作、处理中、已完成。
|
||||
STATUS_NONE = ""
|
||||
STATUS_ING = "ING"
|
||||
STATUS_OK = "OK"
|
||||
STATUS_FAILED = "FAILED"
|
||||
STATUS_CANCELED = "CANCELED"
|
||||
STATUS_UNKNOWN = "UNKNOWN"
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -106,6 +104,7 @@ class State:
|
||||
|
||||
self.set(
|
||||
StateItem(
|
||||
base_order_id=position.trade_id,
|
||||
code=position.stock_code,
|
||||
base_qty=position.volume,
|
||||
base_cost=round(position.open_price, 2),
|
||||
@@ -143,22 +142,14 @@ class State:
|
||||
):
|
||||
local_order_id = getattr(item, order_id_attr)
|
||||
current_status = getattr(item, status_attr)
|
||||
if (
|
||||
current_status not in {STATUS_ING, STATUS_UNKNOWN}
|
||||
or not local_order_id
|
||||
):
|
||||
if current_status != STATUS_ING or not local_order_id:
|
||||
continue
|
||||
|
||||
matching_orders = orders_by_local_id.get(local_order_id)
|
||||
if matching_orders:
|
||||
status = (
|
||||
STATUS_OK
|
||||
if all(order.status == "56" for order in matching_orders)
|
||||
else STATUS_ING
|
||||
)
|
||||
if status != current_status:
|
||||
log.info("[状态] %s 订单=%s,状态=%s->%s", code, local_order_id, current_status, status)
|
||||
setattr(item, status_attr, status)
|
||||
status = _order_status(matching_orders)
|
||||
if status != current_status:
|
||||
log.info("[状态] %s 订单=%s,状态=%s->%s", code, local_order_id, current_status, status)
|
||||
setattr(item, status_attr, status)
|
||||
self.set(item)
|
||||
|
||||
# Opening orders normally have no position until their first fill. Order
|
||||
@@ -209,3 +200,15 @@ class State:
|
||||
}
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ValueError(f"[状态] 状态字段无效: {exc}") from exc
|
||||
|
||||
|
||||
def _order_status(orders: list[OrderItem] | None) -> str:
|
||||
"""将柜台订单简化为无状态、处理中或已成交。"""
|
||||
if not orders:
|
||||
return STATUS_NONE
|
||||
statuses = {order.status for order in orders}
|
||||
if statuses <= COMPLETED_STATUSES:
|
||||
return STATUS_OK
|
||||
if statuses <= BUSY_STATUSES | COMPLETED_STATUSES:
|
||||
return STATUS_ING
|
||||
return STATUS_NONE
|
||||
|
||||
Reference in New Issue
Block a user