Fix roll position display: live contracts, TP profit, and 2-decimal qty precision.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-08 17:06:33 +08:00
parent 5ef6affabf
commit e3e53ff7f5
15 changed files with 217 additions and 33 deletions
+16 -2
View File
@@ -492,9 +492,23 @@ def _roll_execute(cfg: dict, data: dict) -> tuple[bool, str]:
"UPDATE roll_groups SET leg_count=?, current_stop_loss=?, updated_at=? WHERE id=?",
(legs_done + 1, new_sl, cfg["app_now_str"](), rg["id"]),
)
live_qty = float(mon.get("order_amount") or 0) + float(amount)
try:
from lib.hub.hub_position_metrics import contracts_qty_is_open, normalize_contracts_qty
pos2 = cfg["get_position"](ex_sym, direction) or {}
q2 = normalize_contracts_qty(pos2.get("contracts") or 0)
if contracts_qty_is_open(q2):
live_qty = q2
else:
live_qty = normalize_contracts_qty(live_qty)
except Exception:
from lib.hub.hub_position_metrics import normalize_contracts_qty
live_qty = normalize_contracts_qty(live_qty)
conn.execute(
"UPDATE order_monitors SET stop_loss=? WHERE id=?",
(new_sl, mon["id"]),
"UPDATE order_monitors SET stop_loss=?, order_amount=? WHERE id=?",
(new_sl, live_qty, mon["id"]),
)
conn.commit()
_maybe_notify_roll_started(cfg, rg, mon, symbol, direction, tp0, new_sl, roll_is_new=roll_is_new)