feat: add hub fund overview tab with 180-day equity curves
Add /funds page for total and per-account balance (funding+trading), drawdown, and daily snapshots from monitor board aggregation. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
"""hub_fund_history_lib:总资金、回撤与日快照。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from hub_fund_history_lib import (
|
||||
account_total_usdt,
|
||||
build_fund_overview,
|
||||
compute_drawdown,
|
||||
record_fund_snapshot,
|
||||
)
|
||||
|
||||
|
||||
def test_account_total_requires_both_sides():
|
||||
assert account_total_usdt(10, 20) == 30.0
|
||||
assert account_total_usdt(10, None) is None
|
||||
assert account_total_usdt(None, 5) is None
|
||||
|
||||
|
||||
def test_compute_drawdown():
|
||||
dd = compute_drawdown([100, 120, 90, 110])
|
||||
assert dd["peak_usdt"] == 120.0
|
||||
assert dd["max_drawdown_u"] == 30.0
|
||||
assert dd["max_drawdown_pct"] == 25.0
|
||||
|
||||
|
||||
def test_build_fund_overview_skips_unmonitored(tmp_path, monkeypatch):
|
||||
hist_path = tmp_path / "hub_fund_history.json"
|
||||
monkeypatch.setattr("hub_fund_history_lib.FUND_HISTORY_PATH", hist_path)
|
||||
record_fund_snapshot(
|
||||
"2026-06-01",
|
||||
[
|
||||
{
|
||||
"key": "binance",
|
||||
"name": "Binance",
|
||||
"funding_usdt": 10,
|
||||
"trading_usdt": 20,
|
||||
"monitored": True,
|
||||
}
|
||||
],
|
||||
keep_days=180,
|
||||
)
|
||||
record_fund_snapshot(
|
||||
"2026-06-02",
|
||||
[
|
||||
{
|
||||
"key": "binance",
|
||||
"name": "Binance",
|
||||
"funding_usdt": 12,
|
||||
"trading_usdt": 18,
|
||||
"monitored": True,
|
||||
}
|
||||
],
|
||||
keep_days=180,
|
||||
)
|
||||
exchanges = [
|
||||
{"id": "0", "key": "binance", "name": "Binance", "enabled": True},
|
||||
{"id": "3", "key": "gate_bot", "name": "Gate Bot", "enabled": False},
|
||||
]
|
||||
board_rows = [
|
||||
{
|
||||
"key": "binance",
|
||||
"name": "Binance",
|
||||
"account_ok": True,
|
||||
"funding_usdt": 15,
|
||||
"trading_usdt": 25,
|
||||
}
|
||||
]
|
||||
out = build_fund_overview(
|
||||
exchanges,
|
||||
board_rows=board_rows,
|
||||
trading_day="2026-06-02",
|
||||
keep_days=180,
|
||||
)
|
||||
assert out["totals"]["total_usdt"] == 40.0
|
||||
assert out["totals"]["monitored_count"] == 1
|
||||
assert len(out["accounts"]) == 2
|
||||
off = next(a for a in out["accounts"] if a["key"] == "gate_bot")
|
||||
assert off["monitored"] is False
|
||||
assert off["total_usdt"] is None
|
||||
assert out["totals"]["drawdown"]["max_drawdown_u"] == 0.0
|
||||
Reference in New Issue
Block a user