mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 17:28:08 +00:00
fix: improve order price comparison logic in makeOrderPlan function for better precision
This commit is contained in:
@@ -18,11 +18,18 @@ export function makeOrderPlan(
|
|||||||
const orderPrice = String(order.price);
|
const orderPrice = String(order.price);
|
||||||
const reduceOnly = order.reduceOnly === true;
|
const reduceOnly = order.reduceOnly === true;
|
||||||
const matchedIndex = targets.findIndex((target, index) => {
|
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 (
|
return (
|
||||||
unmatched.has(index) &&
|
unmatched.has(index) &&
|
||||||
target.side === order.side &&
|
target.side === order.side &&
|
||||||
target.reduceOnly === reduceOnly &&
|
target.reduceOnly === reduceOnly &&
|
||||||
orderPrice === target.price // 直接使用字符串比较
|
priceMatches
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
if (matchedIndex >= 0) {
|
if (matchedIndex >= 0) {
|
||||||
@@ -39,4 +46,3 @@ export function makeOrderPlan(
|
|||||||
return { toCancel, toPlace };
|
return { toCancel, toPlace };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user