From 8bb1bf7254a3f917391b2db8eaf9b770726f78fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Sat, 28 Feb 2026 19:13:58 +0800 Subject: [PATCH] feat(position_manager): Improve monitoring logic for Binance positions without SL/TP orders Updated the position monitoring logic to handle cases where positions exist on Binance without corresponding stop-loss or take-profit orders. Enhanced logging to provide clearer insights into the status of these positions, ensuring better risk management by avoiding unprotected positions. This change allows for automatic monitoring and order creation based on the presence of SL/TP orders. --- trading_system/position_manager.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index 089d529..5026b30 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -3956,16 +3956,18 @@ class PositionManager: for position in positions: symbol = position['symbol'] if symbol not in self._monitor_tasks: - # 若不在 active_positions:要么开启「同步创建手动开仓」则全部接入,要么仅对「有止损/止盈单」的接入(视为系统单) + # 若不在 active_positions:开启「同步创建手动开仓」则全部接入;或开启「监控仅币安有仓」时也接入(有 SL/TP 的视为系统单,无 SL/TP 的补挂并监控,避免裸仓) if symbol not in self.active_positions: has_sltp = await self._symbol_has_sltp_orders(symbol) if monitor_binance_with_sltp else False - should_create = sync_create_manual or (monitor_binance_with_sltp and has_sltp) + should_create = sync_create_manual or monitor_binance_with_sltp if not should_create: continue if sync_create_manual: logger.warning(f"[账号{self.account_id}] {symbol} 在币安有持仓但不在本地记录中,可能是手动开仓,尝试创建记录...") - else: + elif has_sltp: logger.info(f"[账号{self.account_id}] {symbol} 仅币安有仓且存在止损/止盈单,按系统单接入监控并补建记录") + else: + logger.info(f"[账号{self.account_id}] {symbol} 仅币安有仓且无止损/止盈单,接入监控并补挂 SL/TP(避免裸仓)") try: entry_price = position.get('entryPrice', 0) position_amt = position['positionAmt']