hsliuping/TradingAgents-CN · error · ValueError

不支持的数据源: {self.current_source}

Error message

不支持的数据源: {self.current_source}

What it means

Raised by DataSourceManager.get_data_adapter() when self.current_source does not match any known ChinaDataSource enum branch (MongoDB/AKShare/BAOSTOCK; TDX was removed). It is a formatted message where {self.current_source} is interpolated at raise time.

Source

Thrown at tradingagents/dataflows/data_source_manager.py:564

            logger.info(f"✅ 数据源已切换到: {source.value}")
            return True
        else:
            logger.error(f"❌ 数据源不可用: {source.value}")
            return False

    def get_data_adapter(self):
        """获取当前数据源的适配器"""
        if self.current_source == ChinaDataSource.MONGODB:
            return self._get_mongodb_adapter()
        elif self.current_source == ChinaDataSource.TUSHARE:
            return self._get_tushare_adapter()
        elif self.current_source == ChinaDataSource.AKSHARE:
            return self._get_akshare_adapter()
        elif self.current_source == ChinaDataSource.BAOSTOCK:
            return self._get_baostock_adapter()
        # TDX 已移除
        else:
            raise ValueError(f"不支持的数据源: {self.current_source}")

    def _get_mongodb_adapter(self):
        """获取MongoDB适配器"""
        try:
            from tradingagents.dataflows.cache.mongodb_cache_adapter import get_mongodb_cache_adapter
            return get_mongodb_cache_adapter()
        except ImportError as e:
            logger.error(f"❌ MongoDB适配器导入失败: {e}")
            return None

    def _get_tushare_adapter(self):
        """获取Tushare提供器(原adapter已废弃,现在直接使用provider)"""
        try:
            from .providers.china.tushare import get_tushare_provider
            return get_tushare_provider()
        except ImportError as e:
            logger.error(f"❌ Tushare提供器导入失败: {e}")
            return None

View on GitHub (pinned to 74783e8817)

Solutions

  1. Set the source to a supported value: mongodb, akshare, or baostock
  2. If you depended on TDX, pin the older release or migrate to akshare/baostock
  3. Clear persisted datasource config that still stores 'tdx'

Example fix

# before
manager.current_source = 'tdx'
adapter = manager.get_data_adapter()
# after
from tradingagents.dataflows.datasource_config import ChinaDataSource
manager.current_source = ChinaDataSource.AKSHARE
adapter = manager.get_data_adapter()
Defensive patterns

Strategy: validation

Validate before calling

from tradingagents.dataflows.datasource_config import ChinaDataSource
valid = {s.value for s in ChinaDataSource}
if manager.current_source not in valid:
    raise ValueError(f'unsupported source; choose from {sorted(valid)}')
adapter = manager.get_data_adapter()

Type guard

def is_supported_source(src) -> bool:
    from tradingagents.dataflows.datasource_config import ChinaDataSource
    return src in list(ChinaDataSource)

Try / catch

try:
    adapter = manager.get_data_adapter()
except ValueError as e:
    if '不支持的数据源' in str(e):
        manager.current_source = ChinaDataSource.AKSHARE
        adapter = manager.get_data_adapter()
    else:
        raise

Prevention

When it happens

Trigger: Setting the data source to a stale value like 'tdx' or 'TDX' (removed), an arbitrary string not in ChinaDataSource, or a value loaded from persisted config written by an older version.

Common situations: Upgrade after TDX removal but old config/env still selects it; user typo in the datasource setting; enum member renamed between versions.

Related errors


AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28). Data as JSON: /api/errors/a174a9234197ea0b. Report an issue: GitHub.