mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 01:08:07 +00:00
更新 MakerEngine、OffsetMakerEngine 和 TrendEngine,重构订单同步逻辑,优化撤单和止损判断,新增订单计划生成和安全撤单功能,提升代码可读性和维护性。
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user