fix bug
This commit is contained in:
BIN
py-client/libs/__pycache__/collector.cpython-311.pyc
Normal file
BIN
py-client/libs/__pycache__/collector.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/libs/__pycache__/dataset.cpython-311.pyc
Normal file
BIN
py-client/libs/__pycache__/dataset.cpython-311.pyc
Normal file
Binary file not shown.
42
py-client/libs/collector.py
Normal file
42
py-client/libs/collector.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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"
|
||||
|
||||
|
||||
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:
|
||||
"""Best-effort collector upload; never propagate errors to the caller."""
|
||||
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
|
||||
@@ -1,3 +0,0 @@
|
||||
|
||||
def dataset_push(assets:any,positions:any):
|
||||
pass
|
||||
@@ -26,7 +26,6 @@ def refresh_market(api_host: str = API_HOST) -> str:
|
||||
result = status(get_json(url, HTTP_TIMEOUT))
|
||||
except Exception as exc:
|
||||
result = "UNKNOWN"
|
||||
logging.error("获取大盘指数失败: %s %s", url, exc)
|
||||
with _market_lock:
|
||||
_market_status = result
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user