fix: label trend breakeven handoff as 趋势回调 across four exchanges
Set order monitor and trade record source to trend pullback after handoff; unify hub and instance display; add migration script for legacy rows. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -81,8 +81,45 @@ def _row_monitor_type(row, default_manual: str) -> str:
|
||||
return default_manual
|
||||
|
||||
|
||||
def _row_key_signal_type(row) -> str:
|
||||
if row is None:
|
||||
return ""
|
||||
try:
|
||||
keys = row.keys() if hasattr(row, "keys") else []
|
||||
except Exception:
|
||||
keys = []
|
||||
if "key_signal_type" not in keys:
|
||||
return ""
|
||||
return (row["key_signal_type"] or "").strip()
|
||||
|
||||
|
||||
def order_monitor_source_type(row, *, default_manual: str = "下单监控") -> str:
|
||||
"""展示/平仓记录:趋势保本移交单来源为「趋势回调」,非「下单监控」。"""
|
||||
if trend_plan_id_from_monitor_row(row) is not None:
|
||||
return MONITOR_TYPE_TREND_PULLBACK
|
||||
mt = _row_monitor_type(row, default_manual)
|
||||
if mt != default_manual:
|
||||
return mt
|
||||
kst = _row_key_signal_type(row)
|
||||
if kst in (
|
||||
MONITOR_TYPE_TREND_PULLBACK,
|
||||
TREND_HANDOFF_KEY_SIGNAL,
|
||||
TREND_HANDOFF_TRADE_NOTE,
|
||||
ENTRY_REASON_TREND_PULLBACK,
|
||||
):
|
||||
return MONITOR_TYPE_TREND_PULLBACK
|
||||
return mt
|
||||
|
||||
|
||||
def apply_order_monitor_source_labels(item: dict, *, default_manual: str = "下单监控") -> dict:
|
||||
"""实例页 / 中控 API:统一修正 order_monitors 展示用 monitor_type。"""
|
||||
out = dict(item or {})
|
||||
out["monitor_type"] = order_monitor_source_type(out, default_manual=default_manual)
|
||||
return out
|
||||
|
||||
|
||||
def trade_record_monitor_type(conn, order_row, *, default_manual: str = "下单监控") -> str:
|
||||
"""平仓写入 trade_records 时:曾顺势加仓则标「顺势加仓」,否则沿用监控单类型。"""
|
||||
"""平仓写入 trade_records 时:曾顺势加仓则标「顺势加仓」,否则沿用监控单来源类型。"""
|
||||
oid = None
|
||||
try:
|
||||
keys = order_row.keys() if hasattr(order_row, "keys") else []
|
||||
@@ -92,7 +129,7 @@ def trade_record_monitor_type(conn, order_row, *, default_manual: str = "下单
|
||||
oid = None
|
||||
if oid and order_had_roll_fills(conn, oid):
|
||||
return MONITOR_TYPE_ROLL
|
||||
return _row_monitor_type(order_row, default_manual)
|
||||
return order_monitor_source_type(order_row, default_manual=default_manual)
|
||||
|
||||
|
||||
def entry_reason_for_monitor_type(monitor_type: str | None) -> str:
|
||||
|
||||
Reference in New Issue
Block a user