This commit is contained in:
薇薇安 2026-02-13 23:29:33 +08:00
parent 213e31142c
commit f8058083e3
4 changed files with 23 additions and 20 deletions

View File

@ -101,7 +101,7 @@ class GlobalStrategyConfigManager:
self._cache = {} self._cache = {}
self._redis_client: Optional[redis.Redis] = None self._redis_client: Optional[redis.Redis] = None
self._redis_connected = False 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._init_redis()
self._load_from_db() self._load_from_db()

View File

@ -7,15 +7,18 @@ from pathlib import Path
backend_dir = Path(__file__).parent / 'backend' backend_dir = Path(__file__).parent / 'backend'
sys.path.insert(0, str(backend_dir)) sys.path.insert(0, str(backend_dir))
try: from database.models import GlobalStrategyConfig, TradingConfig
from database.models import GlobalStrategyConfig from database.connection import db
from database.connection import db
print("Checking DB values...")
keys = ["TAKE_PROFIT_1_PERCENT", "STOP_LOSS_PERCENT", "TAKE_PROFIT_PERCENT"] keys = ['TAKE_PROFIT_PERCENT', 'TAKE_PROFIT_1_PERCENT', 'STOP_LOSS_PERCENT']
for k in keys:
val = GlobalStrategyConfig.get_value(k) print("--- GlobalStrategyConfig ---")
raw = GlobalStrategyConfig.get(k) for key in keys:
print(f"{k}: get_value={val}, raw_db={raw.get('config_value') if raw else 'None'}") val = GlobalStrategyConfig.get_value(key)
print(f"{key}: {val} (Type: {type(val)})")
except Exception as e:
print(f"Error: {e}") 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']}")

View File

@ -791,7 +791,7 @@ const ConfigPanel = () => {
key, key,
value: value:
(key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key)
? value / 100 ? value
: value, : value,
type, type,
category, category,
@ -802,7 +802,7 @@ const ConfigPanel = () => {
key, key,
value: value:
(key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key)
? value / 100 ? value
: value, : value,
type: config.type, type: config.type,
category: config.category, category: config.category,
@ -1267,7 +1267,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
return formatPercent(numVal <= 0.05 ? numVal * 100 : numVal) return formatPercent(numVal <= 0.05 ? numVal * 100 : numVal)
} }
// 0.30>1 // 0.30>1
return formatPercent(numVal <= 1 ? numVal : numVal / 100) return formatPercent(numVal)
} }
return val === null || val === undefined ? '' : val return val === null || val === undefined ? '' : val
} }
@ -1311,7 +1311,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
} else if (localValue === '.' || localValue === '-.') { } else if (localValue === '.' || localValue === '-.') {
// "." "-." // "." "-."
const restoreValue = isPercentKey const restoreValue = isPercentKey
? (typeof value === 'number' ? formatPercent(value <= 1 ? value : value / 100) : value) ? (typeof value === 'number' ? formatPercent(value) : value)
: value : value
setLocalValue(restoreValue) setLocalValue(restoreValue)
return return
@ -1325,7 +1325,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
if (isNaN(numValue)) { if (isNaN(numValue)) {
// //
const restoreValue = isPercentKey const restoreValue = isPercentKey
? (typeof value === 'number' ? formatPercent(value <= 1 ? value : value / 100) : value) ? (typeof value === 'number' ? formatPercent(value) : value)
: value : value
setLocalValue(restoreValue) setLocalValue(restoreValue)
return return

View File

@ -638,7 +638,7 @@ const GlobalConfig = () => {
return { return {
key, key,
value: (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) ? value / 100 : value, value,
type, type,
category, category,
description: `预设方案配置项:${key}` description: `预设方案配置项:${key}`
@ -646,7 +646,7 @@ const GlobalConfig = () => {
} }
return { return {
key, key,
value: (key.includes('PERCENT') || key.includes('PCT')) && !PCT_LIKE_KEYS.has(key) ? value / 100 : value, value,
type: config.type, type: config.type,
category: config.category, category: config.category,
description: config.description description: config.description