a
This commit is contained in:
parent
fb04f69965
commit
5faf3e103d
|
|
@ -1788,12 +1788,13 @@ class PositionManager:
|
||||||
# ✅ 已移除时间锁限制,可以立即执行
|
# ✅ 已移除时间锁限制,可以立即执行
|
||||||
take_profit = position_info.get('takeProfit')
|
take_profit = position_info.get('takeProfit')
|
||||||
if take_profit is not None:
|
if take_profit is not None:
|
||||||
# 计算止盈对应的保证金百分比
|
# ⚠️ 关键修复:直接使用配置的 TAKE_PROFIT_PERCENT,而不是从止盈价格反推
|
||||||
if position_info['side'] == 'BUY':
|
# 因为止盈价格可能使用了ATR(更远),反推会导致阈值过大,难以触发
|
||||||
take_profit_amount = (take_profit - entry_price) * quantity
|
take_profit_pct_margin_config = config.TRADING_CONFIG.get('TAKE_PROFIT_PERCENT', 0.10)
|
||||||
else: # SELL
|
# 兼容百分比形式和比例形式
|
||||||
take_profit_amount = (entry_price - take_profit) * quantity
|
if take_profit_pct_margin_config > 1:
|
||||||
take_profit_pct_margin = (take_profit_amount / margin * 100) if margin > 0 else 0
|
take_profit_pct_margin_config = take_profit_pct_margin_config / 100.0
|
||||||
|
take_profit_pct_margin = take_profit_pct_margin_config * 100 # 转换为百分比
|
||||||
|
|
||||||
# 直接比较当前盈亏百分比与止盈目标(基于保证金)
|
# 直接比较当前盈亏百分比与止盈目标(基于保证金)
|
||||||
if pnl_percent_margin >= take_profit_pct_margin:
|
if pnl_percent_margin >= take_profit_pct_margin:
|
||||||
|
|
@ -3012,13 +3013,20 @@ class PositionManager:
|
||||||
take_profit = position_info.get('takeProfit')
|
take_profit = position_info.get('takeProfit')
|
||||||
if take_profit is not None:
|
if take_profit is not None:
|
||||||
# 计算止盈对应的保证金百分比目标
|
# 计算止盈对应的保证金百分比目标
|
||||||
# 止盈金额 = (止盈价 - 开仓价) × 数量 或 (开仓价 - 止盈价) × 数量
|
# ⚠️ 关键修复:直接使用配置的 TAKE_PROFIT_PERCENT,而不是从止盈价格反推
|
||||||
|
# 因为止盈价格可能使用了ATR(更远),反推会导致阈值过大,难以触发
|
||||||
|
take_profit_pct_margin_config = config.TRADING_CONFIG.get('TAKE_PROFIT_PERCENT', 0.10)
|
||||||
|
# 兼容百分比形式和比例形式
|
||||||
|
if take_profit_pct_margin_config > 1:
|
||||||
|
take_profit_pct_margin_config = take_profit_pct_margin_config / 100.0
|
||||||
|
take_profit_pct_margin = take_profit_pct_margin_config * 100 # 转换为百分比
|
||||||
|
|
||||||
|
# 计算止盈金额(用于日志显示,但不用于触发判断)
|
||||||
if position_info['side'] == 'BUY':
|
if position_info['side'] == 'BUY':
|
||||||
take_profit_amount = (take_profit - entry_price) * quantity
|
take_profit_amount = (take_profit - entry_price) * quantity
|
||||||
else: # SELL
|
else: # SELL
|
||||||
take_profit_amount = (entry_price - take_profit) * quantity
|
take_profit_amount = (entry_price - take_profit) * quantity
|
||||||
|
take_profit_pct_margin_from_price = (take_profit_amount / margin * 100) if margin > 0 else 0
|
||||||
take_profit_pct_margin = (take_profit_amount / margin * 100) if margin > 0 else 0
|
|
||||||
|
|
||||||
# 每5%盈利记录一次诊断日志(帮助排查问题)
|
# 每5%盈利记录一次诊断日志(帮助排查问题)
|
||||||
if pnl_percent_margin >= 5.0:
|
if pnl_percent_margin >= 5.0:
|
||||||
|
|
@ -3029,13 +3037,13 @@ class PositionManager:
|
||||||
f"{symbol} [实时监控] 诊断: 盈利{pnl_percent_margin:.2f}% of margin | "
|
f"{symbol} [实时监控] 诊断: 盈利{pnl_percent_margin:.2f}% of margin | "
|
||||||
f"当前价: {current_price_float:.4f} | "
|
f"当前价: {current_price_float:.4f} | "
|
||||||
f"入场价: {entry_price:.4f} | "
|
f"入场价: {entry_price:.4f} | "
|
||||||
f"止盈价: {take_profit:.4f} (目标: {take_profit_pct_margin:.2f}% of margin) | "
|
f"止盈价: {take_profit:.4f} (配置目标: {take_profit_pct_margin:.2f}% of margin, 价格对应: {take_profit_pct_margin_from_price:.2f}%) | "
|
||||||
f"方向: {position_info['side']} | "
|
f"方向: {position_info['side']} | "
|
||||||
f"是否触发: {trigger_condition} | "
|
f"是否触发: {trigger_condition} | "
|
||||||
f"监控状态: {'运行中' if symbol in self._monitor_tasks else '未启动'}"
|
f"监控状态: {'运行中' if symbol in self._monitor_tasks else '未启动'}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 直接比较当前盈亏百分比与止盈目标(基于保证金)
|
# 直接比较当前盈亏百分比与止盈目标(基于保证金,使用配置值)
|
||||||
if pnl_percent_margin >= take_profit_pct_margin:
|
if pnl_percent_margin >= take_profit_pct_margin:
|
||||||
should_close = True
|
should_close = True
|
||||||
exit_reason = 'take_profit'
|
exit_reason = 'take_profit'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user