fix: improve order price comparison logic in makeOrderPlan function for better precision

This commit is contained in:
discountry
2025-10-28 18:59:37 +08:00
parent 265cb6df50
commit 73a88a8a0f
+8 -2
View File
@@ -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 };
}