From 2c8c13b8d9e8846f47c945766c78a26e15877076 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:52:44 +0800 Subject: [PATCH] 1 --- trading_system/position_manager.py | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index a60dfdb..62c49ed 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -659,19 +659,32 @@ class PositionManager: logger.info(f"{symbol} [优化] TP1距离 ({tp1_distance:.4f}) 小于 手续费磨损距离 ({min_fee_distance:.4f}),已自动调整以覆盖成本") tp1_distance = min_fee_distance - # 计算最终TP1价格 if tp1_distance > 0: if side == 'BUY': take_profit_1 = entry_price + tp1_distance else: take_profit_1 = entry_price - tp1_distance else: - # 如果无法计算(极少情况),回退到盈亏比1:1 if side == 'BUY': take_profit_1 = entry_price + (entry_price - stop_loss_price) else: take_profit_1 = entry_price - (stop_loss_price - entry_price) take_profit_2 = take_profit_price + if take_profit_1 is not None and take_profit_2 is not None: + if side == 'BUY': + if take_profit_1 >= take_profit_2 and take_profit_2 > entry_price: + closer = min(take_profit_1, take_profit_2) + further = max(take_profit_1, take_profit_2) + if closer > entry_price: + take_profit_1 = closer + take_profit_2 = further + else: + if take_profit_1 <= take_profit_2 and take_profit_2 < entry_price: + closer = max(take_profit_1, take_profit_2) + further = min(take_profit_1, take_profit_2) + if closer < entry_price: + take_profit_1 = closer + take_profit_2 = further # 记录到数据库(只有在订单真正成交后才保存) trade_id = None @@ -2299,6 +2312,21 @@ class PositionManager: 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 + if take_profit_1 is not None and take_profit_2 is not None: + if side == 'BUY': + if take_profit_1 >= take_profit_2 and take_profit_2 > entry_price: + closer = min(take_profit_1, take_profit_2) + further = max(take_profit_1, take_profit_2) + if closer > entry_price: + take_profit_1 = closer + take_profit_2 = further + else: + if take_profit_1 <= take_profit_2 and take_profit_2 < entry_price: + closer = max(take_profit_1, take_profit_2) + further = min(take_profit_1, take_profit_2) + if closer < entry_price: + take_profit_1 = closer + take_profit_2 = further position_info = { 'symbol': symbol, 'side': side,