From 5a927de07c72f0c4f76f280badac6109216099f0 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Thu, 27 Nov 2025 21:54:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E7=9B=91=E6=B5=8B?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=EF=BC=9A=E4=BB=85=E5=9C=A8=E5=8A=A0=E4=BB=93?= =?UTF-8?q?=E5=88=B05=E4=B8=AA=E7=BD=91=E6=A0=BC=E5=90=8E=E6=89=8D?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=AD=A2=E7=9B=88/=E6=AD=A2=E6=8D=9F?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E8=AF=81=E6=9C=89=E8=B6=B3=E5=A4=9F=E7=9A=84?= =?UTF-8?q?=E6=8C=81=E4=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user_data/strategies/grid_manager.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/user_data/strategies/grid_manager.py b/user_data/strategies/grid_manager.py index 0bceffc..b2a88a6 100644 --- a/user_data/strategies/grid_manager.py +++ b/user_data/strategies/grid_manager.py @@ -211,6 +211,7 @@ class GridManager: ) self.is_completed = False # GridManager 是否完结 self.completion_reason: Optional[str] = None # 完结原因 (take_profit / stop_loss) + self.min_grids_for_exit = 5 # 至少加仓到5个网格才能触发止盈/止损 def update_state(self, current_price: float, candle_index: int) -> None: """ @@ -242,15 +243,18 @@ class GridManager: file=sys.stderr, flush=True) # ✅ 自监测:检查是否需要止盈/止损 + # 仅在加仓超过最低网格数时才触发,保证有足够的持仓 if not self.is_completed and self.total_quantity > 0: - exit_reason = self.monitor.get_exit_reason(current_price, self.avg_entry_price) - if exit_reason: - self.is_completed = True - self.completion_reason = exit_reason - profit_pct = (current_price - self.avg_entry_price) / self.avg_entry_price * 100 - print(f"[GridManager] {self.pair} 自监测触发✅ - 原因: {exit_reason}, " - f"利润: {profit_pct:.2f}%, 当前价: {current_price:.2f}", - file=sys.stderr, flush=True) + filled_count = sum(1 for gs in self.grid_states.values() if gs.status == "filled") + if filled_count >= self.min_grids_for_exit: + exit_reason = self.monitor.get_exit_reason(current_price, self.avg_entry_price) + if exit_reason: + self.is_completed = True + self.completion_reason = exit_reason + profit_pct = (current_price - self.avg_entry_price) / self.avg_entry_price * 100 + print(f"[GridManager] {self.pair} 自监测触发✅ - 原因: {exit_reason}, " + f"利润: {profit_pct:.2f}%, 当前价: {current_price:.2f}, 网格数: {filled_count}", + file=sys.stderr, flush=True) def apply_adjustment(self, adjustment: PositionRecord) -> None: """