a
This commit is contained in:
parent
6341bacc20
commit
14b5acae09
|
|
@ -588,14 +588,24 @@ class ConfigManager:
|
|||
# 账号私有:API Key/Secret/Testnet 从 accounts 表读取(不走 trading_config)
|
||||
if key in ("BINANCE_API_KEY", "BINANCE_API_SECRET", "USE_TESTNET") and Account is not None:
|
||||
try:
|
||||
api_key, api_secret, use_testnet = Account.get_credentials(self.account_id)
|
||||
api_key, api_secret, use_testnet, status = Account.get_credentials(self.account_id)
|
||||
logger.debug(f"ConfigManager.get({key}, account_id={self.account_id}): api_key存在={bool(api_key)}, api_secret存在={bool(api_secret)}, status={status}")
|
||||
if key == "BINANCE_API_KEY":
|
||||
return api_key if api_key else default
|
||||
# 如果 api_key 为空字符串,返回 None 而不是 default(避免返回 'your_api_key_here')
|
||||
if not api_key or api_key.strip() == "":
|
||||
logger.warning(f"ConfigManager.get(BINANCE_API_KEY, account_id={self.account_id}): API密钥为空字符串")
|
||||
return None # 返回 None,让调用方知道密钥未配置
|
||||
return api_key
|
||||
if key == "BINANCE_API_SECRET":
|
||||
return api_secret if api_secret else default
|
||||
# 如果 api_secret 为空字符串,返回 None 而不是 default(避免返回 'your_api_secret_here')
|
||||
if not api_secret or api_secret.strip() == "":
|
||||
logger.warning(f"ConfigManager.get(BINANCE_API_SECRET, account_id={self.account_id}): API密钥Secret为空字符串")
|
||||
return None # 返回 None,让调用方知道密钥未配置
|
||||
return api_secret
|
||||
return bool(use_testnet)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
# 回退到后续逻辑(旧数据/无表)
|
||||
logger.warning(f"ConfigManager.get({key}, account_id={self.account_id}): Account.get_credentials 失败: {e}")
|
||||
pass
|
||||
|
||||
# 1. 优先从Redis缓存读取(最新)
|
||||
|
|
|
|||
|
|
@ -174,23 +174,29 @@ async def main():
|
|||
logger.warning(f"重新加载配置失败: {e}", exc_info=True)
|
||||
|
||||
# 检查API密钥(重新获取,确保是最新值)
|
||||
# 优先直接从 config_manager 获取(使用正确的 account_id)
|
||||
api_key = None
|
||||
api_secret = None
|
||||
|
||||
if config._config_manager:
|
||||
try:
|
||||
# 直接从 config_manager 获取(会调用 Account.get_credentials,使用正确的 account_id)
|
||||
api_key = config._config_manager.get('BINANCE_API_KEY')
|
||||
api_secret = config._config_manager.get('BINANCE_API_SECRET')
|
||||
logger.info(f"从config_manager获取API密钥: KEY存在={bool(api_key)}, SECRET存在={bool(api_secret)}")
|
||||
if api_key:
|
||||
logger.info(f"API_KEY前4位: {api_key[:4]}...")
|
||||
except Exception as e:
|
||||
logger.warning(f"从config_manager获取API密钥失败: {e}")
|
||||
|
||||
# 如果从 config_manager 获取失败,尝试从 _get_config_value 获取(兜底)
|
||||
if not api_key or api_key == 'your_api_key_here':
|
||||
api_key = config._get_config_value('BINANCE_API_KEY', '')
|
||||
logger.info(f"从_get_config_value获取API_KEY: 存在={bool(api_key)}")
|
||||
|
||||
if not api_secret or api_secret == 'your_api_secret_here':
|
||||
api_secret = config._get_config_value('BINANCE_API_SECRET', '')
|
||||
|
||||
# 如果从配置管理器获取失败,尝试直接从config_manager获取
|
||||
if (not api_key or api_key == 'your_api_key_here') and config._config_manager:
|
||||
try:
|
||||
api_key = config._config_manager.get('BINANCE_API_KEY', '')
|
||||
logger.info(f"直接从config_manager获取API_KEY: 存在={bool(api_key)}")
|
||||
except Exception as e:
|
||||
logger.warning(f"从config_manager获取API_KEY失败: {e}")
|
||||
|
||||
if (not api_secret or api_secret == 'your_api_secret_here') and config._config_manager:
|
||||
try:
|
||||
api_secret = config._config_manager.get('BINANCE_API_SECRET', '')
|
||||
logger.info(f"直接从config_manager获取API_SECRET: 存在={bool(api_secret)}")
|
||||
except Exception as e:
|
||||
logger.warning(f"从config_manager获取API_SECRET失败: {e}")
|
||||
logger.info(f"从_get_config_value获取API_SECRET: 存在={bool(api_secret)}")
|
||||
|
||||
logger.info(f"API密钥检查: KEY存在={bool(api_key)}, SECRET存在={bool(api_secret)}")
|
||||
if api_key and api_key != 'your_api_key_here' and len(api_key) > 4:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user