-- Migration: Add JSON Strategy Config to Trade Profiles
-- Date: 2026-02-04
-- Purpose: Enable Per-Profile Strategy Rules & Risk Configuration

ALTER TABLE trade_profiles 
ADD COLUMN IF NOT EXISTS strategy_config jsonb DEFAULT '{
  "rules": [
    { "ruleId": "TrendBiasRule", "enabled": true, "params": { "timeframe": "4h", "emaFast": 50, "emaSlow": 200 } },
    { "ruleId": "SessionRule", "enabled": true, "params": { "allowedSessions": ["NY", "LDN"] } },
    { "ruleId": "ZoneRule", "enabled": true, "params": { "emaPeriod": 20, "tolerancePercent": 0.5 } },
    { "ruleId": "MomentumRule", "enabled": true, "params": { "timeframe": "1h", "rsiPeriod": 14, "rsiOverbought": 70, "rsiOversold": 30 } },
    { "ruleId": "EntryTriggerRule", "enabled": true, "params": { "triggerType": "ema_cross" } },
    { "ruleId": "RiskManagementRule", "enabled": true, "params": { "atrPeriod": 14, "riskRewardRatio": 1.5 } },
    { "ruleId": "AIAnalysisRule", "enabled": false, "params": { "minConfidence": 80 } }
  ],
  "riskLimits": {
    "maxDailyLossUsd": 50,
    "maxConsecutiveLosses": 2,
    "maxOpenTrades": 3
  },
  "execution": {
    "orderType": "market",
    "cooldownMinutes": 30,
    "entryMode": "both"
  }
}'::jsonb;

COMMENT ON COLUMN trade_profiles.strategy_config IS 'JSON configuration for active strategy rules, risk limits, and execution settings per profile.';
