feat: 更新订单处理逻辑,将价格类型改为字符串以避免精度问题,并添加价格格式化函数

This commit is contained in:
discountry
2025-10-03 07:15:21 +08:00
parent 65aaf26879
commit d5c4b04746
7 changed files with 68 additions and 39 deletions
+3 -7
View File
@@ -2,7 +2,7 @@ import type { AsterOrder } from "../../exchanges/types";
export interface OrderTarget {
side: "BUY" | "SELL";
price: number;
price: string; // 改为字符串避免精度问题
amount: number;
reduceOnly: boolean;
}
@@ -15,18 +15,14 @@ export function makeOrderPlan(
const toCancel: AsterOrder[] = [];
for (const order of openOrders) {
const price = Number(order.price);
if (!Number.isFinite(price)) {
toCancel.push(order);
continue;
}
const orderPrice = String(order.price);
const reduceOnly = order.reduceOnly === true;
const matchedIndex = targets.findIndex((target, index) => {
return (
unmatched.has(index) &&
target.side === order.side &&
target.reduceOnly === reduceOnly &&
price === target.price
orderPrice === target.price // 直接使用字符串比较
);
});
if (matchedIndex >= 0) {