Show initial and current roll position size plus rolling status on active roll groups table.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 16:45:32 +08:00
parent f5f302b97e
commit 5ef6affabf
4 changed files with 38 additions and 5 deletions
+11
View File
@@ -1629,6 +1629,17 @@ html[data-theme="light"] #strategy-roll-panel .roll-section-title {
color: #006e9a !important;
}
#strategy-roll-panel .roll-active-groups-table .roll-tp-profit,
#strategy-roll-panel .roll-active-groups-table .roll-status-active {
color: #4cd97f;
font-weight: 600;
}
html[data-theme="light"] #strategy-roll-panel .roll-active-groups-table .roll-tp-profit,
html[data-theme="light"] #strategy-roll-panel .roll-active-groups-table .roll-status-active {
color: #1a8f4a !important;
}
#roll-preview-box.roll-preview-box {
margin: 8px 0;
padding: 10px;
+18 -1
View File
@@ -106,7 +106,12 @@ def compute_roll_chain_metrics(
group_metrics: 最后一腿后的 {avg_entry, reward_at_tp_usdt}
"""
per_leg: dict[Any, dict] = {}
group_out: dict[str, Any] = {"avg_entry": None, "reward_at_tp_usdt": None}
group_out: dict[str, Any] = {
"avg_entry": None,
"reward_at_tp_usdt": None,
"initial_qty": None,
"current_qty": None,
}
if not isinstance(group, dict):
return per_leg, group_out
direction = (group.get("direction") or "long").strip().lower()
@@ -126,6 +131,8 @@ def compute_roll_chain_metrics(
return per_leg, group_out
qty = float(q0)
avg = float(e0)
group_out["initial_qty"] = round(qty, 4)
group_out["current_qty"] = round(qty, 4)
if tp > 0:
group_out["avg_entry"] = avg
group_out["reward_at_tp_usdt"] = reward_at_tp_usdt(
@@ -154,6 +161,14 @@ def compute_roll_chain_metrics(
}
group_out["avg_entry"] = round(avg, 10)
group_out["reward_at_tp_usdt"] = round(reward, 4) if reward is not None else None
group_out["current_qty"] = round(qty, 4)
if qty_live is not None:
try:
live_qty = float(qty_live)
if live_qty > 0:
group_out["current_qty"] = round(live_qty, 4)
except (TypeError, ValueError):
pass
return per_leg, group_out
@@ -264,6 +279,8 @@ def enrich_roll_page_data(conn, page_data: dict, cfg: dict | None) -> dict:
)
g["avg_entry"] = group_metrics.get("avg_entry")
g["reward_at_tp_usdt"] = group_metrics.get("reward_at_tp_usdt")
g["initial_qty"] = group_metrics.get("initial_qty")
g["current_qty"] = group_metrics.get("current_qty")
if callable(price_fmt) and g.get("avg_entry") is not None:
try:
g["avg_entry_display"] = price_fmt(g.get("symbol"), g["avg_entry"])
@@ -55,21 +55,24 @@
<h3 class="roll-section-title">活跃滚仓组</h3>
<div class="table-wrap">
<table>
<tr><th>ID</th><th>币种</th><th>方向</th><th>腿数</th><th>首仓TP</th><th>当前SL</th><th>当前均价</th><th>止盈盈利U</th></tr>
<table class="roll-active-groups-table">
<tr><th>ID</th><th>币种</th><th>方向</th><th>腿数</th><th>首仓张数</th><th>加仓后张数</th><th>首仓TP</th><th>当前SL</th><th>当前均价</th><th>止盈盈利U</th><th>状态</th></tr>
{% for g in roll_groups %}
<tr>
<td>{{ g.id }}</td>
<td>{{ g.symbol }}</td>
<td>{{ g.direction }}</td>
<td>{{ g.leg_count }}</td>
<td>{% if g.initial_qty is not none %}{{ '%.4g'|format(g.initial_qty) }}{% else %}—{% endif %}</td>
<td>{% if g.current_qty is not none %}{{ '%.4g'|format(g.current_qty) }}{% else %}—{% endif %}</td>
<td>{% if price_fmt %}{{ price_fmt(g.symbol, g.initial_take_profit) }}{% else %}{{ g.initial_take_profit }}{% endif %}</td>
<td>{% if price_fmt %}{{ price_fmt(g.symbol, g.current_stop_loss) }}{% else %}{{ g.current_stop_loss }}{% endif %}</td>
<td>{% if g.avg_entry_display %}{{ g.avg_entry_display }}{% elif g.avg_entry is not none %}{{ g.avg_entry }}{% else %}—{% endif %}</td>
<td>{% if g.reward_at_tp_usdt is not none %}{{ '%.2f'|format(g.reward_at_tp_usdt) }}{% else %}—{% endif %}</td>
<td class="roll-tp-profit">{% if g.reward_at_tp_usdt is not none %}{{ '%.2f'|format(g.reward_at_tp_usdt) }}{% else %}—{% endif %}</td>
<td class="roll-status-active">滚仓中</td>
</tr>
{% else %}
<tr><td colspan="8" style="color:#8892b0">暂无</td></tr>
<tr><td colspan="11" style="color:#8892b0">暂无</td></tr>
{% endfor %}
</table>
</div>
+2
View File
@@ -30,6 +30,8 @@ def test_compute_roll_chain_metrics_short():
assert per_leg[10]["avg_entry_after"] is not None
assert per_leg[11]["avg_entry_after"] is not None
assert group_metrics["reward_at_tp_usdt"] is not None
assert group_metrics["initial_qty"] == 3.0
assert group_metrics["current_qty"] == 8.0
assert per_leg[11]["reward_at_tp_usdt"] >= per_leg[10]["reward_at_tp_usdt"]