机器对比改为模拟在上实盘在下,收益率按已结算盈亏相对初始资金计算。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -90,6 +90,50 @@ def record_cash_samples_from_overview(rows: list[dict[str, Any]]) -> int:
|
||||
return len(to_write)
|
||||
|
||||
|
||||
def first_cash_by_instance(instance_ids: list[Any] | None = None) -> dict[Any, float]:
|
||||
"""各机最早一笔现金采样,作初始资金回退(实盘未配 LIVE_INITIAL 时)."""
|
||||
conn = get_db()
|
||||
try:
|
||||
if instance_ids:
|
||||
ids: list[int] = []
|
||||
for x in instance_ids:
|
||||
try:
|
||||
ids.append(int(x))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if not ids:
|
||||
return {}
|
||||
placeholders = ",".join("?" * len(ids))
|
||||
rows = conn.execute(
|
||||
f"""
|
||||
SELECT instance_id, cash_usdt
|
||||
FROM hub_cash_samples
|
||||
WHERE instance_id IN ({placeholders})
|
||||
ORDER BY ts_ms ASC
|
||||
""",
|
||||
tuple(ids),
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT instance_id, cash_usdt
|
||||
FROM hub_cash_samples
|
||||
ORDER BY ts_ms ASC
|
||||
"""
|
||||
).fetchall()
|
||||
finally:
|
||||
conn.close()
|
||||
out: dict[Any, float] = {}
|
||||
for r in rows:
|
||||
iid = r["instance_id"]
|
||||
if iid in out:
|
||||
continue
|
||||
v = _safe_float(r["cash_usdt"])
|
||||
if v is not None and v > 0:
|
||||
out[iid] = round(v, 4)
|
||||
return out
|
||||
|
||||
|
||||
def query_cash_series(
|
||||
*,
|
||||
range_key: str = "7d",
|
||||
|
||||
Reference in New Issue
Block a user