{"record":{"id":"5a66dcc470f90185","repo":"hsliuping/TradingAgents-CN","slug":"stockstats-fail-yahoo-finance-data-not-fetched-ye","errorCode":null,"errorMessage":"Stockstats fail: Yahoo Finance data not fetched yet!","messagePattern":"Stockstats fail: Yahoo Finance data not fetched yet!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"tradingagents/dataflows/technical/stockstats.py","lineNumber":45,"sourceCode":"        online: Annotated[\n            bool,\n            \"whether to use online tools to fetch data or offline tools. If True, will use online tools.\",\n        ] = False,\n    ):\n        df = None\n        data = None\n\n        if not online:\n            try:\n                data = pd.read_csv(\n                    os.path.join(\n                        data_dir,\n                        f\"{symbol}-YFin-data-2015-01-01-2025-03-25.csv\",\n                    )\n                )\n                df = wrap(data)\n            except FileNotFoundError:\n                raise Exception(\"Stockstats fail: Yahoo Finance data not fetched yet!\")\n        else:\n            # Get today's date as YYYY-mm-dd to add to cache\n            today_date = pd.Timestamp.today()\n            curr_date = pd.to_datetime(curr_date)\n\n            end_date = today_date\n            start_date = today_date - pd.DateOffset(years=15)\n            start_date = start_date.strftime(\"%Y-%m-%d\")\n            end_date = end_date.strftime(\"%Y-%m-%d\")\n\n            # Get config and ensure cache directory exists\n            config = get_config()\n            os.makedirs(config[\"data_cache_dir\"], exist_ok=True)\n\n            data_file = os.path.join(\n                config[\"data_cache_dir\"],\n                f\"{symbol}-YFin-data-{start_date}-{end_date}.csv\",\n            )","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/dataflows/technical/stockstats.py#L27-L63","documentation":"Raised by get_stock_stats in stockstats.py when the local Yahoo Finance CSV for the symbol is not on disk in offline mode — the FileNotFoundError from reading {symbol}-YFin-data-2015-01-01-2025-03-25.csv is re-raised as a generic Exception with this message.","triggerScenarios":"Offline mode (not online=True) calling get_stock_stats for a symbol whose YFin CSV hasn't been downloaded into DATA_DIR/market_data/price_data/, so the open() raises FileNotFoundError.","commonSituations":"First use of a new symbol without running the data download step, wrong DATA_DIR, or offline usage after clearing the cache directory.","solutions":["Run the YFin data download/fetch step for the symbol first so the CSV exists","Or call the online variant (pass online/curr_date path that fetches from yfinance)","Check DATA_DIR points at the directory containing market_data/price_data/"],"exampleFix":"# before\ndf = get_stock_stats('MSFT', '2025-01-01')  # offline, no CSV\n# after\nfrom tradingagents.dataflows.yfin_utils import YFinanceUtils\nYFinanceUtils.download_data_one('MSFT')  # populate CSV first\ndf = get_stock_stats('MSFT', '2025-01-01')","handlingStrategy":"validation","validationCode":"import os, tradingagents.dataflows.technical.stockstats as ss\ncsv_path = os.path.join(ss.DATA_DIR, 'market_data/price_data', f'{symbol}-YFin-data-2015-01-01-2025-03-25.csv')\nif not os.path.exists(csv_path):\n    raise SystemExit(f'YFin data missing for {symbol}; download it first')\ndf = get_stock_stats(symbol, curr_date)","typeGuard":null,"tryCatchPattern":"try:\n    df = get_stock_stats(symbol, curr_date)\nexcept Exception as e:\n    if 'data not fetched yet' in str(e):\n        download_yfin_csv(symbol)  # then retry\n        df = get_stock_stats(symbol, curr_date)\n    else:\n        raise","preventionTips":["Download per-symbol YFin CSVs as a prefetch step in batch jobs","Verify DATA_DIR is set correctly in deployment","Use the online mode for symbols not in the offline bundle"],"tags":["python","stockstats","offline-data","filenotfound"],"backgroundTag":"missing-data-file","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}