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.80, 'number', 'risk', '第二目标/单目标止盈80%(保证金百分比)'), ('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.10, 'number', 'risk', '移动止损保护阈值(保证金百分比)'), ('LEVERAGE', 8, 'number', 'risk', '基础杠杆倍数'), ('RISK_REWARD_RATIO', 3.0, 'number', 'risk', '盈亏比目标'), ('ATR_TAKE_PROFIT_MULTIPLIER', 6.0, 'number', 'risk', 'ATR止盈倍数'), ('ATR_STOP_LOSS_MULTIPLIER', 3.0, 'number', 'risk', 'ATR止损倍数'), ('USE_FIXED_RISK_SIZING', True, 'bool', 'risk', '是否使用固定风险仓位计算'), ('FIXED_RISK_PERCENT', 0.03, 'number', 'risk', '每笔交易固定风险百分比'), ('MAX_LEVERAGE_SMALL_CAP', 8, 'number', 'risk', '小众币最大杠杆'), ('MIN_MARGIN_USDT', 2.0, 'number', 'risk', '最小保证金(USDT)') ] 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()