更新策略工具测试,添加 markPrice 字段以确保返回的默认位置和提取位置包含最新信息。

This commit is contained in:
discountry
2025-09-25 10:20:09 +08:00
parent 911e0d4162
commit 5c420f8a5f
+3 -3
View File
@@ -34,17 +34,17 @@ const mockKlines = (values: number[]): AsterKline[] =>
describe("strategy utils", () => {
it("returns default position when snapshot missing", () => {
expect(getPosition(null, "BTCUSDT")).toEqual({ positionAmt: 0, entryPrice: 0, unrealizedProfit: 0 });
expect(getPosition(null, "BTCUSDT")).toEqual({ positionAmt: 0, entryPrice: 0, unrealizedProfit: 0, markPrice: null });
});
it("extracts position for symbol", () => {
const snapshot = mockSnapshot([{ symbol: "BTCUSDT", amt: 1, entry: 100, pnl: 5 }]);
expect(getPosition(snapshot, "BTCUSDT")).toEqual({ positionAmt: 1, entryPrice: 100, unrealizedProfit: 5 });
expect(getPosition(snapshot, "BTCUSDT")).toEqual({ positionAmt: 1, entryPrice: 100, unrealizedProfit: 5, markPrice: null });
});
it("returns zero position when symbol not found", () => {
const snapshot = mockSnapshot([{ symbol: "ETHUSDT", amt: 2, entry: 200, pnl: 10 }]);
expect(getPosition(snapshot, "BTCUSDT")).toEqual({ positionAmt: 0, entryPrice: 0, unrealizedProfit: 0 });
expect(getPosition(snapshot, "BTCUSDT")).toEqual({ positionAmt: 0, entryPrice: 0, unrealizedProfit: 0, markPrice: null });
});
it("returns null when not enough klines", () => {