Implemented 3 critical risk checks in /api/trading/check-risk: 1. Daily Drawdown Check - Blocks trades if today's P&L < maxDailyDrawdown - Prevents catastrophic daily losses - Currently: -0 limit (configurable via MAX_DAILY_DRAWDOWN) 2. Hourly Trade Limit - Blocks trades if tradesInLastHour >= maxTradesPerHour - Prevents overtrading / algorithm malfunction - Currently: 20 trades/hour (configurable via MAX_TRADES_PER_HOUR) 3. Cooldown Period - Blocks trades if timeSinceLastTrade < minTimeBetweenTrades - Enforces breathing room between trades - Uses minutes (not seconds) thanks to previous commit - Currently: 0 min = disabled (configurable via MIN_TIME_BETWEEN_TRADES) Added database helper functions: - getLastTradeTime() - Returns timestamp of most recent trade - getTradesInLastHour() - Counts trades in last 60 minutes - getTodayPnL() - Sums realized P&L since midnight All checks include detailed logging with values and thresholds. Risk check called by n8n workflow before every trade execution.
11 KiB
11 KiB