fix: sync live TP/SL to position cards after entrust changes

Use exchange TP/SL for display and DB sync on price_snapshot polls, refresh instance UI cells on each tick, and merge live values into hub monitor board.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-09 11:06:27 +08:00
parent 7cb55f6557
commit f7d94f67d7
12 changed files with 291 additions and 89 deletions
+20 -1
View File
@@ -140,6 +140,7 @@ from key_monitor_lib import (
from order_monitor_display_lib import (
apply_order_price_display_fields,
enrich_order_display_fields,
order_monitor_tpsl_needs_sync,
)
from wechat_notify_lib import build_wechat_rs_level_message, send_wechat_webhook
from hub_auth import request_allowed as hub_request_allowed
@@ -5935,7 +5936,6 @@ def api_price_snapshot():
order_rows = conn.execute(
"SELECT id,symbol,exchange_symbol,direction,trigger_price,stop_loss,initial_stop_loss,take_profit,margin_capital,leverage FROM order_monitors WHERE status='active'"
).fetchall()
conn.close()
try:
ensure_markets_loaded()
@@ -6122,9 +6122,28 @@ def api_price_snapshot():
take_profit=r["take_profit"],
calc_rr_ratio_fn=calc_rr_ratio,
exchange_tpsl=exchange_tpsl,
format_price_fn=format_price_for_symbol,
symbol=r["symbol"],
)
new_sl, new_tp, changed = order_monitor_tpsl_needs_sync(
r["stop_loss"], r["take_profit"], exchange_tpsl
)
if changed:
try:
conn.execute(
"UPDATE order_monitors SET stop_loss=?, take_profit=? WHERE id=?",
(new_sl, new_tp, int(r["id"])),
)
except Exception:
pass
order_prices.append(payload)
try:
conn.commit()
except Exception:
pass
conn.close()
from hub_position_metrics import build_position_marks_list
position_marks = build_position_marks_list(