2026-09-04 19:48:47 +08:00
|
|
|
|
from dataclasses import asdict, is_dataclass
|
|
|
|
|
|
from datetime import date, datetime
|
|
|
|
|
|
from enum import Enum
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COLLECTOR_URL = "http://139.224.247.176:13499/collector"
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-09-07 14:04:26 +08:00
|
|
|
|
def submit_trend_data() -> None:
|
|
|
|
|
|
"""每五分钟提交趋势策略的最新缓存,尚无快照时跳过。"""
|
|
|
|
|
|
from strategy.trend.boot import get_collector_snapshot
|
|
|
|
|
|
|
|
|
|
|
|
snapshot = get_collector_snapshot()
|
|
|
|
|
|
if snapshot is not None:
|
|
|
|
|
|
collector_push(*snapshot)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-09-04 19:48:47 +08:00
|
|
|
|
def _json_value(value: Any) -> Any:
|
|
|
|
|
|
"""Convert the QMT model values into values accepted by a JSON encoder."""
|
|
|
|
|
|
if is_dataclass(value) and not isinstance(value, type):
|
|
|
|
|
|
return _json_value(asdict(value))
|
|
|
|
|
|
if isinstance(value, dict):
|
|
|
|
|
|
return {str(key): _json_value(item) for key, item in value.items()}
|
|
|
|
|
|
if isinstance(value, (list, tuple, set)):
|
|
|
|
|
|
return [_json_value(item) for item in value]
|
|
|
|
|
|
if isinstance(value, Enum):
|
|
|
|
|
|
return _json_value(value.value)
|
|
|
|
|
|
if isinstance(value, (datetime, date)):
|
|
|
|
|
|
return value.isoformat()
|
|
|
|
|
|
if value is None or isinstance(value, (str, int, float, bool)):
|
|
|
|
|
|
return value
|
|
|
|
|
|
return str(value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def collector_push(account_id: str, assets: Any, positions: Any) -> None:
|
2026-09-07 14:04:26 +08:00
|
|
|
|
"""[暂停] 数据收集提交,太耗时,超过200毫秒."""
|
2026-09-04 19:48:47 +08:00
|
|
|
|
try:
|
|
|
|
|
|
payload = _json_value(
|
|
|
|
|
|
{
|
|
|
|
|
|
"account_id": account_id,
|
|
|
|
|
|
"assets": assets,
|
|
|
|
|
|
"positions": positions,
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
httpx.post(COLLECTOR_URL, json=payload, timeout=3.0)
|
|
|
|
|
|
except BaseException:
|
|
|
|
|
|
# Collection must never interrupt or affect the trading workflow.
|
|
|
|
|
|
pass
|