feat dev6

This commit is contained in:
2026-09-01 14:28:49 +08:00
parent dedbf63a92
commit 556e21d624
27 changed files with 334 additions and 144 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import json
import logging as log
from dataclasses import asdict, dataclass
from pathlib import Path
from threading import Lock
@@ -93,6 +94,7 @@ class State:
立即保存,确保首次接管的持仓在程序重启后仍可恢复。
"""
known_codes = set(self.codes)
imported = 0
for position in positions:
if (
not position.stock_code
@@ -111,8 +113,11 @@ class State:
)
)
known_codes.add(position.stock_code)
imported += 1
self.save()
if imported:
log.info("[状态] 导入持仓=%d,状态总数=%d", imported, len(known_codes))
def reconcile(
self,
@@ -151,6 +156,8 @@ class State:
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)
self.set(item)
@@ -158,7 +165,8 @@ class State:
# reconciliation must therefore happen before stale state is removed.
for code in list(self.codes):
if code not in position_codes:
self.delete(code)
if self.delete(code):
log.info("[状态] 已移除持仓状态,代码=%s", code)
self.save()
def save(self) -> None: