From f8058083e339497e0ed00aa90fb64648bdb75bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Fri, 13 Feb 2026 23:29:33 +0800 Subject: [PATCH] 1 --- backend/config_manager.py | 2 +- check_db_values.py | 27 +++++++++++++----------- frontend/src/components/ConfigPanel.jsx | 10 ++++----- frontend/src/components/GlobalConfig.jsx | 4 ++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/backend/config_manager.py b/backend/config_manager.py index a1981cc..50e7527 100644 --- a/backend/config_manager.py +++ b/backend/config_manager.py @@ -101,7 +101,7 @@ class GlobalStrategyConfigManager: self._cache = {} self._redis_client: Optional[redis.Redis] = None self._redis_connected = False - self._redis_hash_key = "global_strategy_config_v2" # 独立的Redis键 (v2: 强制刷新缓存) + self._redis_hash_key = "global_strategy_config_v3" # 独立的Redis键 (v3: 强制刷新缓存 - 2025-02-13) self._init_redis() self._load_from_db() diff --git a/check_db_values.py b/check_db_values.py index 6e9cc05..c8bc52a 100644 --- a/check_db_values.py +++ b/check_db_values.py @@ -7,15 +7,18 @@ from pathlib import Path backend_dir = Path(__file__).parent / 'backend' sys.path.insert(0, str(backend_dir)) -try: - from database.models import GlobalStrategyConfig - from database.connection import db - - keys = ["TAKE_PROFIT_1_PERCENT", "STOP_LOSS_PERCENT", "TAKE_PROFIT_PERCENT"] - for k in keys: - val = GlobalStrategyConfig.get_value(k) - raw = GlobalStrategyConfig.get(k) - print(f"{k}: get_value={val}, raw_db={raw.get('config_value') if raw else 'None'}") - -except Exception as e: - print(f"Error: {e}") +from database.models import GlobalStrategyConfig, TradingConfig +from database.connection import db + +print("Checking DB values...") +keys = ['TAKE_PROFIT_PERCENT', 'TAKE_PROFIT_1_PERCENT', 'STOP_LOSS_PERCENT'] + +print("--- GlobalStrategyConfig ---") +for key in keys: + val = GlobalStrategyConfig.get_value(key) + print(f"{key}: {val} (Type: {type(val)})") + +print("\n--- TradingConfig (All Accounts) ---") +rows = db.execute_query("SELECT account_id, config_key, config_value FROM trading_config WHERE config_key IN ('TAKE_PROFIT_PERCENT', 'TAKE_PROFIT_1_PERCENT', 'STOP_LOSS_PERCENT') ORDER BY account_id") +for row in rows: + print(f"Account {row['account_id']} - {row['config_key']}: {row['config_value']}") diff --git a/frontend/src/components/ConfigPanel.jsx b/frontend/src/components/ConfigPanel.jsx index 7e0ee71..bfef6d1 100644 --- a/frontend/src/components/ConfigPanel.jsx +++ b/frontend/src/components/ConfigPanel.jsx @@ -791,7 +791,7 @@ const ConfigPanel = () => { key, value: (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) - ? value / 100 + ? value : value, type, category, @@ -802,7 +802,7 @@ const ConfigPanel = () => { key, value: (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) - ? value / 100 + ? value : value, type: config.type, category: config.category, @@ -1267,7 +1267,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => { return formatPercent(numVal <= 0.05 ? numVal * 100 : numVal) } // 常规比例型:直接显示数据库中的值(0.30),如果>1则可能是旧数据 - return formatPercent(numVal <= 1 ? numVal : numVal / 100) + return formatPercent(numVal) } return val === null || val === undefined ? '' : val } @@ -1311,7 +1311,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => { } else if (localValue === '.' || localValue === '-.') { // "." 或 "-." 视为无效,恢复原值 const restoreValue = isPercentKey - ? (typeof value === 'number' ? formatPercent(value <= 1 ? value : value / 100) : value) + ? (typeof value === 'number' ? formatPercent(value) : value) : value setLocalValue(restoreValue) return @@ -1325,7 +1325,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => { if (isNaN(numValue)) { // 如果输入无效,恢复原值 const restoreValue = isPercentKey - ? (typeof value === 'number' ? formatPercent(value <= 1 ? value : value / 100) : value) + ? (typeof value === 'number' ? formatPercent(value) : value) : value setLocalValue(restoreValue) return diff --git a/frontend/src/components/GlobalConfig.jsx b/frontend/src/components/GlobalConfig.jsx index e740951..454443f 100644 --- a/frontend/src/components/GlobalConfig.jsx +++ b/frontend/src/components/GlobalConfig.jsx @@ -638,7 +638,7 @@ const GlobalConfig = () => { return { key, - value: (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) ? value / 100 : value, + value, type, category, description: `预设方案配置项:${key}` @@ -646,7 +646,7 @@ const GlobalConfig = () => { } return { key, - value: (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) ? value / 100 : value, + value, type: config.type, category: config.category, description: config.description