Bot & Automation
Treding Forex Ai
/root/hermes-projects/Treding Forex Ai
tests/riskManager.test.ts
text
import { describe, expect, it } from "vitest";
import { MARKET_SYMBOLS } from "../src/constants/markets";
import type { TradingSignal } from "../src/domain/types";
import { RiskManager } from "../src/services/riskManager";
describe("RiskManager", () => {
it("rejects WAIT signal", () => {
const manager = new RiskManager({
accountBalance: 1000,
riskPerTradePercent: 1,
maxDailyLossPercent: 3,
maxOpenTrades: 3,
maxLotPerOrder: 1
});
const signal = buildSignal("WAIT");
const decision = manager.evaluate(signal, 0, 0);
expect(decision.accepted).toBe(false);
expect(decision.reasons.join(" ")).toContain("WAIT");
});
it("creates position sizing for valid BUY signal", () => {
const manager = new RiskManager({
accountBalance: 1000,
riskPerTradePercent: 1,
maxDailyLossPercent: 3,
maxOpenTrades: 3,
maxLotPerOrder: 1
});
const decision = manager.evaluate(buildSignal("BUY"), 0, 0);
expect(decision.accepted).toBe(true);
expect(decision.positionSizing?.lotSize).toBeGreaterThan(0);
});
});
function buildSignal(action: "BUY" | "SELL" | "WAIT"): TradingSignal {
const symbol = MARKET_SYMBOLS[0];
return {
id: "test-signal",
symbol,
mode: "intraday",
timeframe: "H1",
action,
confidence: action === "WAIT" ? 40 : 75,
currentPrice: 1.085,
trend: "Bullish terstruktur",
entry: action === "WAIT" ? null : 1.085,
stopLoss: action === "WAIT" ? null : 1.083,
takeProfit1: action === "WAIT" ? null : 1.089,
takeProfit2: action === "WAIT" ? null : 1.09,
riskLevel: "Medium",
riskRewardRatio: action === "WAIT" ? 0 : 2,
reasons: ["test"],
invalidation: "test",
snapshot: {
ema20: 1.086,
ema50: 1.084,
ema200: 1.08,
rsi: 55,
atr: 0.001,
macdHistogram: 0.01,
support: 1.08,
resistance: 1.09,
volatilityPercent: 0.2
},
createdAt: new Date().toISOString()
};
}