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, }; }