-
我的交易进程(当前账号 #{accountId})
+
我的交易进程(当前账号 #{accountId})
+
{accountTradingStatus?.running ? '运行中' : '未运行/未知'}
diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py
index c8b8499..b747f2b 100644
--- a/trading_system/position_manager.py
+++ b/trading_system/position_manager.py
@@ -1294,8 +1294,13 @@ class PositionManager:
f"剩余数量: {remaining_quantity:.4f})"
)
else:
- new_stop_loss = entry_price - (remaining_pnl - protect_amount) / remaining_quantity
- if new_stop_loss < position_info['stopLoss']:
+ # 做空:止损价 = 开仓价 + (剩余盈亏 - 保护金额) / 剩余数量
+ # 注意:对于做空,止损价应该高于开仓价,所以用加法
+ # 移动止损只应该在盈利时激活
+ new_stop_loss = entry_price + (remaining_pnl - protect_amount) / remaining_quantity
+ # 对于做空,止损价应该越来越高(更宽松),所以检查 new_stop_loss > 当前止损
+ # 同时,移动止损只应该在盈利时激活
+ if new_stop_loss > position_info['stopLoss'] and remaining_pnl > 0:
position_info['stopLoss'] = new_stop_loss
logger.info(
f"{symbol} 移动止损更新(剩余仓位): {new_stop_loss:.4f} "
@@ -1317,9 +1322,14 @@ class PositionManager:
f"(保护{trailing_protect*100:.1f}% of margin = {protect_amount:.4f} USDT)"
)
else:
- # 做空:止损价 = 开仓价 - (当前盈亏 - 保护金额) / 数量
- new_stop_loss = entry_price - (pnl_amount - protect_amount) / quantity
- if new_stop_loss < position_info['stopLoss']:
+ # 做空:止损价 = 开仓价 + (当前盈亏 - 保护金额) / 数量
+ # 注意:对于做空,止损价应该高于开仓价,所以用加法
+ # 当盈利时(pnl_amount > 0),止损价应该往上移(更宽松)
+ # 当亏损时(pnl_amount < 0),不应该移动止损(保持初始止损)
+ new_stop_loss = entry_price + (pnl_amount - protect_amount) / quantity
+ # 对于做空,止损价应该越来越高(更宽松),所以检查 new_stop_loss > 当前止损
+ # 同时,移动止损只应该在盈利时激活,不应该在亏损时把止损往下移
+ if new_stop_loss > position_info['stopLoss'] and pnl_amount > 0:
position_info['stopLoss'] = new_stop_loss
logger.info(
f"{symbol} 移动止损更新: {new_stop_loss:.4f} "
@@ -2488,9 +2498,14 @@ class PositionManager:
f"(保护{trailing_protect*100:.1f}% of margin = {protect_amount:.4f} USDT)"
)
else: # SELL
- # 做空:止损价 = 开仓价 - (当前盈亏 - 保护金额) / 数量
- new_stop_loss = entry_price - (pnl_amount - protect_amount) / quantity
- if new_stop_loss < position_info['stopLoss']:
+ # 做空:止损价 = 开仓价 + (当前盈亏 - 保护金额) / 数量
+ # 注意:对于做空,止损价应该高于开仓价,所以用加法
+ # 当盈利时(pnl_amount > 0),止损价应该往上移(更宽松)
+ # 当亏损时(pnl_amount < 0),不应该移动止损(保持初始止损)
+ new_stop_loss = entry_price + (pnl_amount - protect_amount) / quantity
+ # 对于做空,止损价应该越来越高(更宽松),所以检查 new_stop_loss > 当前止损
+ # 同时,移动止损只应该在盈利时激活,不应该在亏损时把止损往下移
+ if new_stop_loss > position_info['stopLoss'] and pnl_amount > 0:
position_info['stopLoss'] = new_stop_loss
logger.info(
f"{symbol} [实时监控] 移动止损更新: {new_stop_loss:.4f} "