From 96cf4ea47be266082b7daa4fa5de7547cbce50b4 Mon Sep 17 00:00:00 2001 From: discountry Date: Wed, 8 Oct 2025 04:59:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=BD=91=E6=A0=BC?= =?UTF-8?q?=E5=BC=95=E6=93=8E=EF=BC=8C=E4=BC=98=E5=8C=96=E6=96=B0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E4=B8=8B=E5=8D=95=E9=80=BB=E8=BE=91=EF=BC=8C=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=BF=AB=E7=85=A7=E6=9B=B4=E6=96=B0=E4=B8=8E=E5=86=B7?= =?UTF-8?q?=E5=8D=B4=E6=9C=9F=E6=9D=A1=E4=BB=B6=E4=BB=A5=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=B8=8B=E5=8D=95=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/strategy/grid-engine.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/strategy/grid-engine.ts b/src/strategy/grid-engine.ts index a2aec33..48c8c8b 100644 --- a/src/strategy/grid-engine.ts +++ b/src/strategy/grid-engine.ts @@ -856,15 +856,13 @@ export class GridEngine { this.log("info", "存在未完成的 LIMIT 操作,本轮不再下新单"); break; } - // Gate: require a new orders snapshot since last placement to proceed - if (this.lastPlacementOrdersVersion === this.ordersVersion) { - this.log("info", "等待订单快照更新后再下单"); - break; - } - // Gate: cooldown between LIMIT attempts to avoid thrashing + // Gate: require either a new orders snapshot OR cooldown elapsed const nowTs2 = this.now(); - if (nowTs2 - this.lastLimitAttemptAt < GridEngine.LIMIT_COOLDOWN_MS) { - this.log("info", "冷却期内,暂不下新 LIMIT 单"); + const needSnapshotUpdated = this.lastPlacementOrdersVersion === this.ordersVersion; + const inCooldown = nowTs2 - this.lastLimitAttemptAt < GridEngine.LIMIT_COOLDOWN_MS; + if (needSnapshotUpdated && inCooldown) { + // both conditions unmet: still waiting for either snapshot or cooldown + this.log("info", "等待订单快照或冷却结束再下单"); break; } // If a LIMIT operation is already pending (coordinator lock), skip issuing more this tick @@ -900,6 +898,8 @@ export class GridEngine { continue; } try { + // record attempt time to avoid rapid retries even if placement fails + this.lastLimitAttemptAt = nowTs2; const placed = await placeOrder( this.exchange, this.config.symbol, @@ -917,7 +917,6 @@ export class GridEngine { ); if (placed) { this.lastPlacementOrdersVersion = this.ordersVersion; - this.lastLimitAttemptAt = this.now(); newOrdersPlaced += 1; plannedKeyCounts.set(key, (plannedKeyCounts.get(key) ?? 0) + 1); activeKeyCounts.set(key, (activeKeyCounts.get(key) ?? 0) + 1);