feat: add custom_entry_price and custom_exit_price with 0.25% adjustment, fix data freshness calculation, and improve real-time data handling

This commit is contained in:
zhangkun9038@dingtalk.com 2026-02-26 00:05:31 +08:00
parent 9ed9a6ee74
commit 3bfe9edd11

View File

@ -1633,12 +1633,9 @@ class FreqaiPrimer(IStrategy):
# f"动态ROI阈值={dynamic_roi_threshold:.4f}, 利润比值={profit_ratio:.2f}, "
# f"市场状态={current_state}, entry_tag={entry_tag}, 退出比例={exit_ratio:.0%}")
# 当决定退出时,输出出场价格信息
# 当决定退出时,输出出场价格信息(但不调整价格)
if exit_ratio > 0:
# 计算出场价格上浮比例1.25%
price_markup_percent = 1.25
adjusted_exit_price = current_rate * 1.0125
self.strategy_log(f"[{pair}] 准备出场 - 市场价: {current_rate:.8f}, 调整后出场价: {adjusted_exit_price:.8f}, 上浮: {price_markup_percent}%, 退出比例: {exit_ratio:.0%}")
self.strategy_log(f"[{pair}] 准备出场 - 市场价: {current_rate:.8f}, 退出比例: {exit_ratio:.0%}")
return exit_ratio
@ -1713,3 +1710,31 @@ class FreqaiPrimer(IStrategy):
return adjusted_stake
def custom_exit_price(self, pair: str, trade: Trade, current_time: datetime, proposed_exit_price: float,
current_profit: float, **kwargs) -> float:
"""
自定义出场价格
根据文档价格调整逻辑应该放在这里而不是在 custom_exit
"""
# 计算出场价格上浮比例0.25%
price_markup_percent = 0.25
adjusted_exit_price = proposed_exit_price * (1 + price_markup_percent / 100)
self.strategy_log(f"[{pair}] 自定义出场价格: 原价格 {proposed_exit_price:.8f} -> 调整后价格 {adjusted_exit_price:.8f}, 上浮: {price_markup_percent}%")
return adjusted_exit_price
def custom_entry_price(self, pair: str, current_time: datetime, proposed_entry_price: float,
entry_tag: str, side: str, **kwargs) -> float:
"""
自定义入场价格
将入场价格调低0.25%以提高成交概率
"""
# 计算入场价格下调比例0.25%
price_discount_percent = 0.25
adjusted_entry_price = proposed_entry_price * (1 - price_discount_percent / 100)
self.strategy_log(f"[{pair}] 自定义入场价格: 原价格 {proposed_entry_price:.8f} -> 调整后价格 {adjusted_entry_price:.8f}, 下调: {price_discount_percent}%")
return adjusted_entry_price