From fa1579269a4c9c4b4b115c2a6065142b69dfaeee Mon Sep 17 00:00:00 2001 From: discountry Date: Wed, 24 Sep 2025 01:26:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20MakerEngine=EF=BC=8C?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=8E=86=E5=8F=B2=E6=8C=82=E5=8D=95=E5=B9=B6?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E7=8A=B6=E6=80=81=EF=BC=9B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20getPosition=20=E5=87=BD=E6=95=B0=E4=BB=A5=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9C=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/maker-engine.ts | 4 ++++ src/utils/strategy.ts | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/maker-engine.ts b/src/core/maker-engine.ts index 54a654a..470b882 100644 --- a/src/core/maker-engine.ts +++ b/src/core/maker-engine.ts @@ -227,6 +227,8 @@ export class MakerEngine { await this.exchange.cancelAllOrders({ symbol: this.config.symbol }); this.pendingCancelOrders.clear(); unlockOperating(this.locks, this.timers, this.pending, "LIMIT"); + this.openOrders = []; + this.emitUpdate(); this.tradeLog.push("order", "启动时清理历史挂单"); this.initialOrderResetDone = true; return true; @@ -234,6 +236,8 @@ export class MakerEngine { if (isUnknownOrderError(error)) { this.tradeLog.push("order", "历史挂单已消失,跳过启动清理"); this.initialOrderResetDone = true; + this.openOrders = []; + this.emitUpdate(); return true; } this.tradeLog.push("error", `启动撤单失败: ${String(error)}`); diff --git a/src/utils/strategy.ts b/src/utils/strategy.ts index da8bdb4..db24ccf 100644 --- a/src/utils/strategy.ts +++ b/src/utils/strategy.ts @@ -21,9 +21,9 @@ export function getPosition(snapshot: AsterAccountSnapshot | null, symbol: strin withExposure.sort((a, b) => Math.abs(Number(b.positionAmt)) - Math.abs(Number(a.positionAmt)))[0] ?? positions[0]; return { - positionAmt: Number(selected.positionAmt) || 0, - entryPrice: Number(selected.entryPrice) || 0, - unrealizedProfit: Number(selected.unrealizedProfit) || 0, + positionAmt: Number(selected?.positionAmt) || 0, + entryPrice: Number(selected?.entryPrice) || 0, + unrealizedProfit: Number(selected?.unrealizedProfit) || 0, }; }