更新 MakerEngine,清理历史挂单并重置状态;修复 getPosition 函数以处理未定义的选项

This commit is contained in:
discountry
2025-09-24 01:26:55 +08:00
parent 633f5fb904
commit fa1579269a
2 changed files with 7 additions and 3 deletions
+4
View File
@@ -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)}`);
+3 -3
View File
@@ -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,
};
}