更新 MakerEngine、OffsetMakerEngine 和 TrendEngine,重构订单同步逻辑,优化撤单和止损判断,新增订单计划生成和安全撤单功能,提升代码可读性和维护性。

This commit is contained in:
discountry
2025-09-24 04:33:08 +08:00
parent 6f05ee0da3
commit 7eddc3b88c
9 changed files with 272 additions and 199 deletions
+26
View File
@@ -0,0 +1,26 @@
import type { PositionSnapshot } from "./strategy";
export function shouldStopLoss(
position: PositionSnapshot,
bestBid: number,
bestAsk: number,
lossLimit: number
): boolean {
const absPosition = Math.abs(position.positionAmt);
if (absPosition < 1e-5) return false;
const pnl = position.positionAmt > 0
? (bestBid - position.entryPrice) * absPosition
: (position.entryPrice - bestAsk) * absPosition;
const unrealized = Number.isFinite(position.unrealizedProfit)
? (position.unrealizedProfit as number)
: null;
const derivedLoss = pnl < -lossLimit;
const snapshotLoss = Boolean(unrealized != null && unrealized < -lossLimit && pnl <= 0);
return derivedLoss || snapshotLoss;
}