feat(maker-points): enhance configuration for maker points bands

Added new configuration options for maker points bands, including target distances and maximum distance limits. Updated the logic to handle these configurations, ensuring backward compatibility with existing defaults. Enhanced documentation and tests to cover the new features and ensure correct functionality across the system.
This commit is contained in:
discountry
2026-08-18 15:16:49 +08:00
parent f3a96886ac
commit 85954461f3
16 changed files with 1085 additions and 306 deletions
+68 -1
View File
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { resolveSymbolFromEnv } from "../src/config";
const ORIGINAL_ENV = { ...process.env };
@@ -72,3 +72,70 @@ describe("resolveSymbolFromEnv", () => {
expect(resolveSymbolFromEnv("ondoperp")).toBe("ETH-USD.P");
});
});
describe("makerPointsConfig defaults", () => {
async function loadConfig(env: Record<string, string> = {}) {
for (const key of Object.keys(process.env)) {
if (key.startsWith("MAKER_POINTS_")) delete process.env[key];
}
process.env.EXCHANGE = "standx";
Object.assign(process.env, env);
vi.resetModules();
return (await import("../src/config")).makerPointsConfig;
}
it("runs on sane defaults when none of the new vars are set", async () => {
const config = await loadConfig();
expect(config.band0To10Bps).toBe(9);
expect(config.band10To30Bps).toBe(29);
expect(config.band30To100Bps).toBe(40);
expect(config.maxDistanceBps).toBe(95);
expect(config.minRepriceBps).toBe(3);
expect(config.bandRepriceRatio).toBe(0.15);
expect(config.slOffsetBps).toBe(2);
for (const [key, value] of Object.entries(config)) {
if (typeof value === "number") {
expect(Number.isFinite(value), `${key} must be finite`).toBe(true);
}
}
});
it("falls back to defaults for unparseable values", async () => {
const config = await loadConfig({
MAKER_POINTS_BAND_0_10_BPS: "abc",
MAKER_POINTS_BAND_REPRICE_RATIO: "",
MAKER_POINTS_SL_OFFSET_BPS: "not-a-number",
});
expect(config.band0To10Bps).toBe(9);
expect(config.bandRepriceRatio).toBe(0.15);
expect(config.slOffsetBps).toBe(2);
});
it("never lets the distance cap sit inside an enabled band", async () => {
// 否则夹回会把挂单推向盘口,正好是最容易成交的方向
const config = await loadConfig({
MAKER_POINTS_MAX_DISTANCE_BPS: "20",
MAKER_POINTS_BAND_30_100_BPS: "60",
});
expect(config.maxDistanceBps).toBe(60);
});
it("ignores a disabled band when widening the cap", async () => {
const config = await loadConfig({
MAKER_POINTS_MAX_DISTANCE_BPS: "20",
MAKER_POINTS_BAND_30_100: "false",
MAKER_POINTS_BAND_30_100_BPS: "60",
});
expect(config.maxDistanceBps).toBe(29);
});
it("caps the distance at the zero-points cliff", async () => {
const config = await loadConfig({ MAKER_POINTS_MAX_DISTANCE_BPS: "500" });
expect(config.maxDistanceBps).toBe(100);
});
});