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,便于监控")