[Bug] YFinance 行情源永远返回空: fast_info.get("last_price") 在 yfinance 1.7 下为 None / YFinance quotes always empty
What happened? / 发生了什么?
启用「YFinance 行情」数据源后,测试总是失败:
yfinance AAPL: 返回空(last_price 缺失,可能 Yahoo 不可达/被限流/需要代理)
但网络沒問題:在同一容器内直接调用 yfinance 能正常拿到价格。失败只用了 ~55ms,并不是网络超时。
After enabling the "YFinance 行情" data source, every symbol fails with the error above. Yahoo is reachable (calling yfinance directly in the same container works), and the test fails in ~55 ms, so it's not a network problem.
Steps to reproduce / 复现步骤
docker exec panwatch python -c '
import yfinance as yf
fi = yf.Ticker("AAPL").fast_info
print(fi["last_price"]) # 343.99
print(fi.get("last_price")) # None
print(fi.get("lastPrice")) # 343.99
'
Expected behavior / 预期行为
启用「YFinance 行情」并测试时,US/HK 标的(如 AAPL、NVDA、00700)应返回正常行情: 现价、昨收、开盘、最高、最低、成交量,测试通过。 与在同一容器内直接调用 yfinance 的结果一致(例如 AAPL 现价 343.99,昨收 338.0)。
When the "YFinance 行情" source is enabled and tested, US/HK symbols (e.g. AAPL, NVDA, 00700) should return valid quotes (current price, previous close, open, high, low, volume) and the test should pass, matching what yfinance returns when called directly in the same container (e.g. AAPL last price 343.99, previous close 338.0).
If Yahoo really is unreachable, the "可能 Yahoo 不可达/被限流/需要代理" error is fine, but it shouldn't appear when the data is actually available.
PanWatch version or commit / PanWatch 版本或提交
0.19.0
Installation method / 安装方式
Docker
Affected area / 影响范围
Market data / 行情数据, API / 后端接口
Sanitized logs, screenshots, or context / 脱敏日志、截图或补充信息
### 原因 / Root cause
`vendors/yfinance.py` 用 `info.get("last_price")` 判断有没有价格。在 yfinance 1.7.0 中,`fast_info` 的 `[]` 支持 snake_case,但 `.get()` 只认 camelCase(`fast_info.keys()` 只有 `lastPrice`、`previousClose`、`dayHigh`、`dayLow`、`lastVolume` 等)。所以 `.get("last_price")` 永远是 `None`,代码直接 `continue`,数据源永远返回空。
`vendors/yfinance.py` checks `info.get("last_price")`. In yfinance 1.7.0, `fast_info[...]` accepts snake_case keys, but `.get(...)` only knows the camelCase keys listed in `fast_info.keys()`. So `.get("last_price")` is always `None` and every symbol is skipped. `previous_close`, `day_high`, `day_low` and `last_volume` have the same problem.