删除不必要的min_grids_for_exit条件 - 止盈只由ROI信号决定,与加仓次数无关

This commit is contained in:
zhangkun9038@dingtalk.com 2025-11-28 00:37:48 +08:00
parent 2196de16ec
commit 9ee9e57114

View File

@ -260,7 +260,7 @@ class GridManager:
) )
self.is_completed = False # GridManager 是否完结 self.is_completed = False # GridManager 是否完结
self.completion_reason: Optional[str] = None # 完结原因 (take_profit / stop_loss) self.completion_reason: Optional[str] = None # 完结原因 (take_profit / stop_loss)
self.min_grids_for_exit = 20 # 至少加仓到约20个网格才能触发止盈保证按照预与加仓足够次 # ❌ 删除min_grids_for_exit - 止盈与加仓次数无关只由ROI信号决定
# ✅ GridManager 不变量:沉求下来就不改了(除非网格范围更新) # ✅ GridManager 不变量:沉求下来就不改了(除非网格范围更新)
# 便于 Redis 序列化保存 # 便于 Redis 序列化保存
@ -301,18 +301,17 @@ class GridManager:
file=sys.stderr, flush=True) file=sys.stderr, flush=True)
# ✅ 自监测:检查是否需要止盈/止损 # ✅ 自监测:检查是否需要止盈/止损
# 仅在加仓超过最低网格数时才触发,保证有足够的持仓 # 只要有持仓,就检查是否触发止盈/止损条件
if not self.is_completed and self.total_quantity > 0: if not self.is_completed and self.total_quantity > 0:
filled_count = sum(1 for gs in self.grid_states.values() if gs.status == "filled") exit_reason = self.monitor.get_exit_reason(current_price, self.avg_entry_price)
if filled_count >= self.min_grids_for_exit: if exit_reason:
exit_reason = self.monitor.get_exit_reason(current_price, self.avg_entry_price) self.is_completed = True
if exit_reason: self.completion_reason = exit_reason
self.is_completed = True profit_pct = (current_price - self.avg_entry_price) / self.avg_entry_price * 100
self.completion_reason = exit_reason filled_count = sum(1 for gs in self.grid_states.values() if gs.status == "filled")
profit_pct = (current_price - self.avg_entry_price) / self.avg_entry_price * 100 print(f"[GridManager] {self.pair} 自监测触发✅ - 原因: {exit_reason}, "
print(f"[GridManager] {self.pair} 自监测触发✅ - 原因: {exit_reason}, " f"利润: {profit_pct:.2f}%, 当前价: {current_price:.2f}, 网格数: {filled_count}",
f"利润: {profit_pct:.2f}%, 当前价: {current_price:.2f}, 网格数: {filled_count}", file=sys.stderr, flush=True)
file=sys.stderr, flush=True)
def apply_adjustment(self, adjustment: PositionRecord) -> None: def apply_adjustment(self, adjustment: PositionRecord) -> None:
""" """