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,10 @@
from __future__ import annotations
from datetime import datetime
from dataclasses import dataclass, field
from typing import Any
from functools import lru_cache
_SIDES = {"23": "BUY", "24": "SELL", "48": "BUY", "49": "SELL"}
def _number(value: Any, kind: type = float) -> Any:
@@ -40,6 +43,9 @@ class OrderItem:
def get_local_order_id(self) -> str:
return self.remark.split("|", 1)[0]
# Keep the existing property name available to SDK callers.
local_order_id = get_local_order_id
@property
def created_at(self) -> datetime | None:
return _parse_datetime(self.insert_date, self.insert_time)
@@ -71,6 +77,8 @@ class DealItem:
def get_local_order_id(self) -> str:
return self.remark.split("|", 1)[0]
local_order_id = get_local_order_id
@dataclass(slots=True)
class PositionItem:
@@ -111,9 +119,10 @@ class Portfolio:
def _side(offset_flag: int) -> str:
return {"23": "BUY", "24": "SELL", "48": "BUY", "49": "SELL"}.get(str(offset_flag), "")
return _SIDES.get(str(offset_flag), "")
@lru_cache(maxsize=4096)
def _parse_datetime(date: str, clock: str) -> datetime | None:
clock = clock.replace(":", "").zfill(6)
try:
@@ -129,7 +138,7 @@ class Tick:
raw: dict[str, Any] = field(default_factory=dict)
@classmethod
def from_dict(cls, data: Any) -> "Tick":
def from_dict(cls, data: Any) -> Tick:
if not isinstance(data, dict):
return cls()
return cls(