diff --git a/trading_system/config.py b/trading_system/config.py index 8532267..eb92a68 100644 --- a/trading_system/config.py +++ b/trading_system/config.py @@ -83,19 +83,32 @@ def _init_config_manager(): # 尝试导入 try: print("[配置管理器] 尝试导入config_manager...") - from config_manager import config_manager # type: ignore + from config_manager import ConfigManager # type: ignore print("[配置管理器] ✓ 导入成功") + # 从环境变量获取 account_id(trading_system 进程通过 ATS_ACCOUNT_ID 指定) + try: + account_id = int(os.getenv("ATS_ACCOUNT_ID") or os.getenv("ACCOUNT_ID") or 1) + except Exception: + account_id = 1 + print(f"[配置管理器] 使用 account_id={account_id} (从环境变量 ATS_ACCOUNT_ID 读取)") + + # 为当前账号创建 ConfigManager 实例(而不是使用全局的) + config_manager = ConfigManager.for_account(account_id) + print(f"[配置管理器] ✓ 已创建 ConfigManager 实例 (account_id={account_id})") + # 测试数据库连接 try: print("[配置管理器] 测试数据库连接...") config_manager.reload() print(f"[配置管理器] ✓ 数据库连接成功,已加载 {len(config_manager._cache)} 个配置项") - # 检查API密钥 + # 检查API密钥(使用正确的 account_id) api_key = config_manager.get('BINANCE_API_KEY') api_secret = config_manager.get('BINANCE_API_SECRET') print(f"[配置管理器] API密钥检查: KEY存在={bool(api_key)}, SECRET存在={bool(api_secret)}") + if api_key and api_key != 'your_api_key_here': + print(f"[配置管理器] API_KEY前4位: {api_key[:4]}...") _config_manager = config_manager USE_DB_CONFIG = True