跳到主要内容

数据提供商

本文档介绍了 OpenBB 平台支持的各种数据提供商及其配置方法。

免费数据提供商

Yahoo Finance

特点

  • 免费使用
  • 股票、ETF、指数数据
  • 历史价格数据
  • 无需 API 密钥

使用示例

import openbb

data = openbb.equity.price.historical("AAPL", provider="yfinance")

FRED (Federal Reserve Economic Data)

特点

  • 美国经济数据
  • 免费使用
  • 需要 API 密钥(免费申请)

配置

openbb.account.credentials.fred_api_key = "your_fred_api_key"

付费数据提供商

Alpha Vantage

特点

  • 股票、外汇、加密货币数据
  • 免费层级:每分钟 5 次请求
  • 付费计划:更高请求限制

配置

openbb.account.credentials.alpha_vantage_api_key = "your_api_key"

使用示例

data = openbb.equity.price.historical("AAPL", provider="alpha_vantage")

Polygon

特点

  • 实时和历史市场数据
  • 股票、期权、外汇、加密货币
  • 高质量数据

配置

openbb.account.credentials.polygon_api_key = "your_api_key"

Quandl

特点

  • 金融和经济数据
  • 多种数据集
  • 现已被 Nasdaq 收购

配置

openbb.account.credentials.quandl_api_key = "your_api_key"

企业级数据提供商

Bloomberg Terminal

特点

  • 专业级金融数据
  • 实时市场数据
  • 需要 Bloomberg 终端订阅

Refinitiv (formerly Thomson Reuters)

特点

  • 全球金融市场数据
  • 企业级解决方案
  • 需要企业订阅

配置管理

环境变量

export OPENBB_ALPHA_VANTAGE_API_KEY="your_key"
export OPENBB_FRED_API_KEY="your_key"
export OPENBB_POLYGON_API_KEY="your_key"

配置文件

# 保存配置
openbb.account.save()

# 加载配置
openbb.account.load()

运行时配置

# 临时设置(仅当前会话有效)
openbb.account.credentials.alpha_vantage_api_key = "temp_key"

选择数据提供商

按需求选择

需求推荐提供商
免费股票数据Yahoo Finance
美国经济数据FRED
高频交易数据Polygon
全球市场数据Alpha Vantage
企业级应用Bloomberg, Refinitiv

性能考虑

  • 延迟: 实时数据 vs 延迟数据
  • 限制: API 请求限制
  • 可靠性: 服务可用性
  • 成本: 免费 vs 付费计划

故障排除

常见问题

  1. API 密钥错误

    • 检查密钥是否正确
    • 确认密钥未过期
  2. 请求限制

    • 检查当前使用量
    • 考虑升级计划
  3. 数据不可用

    • 尝试不同的提供商
    • 检查数据是否存在

调试技巧

# 检查可用提供商
print(openbb.equity.price.historical.__doc__)

# 查看错误详情
import logging
logging.basicConfig(level=logging.DEBUG)