Fix mark/PnL display fallback and intraday entry labels
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -527,6 +527,12 @@ def register_hub_routes(app):
|
||||
od = apply_order_monitor_source_labels(od)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
from lib.trade.entry_model_lib import enrich_entry_model_display
|
||||
|
||||
enrich_entry_model_display(od)
|
||||
except Exception:
|
||||
pass
|
||||
orders.append(od)
|
||||
trends = []
|
||||
if c.get("has_trend"):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""price_snapshot 共用:订单行情价兜底,避免 get_price 失败时整单不入 order_prices。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Mapping, Optional
|
||||
from typing import Any, Callable, Mapping, Optional, Sequence
|
||||
|
||||
from lib.hub.hub_position_metrics import parse_position_mark_price
|
||||
|
||||
@@ -73,3 +73,52 @@ def resolve_order_snapshot_price(
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def seed_prices_from_positions(
|
||||
prices: dict[str, float],
|
||||
order_rows: Sequence[Any],
|
||||
all_positions: Sequence[dict[str, Any]],
|
||||
*,
|
||||
resolve_ex_sym_fn: Callable[[Any], str],
|
||||
) -> None:
|
||||
"""用持仓标记价补全 prices 字典(symbol 与 order_monitors 行对齐)。"""
|
||||
if not all_positions or not order_rows:
|
||||
return
|
||||
try:
|
||||
from lib.hub.hub_symbol_lib import symbols_match
|
||||
except Exception:
|
||||
symbols_match = None
|
||||
for r in order_rows:
|
||||
try:
|
||||
sym = str(r["symbol"] or "").strip()
|
||||
except (KeyError, TypeError, IndexError):
|
||||
sym = ""
|
||||
if not sym or sym in prices:
|
||||
continue
|
||||
try:
|
||||
ex_sym = resolve_ex_sym_fn(r)
|
||||
except Exception:
|
||||
ex_sym = sym
|
||||
try:
|
||||
direction = str(r["direction"] or "long").lower()
|
||||
except (KeyError, TypeError, IndexError):
|
||||
direction = "long"
|
||||
for p in all_positions:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
ps = p.get("symbol") or ""
|
||||
if not ps:
|
||||
continue
|
||||
matched = ps == sym or ps == ex_sym
|
||||
if not matched and symbols_match is not None:
|
||||
matched = symbols_match(sym, ps) or symbols_match(ex_sym, ps)
|
||||
if not matched:
|
||||
continue
|
||||
side = (p.get("side") or "").lower()
|
||||
if side and side != direction:
|
||||
continue
|
||||
mp = parse_position_mark_price(p)
|
||||
if mp is not None and mp > 0:
|
||||
prices[sym] = float(mp)
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user