feat数据统计曲线改为各机累计已实现盈亏叠加,不再用余额采样。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -325,6 +325,77 @@ def pull_all_stats(window: str = "7d") -> list[dict[str, Any]]:
|
||||
return results
|
||||
|
||||
|
||||
def fetch_one_pnl_curve(inst: dict[str, Any], *, range_key: str = "7d") -> dict[str, Any]:
|
||||
"""拉取单机累计已实现盈亏曲线."""
|
||||
base = (inst.get("base_url") or "").rstrip("/")
|
||||
token = (inst.get("bridge_token") or "").strip()
|
||||
out: dict[str, Any] = {
|
||||
"id": inst.get("id"),
|
||||
"name": inst.get("name"),
|
||||
"online": False,
|
||||
"error": "",
|
||||
"points": [],
|
||||
"trade_count": 0,
|
||||
"latest": None,
|
||||
"metric": "realized_pnl",
|
||||
}
|
||||
if not base or not token:
|
||||
out["error"] = "缺少 URL 或 Token"
|
||||
return out
|
||||
url = f"{base}/api/hub/options/pnl_curve"
|
||||
try:
|
||||
r = requests.get(
|
||||
url,
|
||||
headers={"X-Hub-Token": token, "Accept": "application/json"},
|
||||
params={"range": range_key},
|
||||
timeout=max(_timeout(), 15.0),
|
||||
)
|
||||
data = {}
|
||||
try:
|
||||
data = r.json()
|
||||
except Exception:
|
||||
data = {}
|
||||
if r.status_code != 200 or not isinstance(data, dict) or not data.get("ok"):
|
||||
out["error"] = (data.get("msg") if isinstance(data, dict) else None) or f"HTTP {r.status_code}"
|
||||
return out
|
||||
out["online"] = True
|
||||
pts = data.get("points") if isinstance(data.get("points"), list) else []
|
||||
out["points"] = pts
|
||||
out["trade_count"] = int(data.get("trade_count") or 0)
|
||||
out["latest"] = data.get("latest")
|
||||
out["metric"] = data.get("metric") or "realized_pnl"
|
||||
out["start_ms"] = data.get("start_ms")
|
||||
out["end_ms"] = data.get("end_ms")
|
||||
return out
|
||||
except requests.Timeout:
|
||||
out["error"] = "超时"
|
||||
return out
|
||||
except Exception as e:
|
||||
out["error"] = str(e) or "拉取失败"
|
||||
return out
|
||||
|
||||
|
||||
def pull_all_pnl_curves(range_key: str = "7d") -> list[dict[str, Any]]:
|
||||
instances = list_instances(enabled_only=True)
|
||||
if not instances:
|
||||
return []
|
||||
results: list[dict[str, Any]] = []
|
||||
with ThreadPoolExecutor(max_workers=min(8, len(instances))) as pool:
|
||||
futs = {
|
||||
pool.submit(fetch_one_pnl_curve, inst, range_key=range_key): inst["id"]
|
||||
for inst in instances
|
||||
}
|
||||
by_id: dict[Any, dict[str, Any]] = {}
|
||||
for fut in as_completed(futs):
|
||||
row = fut.result()
|
||||
by_id[row.get("id")] = row
|
||||
for inst in instances:
|
||||
results.append(
|
||||
by_id.get(inst["id"]) or fetch_one_pnl_curve(inst, range_key=range_key)
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def fetch_client_version(inst: dict[str, Any]) -> dict[str, Any]:
|
||||
"""探测客户端 git 版本 / 在线."""
|
||||
base = (inst.get("base_url") or "").rstrip("/")
|
||||
|
||||
Reference in New Issue
Block a user