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,5 +1,3 @@
from __future__ import annotations
import json
from dataclasses import asdict, is_dataclass
from typing import Any
@@ -33,13 +31,13 @@ class HTTPClient:
def close(self) -> None:
self.http.close()
def __enter__(self) -> "HTTPClient":
def __enter__(self) -> HTTPClient:
return self
def __exit__(self, *_args: object) -> None:
self.close()
def set_account_type(self, account_type: str) -> "HTTPClient":
def set_account_type(self, account_type: str) -> HTTPClient:
if account_type.strip():
self.account_type = account_type
return self

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
from typing import Any

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
from .models import Tick

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
from typing import Any
from urllib.parse import urlencode

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(

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
from typing import Any
from .models import Assets, DealItem, OrderItem, Portfolio, PositionItem

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
from typing import Any

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
from typing import Any