HKUDS/Vibe-Trading · error · RuntimeError

TUSHARE_TOKEN not in agent/.env or environment; required for

Error message

TUSHARE_TOKEN not in agent/.env or environment; required for csi300 universe

What it means

The csi300 universe pulls constituents from Tushare, which requires a token. This RuntimeError fires when the configured tushare_token is empty or still the placeholder 'your-tushare-token' from agent/.env.

Source

Thrown at agent/src/tools/alpha_bench_tool.py:318

    "AAPL", "MSFT", "NVDA", "GOOGL", "AMZN", "META", "TSLA", "BRK-B",
    "JPM", "JNJ", "V", "PG", "UNH", "MA", "HD", "XOM", "LLY", "MRK",
    "PEP", "KO", "ABBV", "AVGO", "CVX", "WMT", "COST", "ADBE", "MCD",
    "CRM", "ACN", "BAC", "TMO", "ORCL", "CSCO", "ABT", "WFC", "DHR",
    "VZ", "PFE", "INTC", "DIS", "CMCSA", "AMD", "TXN", "PM", "QCOM",
    "NEE", "RTX", "HON", "T", "IBM",
]


def _load_csi300_panel(start: str, end: str) -> dict[str, pd.DataFrame]:
    """CSI 300 panel via Tushare. Includes ``amount`` (required by gtja191).

    Constituents are taken from the most recent ``index_weight`` snapshot in
    the requested window; if that call fails we degrade to a 30-name
    blue-chip fallback so the bench still runs.
    """
    token = get_env_config().data.tushare_token.strip()
    if not token or token == "your-tushare-token":
        raise RuntimeError(
            "TUSHARE_TOKEN not in agent/.env or environment; required for csi300 universe"
        )

    try:
        import tushare as ts
    except ImportError as exc:
        raise RuntimeError(f"tushare not installed: {exc}") from exc

    pro = ts.pro_api(token)
    sd = start.replace("-", "")
    ed = end.replace("-", "")

    codes: list[str] = []
    constituent_source = "tushare index_weight"
    constituent_source_date: str | None = None
    membership: pd.DataFrame | None = None
    try:
        # Reach back before ``start`` so the snapshot that was in force on the

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Set TUSHARE_TOKEN in agent/.env or the shell environment with a real token from tushare.pro
  2. Ensure the value is non-empty and not the literal 'your-tushare-token'
  3. Register a Tushare account with enough points for index_weight/adj_factor access

Example fix

# agent/.env
# before
TUSHARE_TOKEN=your-tushare-token
# after
TUSHARE_TOKEN=<real-token-from-tushare.pro>
Defensive patterns

Strategy: validation

Validate before calling

from src.config import get_env_config
tok = get_env_config().data.tushare_token.strip()
assert tok and tok != 'your-tushare-token', 'set TUSHARE_TOKEN in agent/.env'

Type guard

def has_tushare_token() -> bool:
    tok = get_env_config().data.tushare_token.strip()
    return bool(tok) and tok != 'your-tushare-token'

Try / catch

try:
    _load_csi300_panel(s, e)
except RuntimeError as e:
    if 'TUSHARE_TOKEN' in str(e):
        prompt_user_for_token(); return

Prevention

When it happens

Trigger: Calling _load_universe_panel(universe='csi300', ...) with no TUSHARE_TOKEN in the environment and an unset/placeholder value in agent/.env.

Common situations: Fresh clones that copy .env.example without filling values; CI environments without secrets; tokens named differently (TUSHARE_API_KEY) so the config lookup misses.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/7bdcf5f8c0543fbc. Report an issue: GitHub.