mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 08:48:07 +00:00
优化做市引擎、偏移做市引擎和趋势引擎的订单管理逻辑,将待取消订单的类型从数字更改为字符串,确保在处理订单时的类型一致性。同时,增强风险检查逻辑,确保在平仓时使用正确的价格,提升交易策略的稳定性和准确性。
This commit is contained in:
+2
-1
@@ -14,7 +14,8 @@ export function roundQtyDownToStep(value: number, step: number): number {
|
||||
export function decimalsOf(step: number): number {
|
||||
const s = step.toString();
|
||||
if (!s.includes(".")) return 0;
|
||||
return s.split(".")[1].length;
|
||||
const fraction = s.split(".")[1];
|
||||
return fraction ? fraction.length : 0;
|
||||
}
|
||||
|
||||
export function isNearlyZero(value: number, epsilon = 1e-5): boolean {
|
||||
|
||||
+11
-11
@@ -9,18 +9,18 @@ export function shouldStopLoss(
|
||||
const absPosition = Math.abs(position.positionAmt);
|
||||
if (absPosition < 1e-5) return false;
|
||||
|
||||
if (!Number.isFinite(position.entryPrice) || Math.abs(position.entryPrice) < 1e-8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const closePrice = position.positionAmt > 0 ? bestBid : bestAsk;
|
||||
if (!Number.isFinite(closePrice)) return false;
|
||||
|
||||
const pnl = position.positionAmt > 0
|
||||
? (bestBid - position.entryPrice) * absPosition
|
||||
: (position.entryPrice - bestAsk) * absPosition;
|
||||
? (closePrice - position.entryPrice) * absPosition
|
||||
: (position.entryPrice - closePrice) * absPosition;
|
||||
|
||||
const unrealized = Number.isFinite(position.unrealizedProfit)
|
||||
? (position.unrealizedProfit as number)
|
||||
: null;
|
||||
if (!Number.isFinite(pnl)) return false;
|
||||
|
||||
const derivedLoss = pnl < -lossLimit;
|
||||
const snapshotLoss = Boolean(unrealized != null && unrealized < -lossLimit && pnl <= 0);
|
||||
|
||||
return derivedLoss || snapshotLoss;
|
||||
return pnl < -lossLimit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user