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,16 @@
|
||||
import type { PositionSnapshot } from "./strategy";
|
||||
|
||||
export function computePositionPnl(
|
||||
position: PositionSnapshot,
|
||||
bestBid?: number | null,
|
||||
bestAsk?: number | null
|
||||
): number {
|
||||
const priceForPnl = position.positionAmt > 0 ? bestBid : bestAsk;
|
||||
if (!Number.isFinite(priceForPnl as number)) return 0;
|
||||
const absAmt = Math.abs(position.positionAmt);
|
||||
return position.positionAmt > 0
|
||||
? ((priceForPnl as number) - position.entryPrice) * absAmt
|
||||
: (position.entryPrice - (priceForPnl as number)) * absAmt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user