From 73a88a8a0f10b67472e6b0ce815567bf14cf2e86 Mon Sep 17 00:00:00 2001 From: discountry Date: Tue, 28 Oct 2025 18:59:37 +0800 Subject: [PATCH] fix: improve order price comparison logic in makeOrderPlan function for better precision --- src/core/lib/order-plan.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/lib/order-plan.ts b/src/core/lib/order-plan.ts index 3e3d7c2..a321447 100644 --- a/src/core/lib/order-plan.ts +++ b/src/core/lib/order-plan.ts @@ -18,11 +18,18 @@ export function makeOrderPlan( const orderPrice = String(order.price); const reduceOnly = order.reduceOnly === true; const matchedIndex = targets.findIndex((target, index) => { + const targetPrice = String(target.price); + const orderPriceValue = Number(orderPrice); + const targetPriceValue = Number(targetPrice); + const priceMatches = + Number.isFinite(orderPriceValue) && Number.isFinite(targetPriceValue) + ? Math.abs(orderPriceValue - targetPriceValue) <= 1e-8 + : orderPrice === targetPrice; return ( unmatched.has(index) && target.side === order.side && target.reduceOnly === reduceOnly && - orderPrice === target.price // 直接使用字符串比较 + priceMatches ); }); if (matchedIndex >= 0) { @@ -39,4 +46,3 @@ export function makeOrderPlan( return { toCancel, toPlace }; } -