Refactor price calculation in MakerPointsEngine for improved accuracy

- Replaced direct price calculations with a new method `normalizeDepthTargetPrice` to ensure valid target prices for buy and sell orders.
- Updated all instances of price calculations in the MakerPointsEngine to utilize the new normalization method.
- Added boundary tests for `getDepthBetweenPrices` to validate behavior when prices are exactly at the target.
This commit is contained in:
discountry
2026-02-07 23:27:42 +08:00
parent b8942c18e6
commit 6998afebb1
2 changed files with 69 additions and 22 deletions
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { getDepthBetweenPrices } from "../src/utils/price";
import type { AsterDepth } from "../src/exchanges/types";
describe("getDepthBetweenPrices boundary", () => {
it("SELL side excludes quantity exactly at target price", () => {
const depth: AsterDepth = {
lastUpdateId: 1,
bids: [],
asks: [
["69345", "1"],
["69349", "2"],
["69350", "999"],
["69351", "3"],
],
};
const total = getDepthBetweenPrices(depth, "SELL", 69350);
expect(total).toBe(3); // 仅 69345 + 69349
});
it("BUY side excludes quantity exactly at target price", () => {
const depth: AsterDepth = {
lastUpdateId: 1,
bids: [
["69355", "1"],
["69351", "2"],
["69350", "999"],
["69349", "3"],
],
asks: [],
};
const total = getDepthBetweenPrices(depth, "BUY", 69350);
expect(total).toBe(3); // 仅 69355 + 69351
});
});