feat: 持仓快照盈亏比与交易所止损已保本标识
盈亏比固定用开仓 initial_stop_loss 计算,人工改委托后不变化;轮询交易所止损触发价相对成交价判定已保本,四所实例与中控统一显示绿色标识。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+19
-19
@@ -94,6 +94,10 @@ from key_monitor_lib import (
|
||||
rs_break_from_direction,
|
||||
run_rs_level_alert_tick,
|
||||
)
|
||||
from order_monitor_display_lib import (
|
||||
apply_order_price_display_fields,
|
||||
enrich_order_display_fields,
|
||||
)
|
||||
from wechat_notify_lib import build_wechat_rs_level_message, send_wechat_webhook
|
||||
from hub_auth import request_allowed as hub_request_allowed
|
||||
from history_window_lib import (
|
||||
@@ -2126,13 +2130,7 @@ def enrich_order_item(raw_item, current_capital):
|
||||
ratio = round(margin / current_capital * 100, 2) if current_capital else 0
|
||||
item["notional_value"] = notional
|
||||
item["position_ratio"] = ratio
|
||||
item["rr_ratio"] = calc_planned_rr_ratio(
|
||||
item.get("direction") or "long",
|
||||
item.get("trigger_price"),
|
||||
item.get("stop_loss"),
|
||||
item.get("initial_stop_loss"),
|
||||
item.get("take_profit"),
|
||||
)
|
||||
enrich_order_display_fields(item, calc_rr_ratio)
|
||||
try:
|
||||
be = item.get("breakeven_enabled")
|
||||
item["breakeven_enabled"] = 0 if be is not None and int(be) == 0 else 1
|
||||
@@ -5934,13 +5932,7 @@ def api_price_snapshot():
|
||||
entry = float(r["trigger_price"] or 0)
|
||||
pnl = calc_pnl(r["direction"], entry, price, margin, leverage) if entry > 0 else 0
|
||||
pnl_pct = round((pnl / margin * 100), 4) if margin > 0 else 0
|
||||
rr_ratio = calc_planned_rr_ratio(
|
||||
r["direction"],
|
||||
entry,
|
||||
r["stop_loss"],
|
||||
r["initial_stop_loss"],
|
||||
r["take_profit"],
|
||||
)
|
||||
exchange_tpsl = {"sl": None, "tp": None}
|
||||
ex_sym = resolve_monitor_exchange_symbol(r)
|
||||
prow = _select_live_position_row(all_swap_positions, ex_sym, r["direction"])
|
||||
lev_row = r["leverage"] if "leverage" in r.keys() else None
|
||||
@@ -5950,7 +5942,6 @@ def api_price_snapshot():
|
||||
"symbol": r["symbol"],
|
||||
"float_pnl": round(pnl, 2),
|
||||
"float_pct": pnl_pct,
|
||||
"rr_ratio": rr_ratio,
|
||||
"plan_margin": round(margin, 2) if margin else None,
|
||||
"exchange_initial_margin": None,
|
||||
"exchange_notional": None,
|
||||
@@ -5985,16 +5976,25 @@ def api_price_snapshot():
|
||||
payload["price_display"] = px_disp
|
||||
if exchange_private_api_configured():
|
||||
try:
|
||||
payload["exchange_tpsl"] = fetch_exchange_tpsl_slots(
|
||||
exchange_tpsl = fetch_exchange_tpsl_slots(
|
||||
ex_sym,
|
||||
r["direction"],
|
||||
plan_sl=r["stop_loss"],
|
||||
plan_tp=r["take_profit"],
|
||||
)
|
||||
except Exception:
|
||||
payload["exchange_tpsl"] = {"sl": None, "tp": None}
|
||||
else:
|
||||
payload["exchange_tpsl"] = {"sl": None, "tp": None}
|
||||
exchange_tpsl = {"sl": None, "tp": None}
|
||||
payload["exchange_tpsl"] = exchange_tpsl
|
||||
apply_order_price_display_fields(
|
||||
payload,
|
||||
direction=r["direction"],
|
||||
entry_price=entry,
|
||||
initial_stop_loss=r["initial_stop_loss"],
|
||||
stop_loss=r["stop_loss"],
|
||||
take_profit=r["take_profit"],
|
||||
calc_rr_ratio_fn=calc_rr_ratio,
|
||||
exchange_tpsl=exchange_tpsl,
|
||||
)
|
||||
order_prices.append(payload)
|
||||
|
||||
return jsonify({
|
||||
|
||||
Reference in New Issue
Block a user