auto_trade_sys/backend/database/add_global_strategy_config.sql
薇薇安 0c489bfdee a
2026-01-23 14:59:57 +08:00

46 lines
1.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 创建全局策略配置表(独立于账户)
-- 全局配置不依赖任何account_id由管理员统一管理
CREATE TABLE IF NOT EXISTS `global_strategy_config` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`config_key` VARCHAR(100) NOT NULL,
`config_value` TEXT NOT NULL,
`config_type` VARCHAR(50) NOT NULL COMMENT 'string, number, boolean, json',
`category` VARCHAR(50) NOT NULL COMMENT 'strategy, risk, scan',
`description` TEXT,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated_by` VARCHAR(50) COMMENT '更新人(用户名)',
INDEX `idx_category` (`category`),
UNIQUE KEY `uk_config_key` (`config_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='全局策略配置表(管理员专用)';
-- 迁移现有account_id=1的核心策略配置到全局配置表
-- 注意:只迁移非风险旋钮的配置
INSERT INTO `global_strategy_config` (`config_key`, `config_value`, `config_type`, `category`, `description`)
SELECT
`config_key`,
`config_value`,
`config_type`,
`category`,
`description`
FROM `trading_config`
WHERE `account_id` = 1
AND `config_key` NOT IN (
'MIN_MARGIN_USDT',
'MIN_POSITION_PERCENT',
'MAX_POSITION_PERCENT',
'MAX_TOTAL_POSITION_PERCENT',
'AUTO_TRADE_ENABLED',
'MAX_OPEN_POSITIONS',
'MAX_DAILY_ENTRIES',
'BINANCE_API_KEY',
'BINANCE_API_SECRET',
'USE_TESTNET'
)
ON DUPLICATE KEY UPDATE
`config_value` = VALUES(`config_value`),
`config_type` = VALUES(`config_type`),
`category` = VALUES(`category`),
`description` = VALUES(`description`),
`updated_at` = CURRENT_TIMESTAMP;