a
This commit is contained in:
parent
731e71aae8
commit
762e9c4b38
|
|
@ -1199,11 +1199,11 @@ class PositionManager:
|
||||||
if side == "BUY":
|
if side == "BUY":
|
||||||
# 做多:当前价 <= 止损价,说明已触发止损
|
# 做多:当前价 <= 止损价,说明已触发止损
|
||||||
if current_price_val <= stop_loss_val:
|
if current_price_val <= stop_loss_val:
|
||||||
logger.error(f"{symbol} ⚠️ 当前价格({current_price_val:.8f})已触发止损价({stop_loss_val:.8f}),无法挂止损单,应该立即平仓!")
|
logger.error(f"{symbol} ⚠️ 当前价格({current_price_val:.8f})已触发止损价({stop_loss_val:.8f}),无法挂止损单,立即执行市价平仓保护!")
|
||||||
logger.error(f" 入场价: {entry_price_val:.8f if entry_price_val else 'N/A'}")
|
logger.error(f" 入场价: {entry_price_val:.8f if entry_price_val else 'N/A'}")
|
||||||
logger.error(f" 建议: 立即手动平仓或等待WebSocket监控触发平仓")
|
# 立即执行市价平仓
|
||||||
# 不挂止损单,依赖WebSocket监控立即平仓
|
await self.close_position(symbol, reason='stop_loss')
|
||||||
sl_order = None
|
return
|
||||||
else:
|
else:
|
||||||
sl_order = await self.client.place_trigger_close_position_order(
|
sl_order = await self.client.place_trigger_close_position_order(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
|
|
@ -1216,11 +1216,11 @@ class PositionManager:
|
||||||
elif side == "SELL":
|
elif side == "SELL":
|
||||||
# 做空:当前价 >= 止损价,说明已触发止损
|
# 做空:当前价 >= 止损价,说明已触发止损
|
||||||
if current_price_val >= stop_loss_val:
|
if current_price_val >= stop_loss_val:
|
||||||
logger.error(f"{symbol} ⚠️ 当前价格({current_price_val:.8f})已触发止损价({stop_loss_val:.8f}),无法挂止损单,应该立即平仓!")
|
logger.error(f"{symbol} ⚠️ 当前价格({current_price_val:.8f})已触发止损价({stop_loss_val:.8f}),无法挂止损单,立即执行市价平仓保护!")
|
||||||
logger.error(f" 入场价: {entry_price_val:.8f if entry_price_val else 'N/A'}")
|
logger.error(f" 入场价: {entry_price_val:.8f if entry_price_val else 'N/A'}")
|
||||||
logger.error(f" 建议: 立即手动平仓或等待WebSocket监控触发平仓")
|
# 立即执行市价平仓
|
||||||
# 不挂止损单,依赖WebSocket监控立即平仓
|
await self.close_position(symbol, reason='stop_loss')
|
||||||
sl_order = None
|
return
|
||||||
else:
|
else:
|
||||||
sl_order = await self.client.place_trigger_close_position_order(
|
sl_order = await self.client.place_trigger_close_position_order(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
|
|
@ -1269,6 +1269,26 @@ class PositionManager:
|
||||||
logger.error(f" ⚠️ 警告: 没有交易所级别的止损保护,如果系统崩溃或网络中断,可能无法及时止损!")
|
logger.error(f" ⚠️ 警告: 没有交易所级别的止损保护,如果系统崩溃或网络中断,可能无法及时止损!")
|
||||||
logger.error(f" 💡 建议: 检查止损价格计算是否正确,或手动在币安界面设置止损")
|
logger.error(f" 💡 建议: 检查止损价格计算是否正确,或手动在币安界面设置止损")
|
||||||
|
|
||||||
|
# 在挂止盈单前,检查当前价格是否已经触发止盈
|
||||||
|
if current_price and take_profit:
|
||||||
|
try:
|
||||||
|
current_price_val = float(current_price)
|
||||||
|
take_profit_val = float(take_profit)
|
||||||
|
|
||||||
|
# 检查是否已经触发止盈
|
||||||
|
triggered_tp = False
|
||||||
|
if side == "BUY" and current_price_val >= take_profit_val:
|
||||||
|
triggered_tp = True
|
||||||
|
elif side == "SELL" and current_price_val <= take_profit_val:
|
||||||
|
triggered_tp = True
|
||||||
|
|
||||||
|
if triggered_tp:
|
||||||
|
logger.info(f"{symbol} 🎯 当前价格({current_price_val:.8f})已达到止盈价({take_profit_val:.8f}),立即执行市价止盈!")
|
||||||
|
await self.close_position(symbol, reason='take_profit')
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"{symbol} 检查止盈触发条件时出错: {e}")
|
||||||
|
|
||||||
tp_order = await self.client.place_trigger_close_position_order(
|
tp_order = await self.client.place_trigger_close_position_order(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
position_direction=side,
|
position_direction=side,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user