From 550d0b278d42ef30379d38bffc196f6398b91b4c 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 22:35:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(position=5Fmanager):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=9A=E7=BA=A7=E6=AD=A2=E7=9B=88=E5=AD=97=E6=AE=B5=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=83=A8=E5=88=86=E6=AD=A2=E7=9B=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 扩展 position_info 字典,新增 takeProfit1、takeProfit2、partialProfitTaken 和 remainingQuantity 字段。 当 take_profit_2 未设置时,默认使用 take_profit_price 作为其值,确保向后兼容。 --- trading_system/position_manager.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index accaf42..a60dfdb 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -2284,6 +2284,8 @@ class PositionManager: leverage = float(pos.get('leverage', 10) or trade.get('leverage', 10) or 10) stop_loss_price = trade.get('stop_loss_price') take_profit_price = trade.get('take_profit_price') or trade.get('take_profit_1') + take_profit_1 = trade.get('take_profit_1') + take_profit_2 = trade.get('take_profit_2') if stop_loss_price is None or take_profit_price is None: stop_loss_pct = config.TRADING_CONFIG.get('STOP_LOSS_PERCENT', 0.08) if stop_loss_pct is not None and stop_loss_pct > 1: @@ -2295,12 +2297,28 @@ class PositionManager: take_profit_pct = (stop_loss_pct or 0.08) * 2.0 stop_loss_price = self.risk_manager.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=stop_loss_pct) take_profit_price = take_profit_price or self.risk_manager.get_take_profit_price(entry_price, side, quantity, leverage, take_profit_pct=take_profit_pct) + if take_profit_2 is None and take_profit_price is not None: + take_profit_2 = take_profit_price position_info = { - 'symbol': symbol, 'side': side, 'quantity': quantity, 'entryPrice': entry_price, - 'changePercent': 0, 'orderId': trade.get('entry_order_id'), 'tradeId': trade.get('id'), - 'stopLoss': stop_loss_price, 'takeProfit': take_profit_price, 'initialStopLoss': stop_loss_price, - 'leverage': leverage, 'entryReason': trade.get('entry_reason') or 'db_sync', 'atr': trade.get('atr'), - 'maxProfit': 0.0, 'trailingStopActivated': False, + 'symbol': symbol, + 'side': side, + 'quantity': quantity, + 'entryPrice': entry_price, + 'changePercent': 0, + 'orderId': trade.get('entry_order_id'), + 'tradeId': trade.get('id'), + 'stopLoss': stop_loss_price, + 'takeProfit': take_profit_price, + 'takeProfit1': take_profit_1, + 'takeProfit2': take_profit_2, + 'partialProfitTaken': False, + 'remainingQuantity': quantity, + 'initialStopLoss': stop_loss_price, + 'leverage': leverage, + 'entryReason': trade.get('entry_reason') or 'db_sync', + 'atr': trade.get('atr'), + 'maxProfit': 0.0, + 'trailingStopActivated': False, } self.active_positions[symbol] = position_info logger.debug(f"{symbol} 已从 DB 载入到 active_positions,便于监控")