1
This commit is contained in:
parent
bbbac43506
commit
d16bb53e60
|
|
@ -98,7 +98,7 @@ class GlobalStrategyConfigManager:
|
|||
self._cache = {}
|
||||
self._redis_client: Optional[redis.Redis] = None
|
||||
self._redis_connected = False
|
||||
self._redis_hash_key = "global_strategy_config" # 独立的Redis键
|
||||
self._redis_hash_key = "global_strategy_config_v2" # 独立的Redis键 (v2: 强制刷新缓存)
|
||||
self._init_redis()
|
||||
self._load_from_db()
|
||||
|
||||
|
|
|
|||
|
|
@ -330,12 +330,12 @@ class TradingConfig:
|
|||
@staticmethod
|
||||
def _convert_value(value, config_type):
|
||||
"""转换配置值类型"""
|
||||
if config_type == 'number':
|
||||
if config_type in ('number', 'float', 'int', 'integer'):
|
||||
try:
|
||||
return float(value) if '.' in str(value) else int(value)
|
||||
except:
|
||||
return 0
|
||||
elif config_type == 'boolean':
|
||||
elif config_type in ('boolean', 'bool'):
|
||||
return str(value).lower() in ('true', '1', 'yes', 'on')
|
||||
elif config_type == 'json':
|
||||
try:
|
||||
|
|
|
|||
69
update_global_config.py
Normal file
69
update_global_config.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Add backend to sys.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
|
||||
|
||||
# Check DB connection
|
||||
print("Checking DB connection...")
|
||||
db.execute_one("SELECT 1")
|
||||
print("DB connection successful.")
|
||||
|
||||
configs_to_update = [
|
||||
# Key, Value, Type, Category, Description
|
||||
('TAKE_PROFIT_PERCENT', 0.60, 'number', 'risk', '第二目标/单目标止盈60%(保证金百分比)'),
|
||||
('TAKE_PROFIT_1_PERCENT', 0.30, 'number', 'risk', '第一目标止盈30%(保证金百分比)'),
|
||||
('STOP_LOSS_PERCENT', 0.10, 'number', 'risk', '止损10%(保证金百分比)'),
|
||||
('TRAILING_STOP_ACTIVATION', 0.30, 'number', 'risk', '移动止损激活阈值(保证金百分比)'),
|
||||
('TRAILING_STOP_PROTECT', 0.05, 'number', 'risk', '移动止损保护阈值(保证金百分比)'),
|
||||
('LEVERAGE', 4, 'number', 'risk', '基础杠杆倍数'),
|
||||
('RISK_REWARD_RATIO', 3.0, 'number', 'risk', '盈亏比目标'),
|
||||
('ATR_TAKE_PROFIT_MULTIPLIER', 4.5, 'number', 'risk', 'ATR止盈倍数'),
|
||||
('ATR_STOP_LOSS_MULTIPLIER', 1.5, 'number', 'risk', 'ATR止损倍数'),
|
||||
('USE_FIXED_RISK_SIZING', True, 'bool', 'risk', '是否使用固定风险仓位计算'),
|
||||
('FIXED_RISK_PERCENT', 0.01, 'number', 'risk', '每笔交易固定风险百分比'),
|
||||
('MAX_LEVERAGE_SMALL_CAP', 4, 'number', 'risk', '小众币最大杠杆')
|
||||
]
|
||||
|
||||
print("Updating Global Strategy Config...")
|
||||
for key, value, type_, category, desc in configs_to_update:
|
||||
print(f"Updating {key} -> {value}")
|
||||
GlobalStrategyConfig.set(
|
||||
key=key,
|
||||
value=value,
|
||||
config_type=type_,
|
||||
category=category,
|
||||
description=desc,
|
||||
updated_by='admin_script'
|
||||
)
|
||||
|
||||
# Force Redis Cache Clear
|
||||
try:
|
||||
import redis
|
||||
print("Clearing Redis Cache...")
|
||||
r = redis.from_url('rediss://127.0.0.1:6379', decode_responses=True, ssl_cert_reqs='none')
|
||||
r.delete("global_strategy_config")
|
||||
print("Redis Cache Cleared.")
|
||||
except Exception as e:
|
||||
print(f"Redis clear failed: {e}")
|
||||
|
||||
|
||||
print("Update complete.")
|
||||
|
||||
# Verify updates
|
||||
print("\nVerifying updates:")
|
||||
for key, expected_value, _, _, _ in configs_to_update:
|
||||
actual_value = GlobalStrategyConfig.get_value(key)
|
||||
print(f"{key}: {actual_value} (Expected: {expected_value})")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
Loading…
Reference in New Issue
Block a user