feat: 持仓快照盈亏比与交易所止损已保本标识
盈亏比固定用开仓 initial_stop_loss 计算,人工改委托后不变化;轮询交易所止损触发价相对成交价判定已保本,四所实例与中控统一显示绿色标识。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -601,6 +601,31 @@ def _find_exchange_tpsl_for_position(
|
||||
return None
|
||||
|
||||
|
||||
def _merge_flask_order_price_fields(hub_mon: dict | None, snap: dict | None) -> None:
|
||||
"""将 price_snapshot 中的快照盈亏比、已保本状态合并进 hub_monitor.orders。"""
|
||||
if not isinstance(hub_mon, dict) or not isinstance(snap, dict):
|
||||
return
|
||||
order_prices = snap.get("order_prices") or []
|
||||
op_by_id = {
|
||||
op.get("id"): op
|
||||
for op in order_prices
|
||||
if isinstance(op, dict) and op.get("id") is not None
|
||||
}
|
||||
orders = hub_mon.get("orders") or []
|
||||
if not isinstance(orders, list):
|
||||
return
|
||||
for o in orders:
|
||||
if not isinstance(o, dict):
|
||||
continue
|
||||
op = op_by_id.get(o.get("id"))
|
||||
if not isinstance(op, dict):
|
||||
continue
|
||||
if op.get("rr_ratio") is not None:
|
||||
o["rr_ratio"] = op["rr_ratio"]
|
||||
if "sl_breakeven_secured" in op:
|
||||
o["sl_breakeven_secured"] = bool(op["sl_breakeven_secured"])
|
||||
|
||||
|
||||
def _merge_flask_exchange_tpsl(agent_row: dict, snap: dict | None, hub_mon: dict | None) -> None:
|
||||
"""子代理挂单为空时,用实例 Flask 已算好的 exchange_tpsl 补全展示。"""
|
||||
ag = agent_row.get("agent")
|
||||
@@ -656,6 +681,8 @@ async def _assemble_board_row(
|
||||
client: httpx.AsyncClient, ex: dict, agent_row: dict
|
||||
) -> dict:
|
||||
hub_mon, meta, key_prices, snap = await _fetch_exchange_flask_bundle(client, ex)
|
||||
if isinstance(hub_mon, dict):
|
||||
_merge_flask_order_price_fields(hub_mon, snap)
|
||||
_merge_flask_exchange_tpsl(agent_row, snap, hub_mon if isinstance(hub_mon, dict) else None)
|
||||
flask_ok = isinstance(hub_mon, dict) and hub_mon.get("ok") is not False
|
||||
raw_review = (ex.get("review_url") or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user