mindesbunister
7c4adff4e4
Implement risk checks: cooldown, hourly limit, and daily drawdown
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.
2025-10-30 10:50:08 +01:00
..
2025-10-30 10:50:08 +01:00
2025-10-29 20:51:46 +01:00
2025-10-24 14:24:36 +02:00
2025-10-27 23:27:48 +01:00
2025-10-30 07:37:10 +01:00