From c4a23be3bf2ecfca4e2a0f94beaa203a9f7508c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Sun, 15 Feb 2026 09:21:15 +0800 Subject: [PATCH] 1 --- trading_system/position_manager.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index 1675cfe..c3bc7e0 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -2952,6 +2952,11 @@ class PositionManager: "leverage": lev, "entryReason": "sync_recovered", "atr": None, "maxProfit": 0.0, "trailingStopActivated": False, } self.active_positions[symbol] = position_info + # 补建后立即在交易所挂/修正止损止盈(替换可能存在的异常远止损、缺止盈等) + try: + await self._ensure_exchange_sltp_orders(symbol, position_info, current_price=current_price) + except Exception as sltp_e: + logger.warning(f" {symbol} [补建] 补挂交易所止损止盈失败(不影响监控): {sltp_e}") if self._monitoring_enabled: await self._start_position_monitoring(symbol) except Exception as e: @@ -3221,6 +3226,19 @@ class PositionManager: logger.warning(f"{symbol} 补挂币安止盈止损失败(不影响监控): {e}") except Exception as e: logger.error(f"{symbol} 创建临时持仓记录失败: {e}") + else: + # 已在 active_positions 的持仓:启动前统一补挂/修正交易所 SL/TP(识别缺止盈、止损过远等异常并替换) + position_info = self.active_positions.get(symbol) + if position_info and position_info.get("stopLoss") and position_info.get("takeProfit"): + try: + mp = None + try: + mp = float(position.get("markPrice", 0) or 0) or None + except Exception: + mp = None + await self._ensure_exchange_sltp_orders(symbol, position_info, current_price=mp) + except Exception as e: + logger.warning(f"{symbol} 补挂/修正交易所止损止盈失败(不影响监控): {e}") await self._start_position_monitoring(symbol)