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.
This commit is contained in:
薇薇安 2026-02-28 19:13:58 +08:00
parent c926586f8d
commit 8bb1bf7254

View File

@ -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']