From 39a97110dd3727902246849824b5b32d0c0be2a2 Mon Sep 17 00:00:00 2001 From: discountry Date: Tue, 7 Oct 2025 22:00:43 +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=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=A1=AB=E5=85=85=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E5=AF=B9=E5=8E=86=E5=8F=B2=E9=94=AE=E5=92=8C?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E7=9A=84=E6=AF=94=E8=BE=83=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/strategy/grid-engine.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/strategy/grid-engine.ts b/src/strategy/grid-engine.ts index 0906ab3..2afe461 100644 --- a/src/strategy/grid-engine.ts +++ b/src/strategy/grid-engine.ts @@ -454,7 +454,10 @@ export class GridEngine { private async syncGridSimple(price: number): Promise { const activeOrders = this.openOrders.filter((o) => o.symbol === this.config.symbol && o.type === "LIMIT"); - // Detect fills by comparing last keys + // Detect fills by comparing previous keys vs current snapshot + const prevKeys = this.lastOpenOrderKeys; + const prevMeta = this.lastKeyMeta; + const currentKeys = new Set(); const keyToMeta = new Map(); for (const o of activeOrders) { @@ -465,11 +468,10 @@ export class GridEngine { keyToMeta.set(key, { side: o.side, level, reduceOnly: o.reduceOnly === true }); } } - // persist metadata for next tick to detect fills - this.lastKeyMeta = keyToMeta; - for (const prevKey of this.lastOpenOrderKeys) { + + for (const prevKey of prevKeys) { if (currentKeys.has(prevKey)) continue; - const meta = this.lastKeyMeta.get(prevKey) || keyToMeta.get(prevKey); + const meta = prevMeta.get(prevKey); // If we can't resolve from current snapshot, try to decode by stored mapping if (!meta) { // For reduce-only disappearance, check mapping @@ -512,6 +514,8 @@ export class GridEngine { } } this.lastOpenOrderKeys = currentKeys; + // persist metadata for next tick to detect fills + this.lastKeyMeta = keyToMeta; // Desired open orders according to locked sides const desired: DesiredGridOrder[] = [];