a
This commit is contained in:
parent
d29abf9055
commit
54430a0e06
|
|
@ -492,12 +492,13 @@ class PositionManager:
|
||||||
f"{symbol} 触发止损: {current_price:.4f} <= {stop_loss:.4f} "
|
f"{symbol} 触发止损: {current_price:.4f} <= {stop_loss:.4f} "
|
||||||
f"(盈亏: {pnl_percent:.2f}%)"
|
f"(盈亏: {pnl_percent:.2f}%)"
|
||||||
)
|
)
|
||||||
|
# 确定平仓原因
|
||||||
|
exit_reason = 'trailing_stop' if position_info.get('trailingStopActivated') else 'stop_loss'
|
||||||
# 更新数据库
|
# 更新数据库
|
||||||
if DB_AVAILABLE:
|
if DB_AVAILABLE:
|
||||||
trade_id = position_info.get('tradeId')
|
trade_id = position_info.get('tradeId')
|
||||||
if trade_id:
|
if trade_id:
|
||||||
try:
|
try:
|
||||||
exit_reason = 'trailing_stop' if position_info.get('trailingStopActivated') else 'stop_loss'
|
|
||||||
Trade.update_exit(
|
Trade.update_exit(
|
||||||
trade_id=trade_id,
|
trade_id=trade_id,
|
||||||
exit_price=current_price,
|
exit_price=current_price,
|
||||||
|
|
@ -507,7 +508,7 @@ class PositionManager:
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"更新止损记录失败: {e}")
|
logger.warning(f"更新止损记录失败: {e}")
|
||||||
if await self.close_position(symbol):
|
if await self.close_position(symbol, reason=exit_reason):
|
||||||
closed_positions.append(symbol)
|
closed_positions.append(symbol)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -516,12 +517,13 @@ class PositionManager:
|
||||||
f"{symbol} 触发止损: {current_price:.4f} >= {stop_loss:.4f} "
|
f"{symbol} 触发止损: {current_price:.4f} >= {stop_loss:.4f} "
|
||||||
f"(盈亏: {pnl_percent:.2f}%)"
|
f"(盈亏: {pnl_percent:.2f}%)"
|
||||||
)
|
)
|
||||||
|
# 确定平仓原因
|
||||||
|
exit_reason = 'trailing_stop' if position_info.get('trailingStopActivated') else 'stop_loss'
|
||||||
# 更新数据库
|
# 更新数据库
|
||||||
if DB_AVAILABLE:
|
if DB_AVAILABLE:
|
||||||
trade_id = position_info.get('tradeId')
|
trade_id = position_info.get('tradeId')
|
||||||
if trade_id:
|
if trade_id:
|
||||||
try:
|
try:
|
||||||
exit_reason = 'trailing_stop' if position_info.get('trailingStopActivated') else 'stop_loss'
|
|
||||||
Trade.update_exit(
|
Trade.update_exit(
|
||||||
trade_id=trade_id,
|
trade_id=trade_id,
|
||||||
exit_price=current_price,
|
exit_price=current_price,
|
||||||
|
|
@ -531,7 +533,7 @@ class PositionManager:
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"更新止损记录失败: {e}")
|
logger.warning(f"更新止损记录失败: {e}")
|
||||||
if await self.close_position(symbol):
|
if await self.close_position(symbol, reason=exit_reason):
|
||||||
closed_positions.append(symbol)
|
closed_positions.append(symbol)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -542,6 +544,8 @@ class PositionManager:
|
||||||
f"{symbol} 触发止盈: {current_price:.4f} >= {take_profit:.4f} "
|
f"{symbol} 触发止盈: {current_price:.4f} >= {take_profit:.4f} "
|
||||||
f"(盈亏: {pnl_percent:.2f}%)"
|
f"(盈亏: {pnl_percent:.2f}%)"
|
||||||
)
|
)
|
||||||
|
# 确定平仓原因
|
||||||
|
exit_reason = 'take_profit'
|
||||||
# 更新数据库
|
# 更新数据库
|
||||||
if DB_AVAILABLE:
|
if DB_AVAILABLE:
|
||||||
trade_id = position_info.get('tradeId')
|
trade_id = position_info.get('tradeId')
|
||||||
|
|
@ -550,13 +554,13 @@ class PositionManager:
|
||||||
Trade.update_exit(
|
Trade.update_exit(
|
||||||
trade_id=trade_id,
|
trade_id=trade_id,
|
||||||
exit_price=current_price,
|
exit_price=current_price,
|
||||||
exit_reason='take_profit',
|
exit_reason=exit_reason,
|
||||||
pnl=pnl_percent * entry_price * quantity / 100,
|
pnl=pnl_percent * entry_price * quantity / 100,
|
||||||
pnl_percent=pnl_percent
|
pnl_percent=pnl_percent
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"更新止盈记录失败: {e}")
|
logger.warning(f"更新止盈记录失败: {e}")
|
||||||
if await self.close_position(symbol):
|
if await self.close_position(symbol, reason=exit_reason):
|
||||||
closed_positions.append(symbol)
|
closed_positions.append(symbol)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -565,6 +569,8 @@ class PositionManager:
|
||||||
f"{symbol} 触发止盈: {current_price:.4f} <= {take_profit:.4f} "
|
f"{symbol} 触发止盈: {current_price:.4f} <= {take_profit:.4f} "
|
||||||
f"(盈亏: {pnl_percent:.2f}%)"
|
f"(盈亏: {pnl_percent:.2f}%)"
|
||||||
)
|
)
|
||||||
|
# 确定平仓原因
|
||||||
|
exit_reason = 'take_profit'
|
||||||
# 更新数据库
|
# 更新数据库
|
||||||
if DB_AVAILABLE:
|
if DB_AVAILABLE:
|
||||||
trade_id = position_info.get('tradeId')
|
trade_id = position_info.get('tradeId')
|
||||||
|
|
@ -573,13 +579,13 @@ class PositionManager:
|
||||||
Trade.update_exit(
|
Trade.update_exit(
|
||||||
trade_id=trade_id,
|
trade_id=trade_id,
|
||||||
exit_price=current_price,
|
exit_price=current_price,
|
||||||
exit_reason='take_profit',
|
exit_reason=exit_reason,
|
||||||
pnl=pnl_percent * entry_price * quantity / 100,
|
pnl=pnl_percent * entry_price * quantity / 100,
|
||||||
pnl_percent=pnl_percent
|
pnl_percent=pnl_percent
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"更新止盈记录失败: {e}")
|
logger.warning(f"更新止盈记录失败: {e}")
|
||||||
if await self.close_position(symbol):
|
if await self.close_position(symbol, reason=exit_reason):
|
||||||
closed_positions.append(symbol)
|
closed_positions.append(symbol)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user