mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 16:58:08 +00:00
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:
@@ -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
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user