Improve dashboard responsive layout, collapsible risk section, and breakeven badge.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-29 22:50:48 +08:00
parent 8b4b1a875c
commit d1ad0f9253
5 changed files with 543 additions and 14 deletions
+34
View File
@@ -166,6 +166,33 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
"symbol_is_main": bool(meta.get("is_main")),
}
def _breakeven_locked(
*,
entry: Optional[float],
stop_loss: Optional[float],
direction: str,
tick_size: Optional[float] = None,
trailing_r_locked: int = 0,
) -> bool:
if int(trailing_r_locked or 0) >= 1:
return True
if entry is None or stop_loss is None:
return False
try:
entry_f = float(entry)
sl_f = float(stop_loss)
except (TypeError, ValueError):
return False
if entry_f <= 0:
return False
tick = float(tick_size or 0) or max(abs(entry_f) * 1e-6, 0.01)
buf = tick * max(2, get_trailing_be_tick_buffer(get_setting))
d = (direction or "long").strip().lower()
near = abs(sl_f - entry_f) <= buf + tick
if d == "long":
return near and sl_f >= entry_f - tick * 0.05
return near and sl_f <= entry_f + tick * 0.05
def _schedule_recommend_refresh() -> None:
from db_conn import DB_PATH
@@ -1208,6 +1235,13 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
"pending_orders": pending_for_row,
"trailing_be": bool(mon.get("trailing_be")) if mon else False,
"trailing_r_locked": int(mon.get("trailing_r_locked") or 0) if mon else 0,
"breakeven_locked": _breakeven_locked(
entry=entry,
stop_loss=sl,
direction=direction,
tick_size=tick.get("tick_size"),
trailing_r_locked=int(mon.get("trailing_r_locked") or 0) if mon else 0,
),
}
def _compose_pending_row(