-- =============================================
-- 交易模拟引擎数据库迁移
-- =============================================

-- 1. coin表新增模拟引擎配置字段
ALTER TABLE coin ADD COLUMN volatility_min DECIMAL(8,6) DEFAULT 0.000100 COMMENT '最小波动率(每tick)';
ALTER TABLE coin ADD COLUMN volatility_max DECIMAL(8,6) DEFAULT 0.003000 COMMENT '最大波动率(每tick)';
ALTER TABLE coin ADD COLUMN tick_interval_ms INT DEFAULT 3000 COMMENT '报价刷新间隔(毫秒)';
ALTER TABLE coin ADD COLUMN simulation_enabled TINYINT DEFAULT 1 COMMENT '是否启用模拟:0否1是';

-- 2. Java实体已有但DB缺失的字段
ALTER TABLE coin ADD COLUMN trade_start_time VARCHAR(10) DEFAULT NULL COMMENT '交易开始时间HH:mm';
ALTER TABLE coin ADD COLUMN trade_end_time VARCHAR(10) DEFAULT NULL COMMENT '交易结束时间HH:mm';
ALTER TABLE coin ADD COLUMN max_change_percent DECIMAL(6,2) DEFAULT 10.00 COMMENT '日最大涨跌幅%';
ALTER TABLE coin ADD COLUMN circulating_supply DECIMAL(20,4) DEFAULT NULL COMMENT '流通量';

-- 3. 初始化各币种模拟配置
UPDATE coin SET volatility_min=0.000100, volatility_max=0.002000, tick_interval_ms=3000 WHERE code='BTC';
UPDATE coin SET volatility_min=0.000200, volatility_max=0.003000, tick_interval_ms=3000 WHERE code='ETH';
UPDATE coin SET volatility_min=0.000300, volatility_max=0.005000, tick_interval_ms=2500 WHERE code='SOL';
UPDATE coin SET volatility_min=0.000500, volatility_max=0.008000, tick_interval_ms=2000 WHERE code='DOGE';
UPDATE coin SET volatility_min=0.000200, volatility_max=0.004000, tick_interval_ms=2500 WHERE code='XRP';
UPDATE coin SET simulation_enabled=0 WHERE code='USDT';

-- 4. 初始化24h统计数据（基于当前价格）
UPDATE coin SET high_24h = price, low_24h = price, volume_24h = 0, change_24h = 0 WHERE code != 'USDT';

-- =============================================
-- V3: 交易时段 + 目标价格范围
-- =============================================

-- 5. coin表新增交易时段和目标价格字段
ALTER TABLE coin ADD COLUMN trade_start_am VARCHAR(5) DEFAULT '09:00' COMMENT '上午开盘时间(HH:mm)';
ALTER TABLE coin ADD COLUMN trade_end_am VARCHAR(5) DEFAULT '12:00' COMMENT '上午收盘时间(HH:mm)';
ALTER TABLE coin ADD COLUMN trade_start_pm VARCHAR(5) DEFAULT '13:00' COMMENT '下午开盘时间(HH:mm)';
ALTER TABLE coin ADD COLUMN trade_end_pm VARCHAR(5) DEFAULT '17:00' COMMENT '下午收盘时间(HH:mm)';
ALTER TABLE coin ADD COLUMN target_low DECIMAL(20,8) DEFAULT NULL COMMENT '今日目标最低价';
ALTER TABLE coin ADD COLUMN target_high DECIMAL(20,8) DEFAULT NULL COMMENT '今日目标最高价';
ALTER TABLE coin ADD COLUMN target_close DECIMAL(20,8) DEFAULT NULL COMMENT '今日目标收盘价';
