EODHD API Skill
This skill provides a comprehensive toolkit for interacting with the EOD Historical Data (EODHD) API, a powerful source for a wide range of financial data.
Core Principles
- 1. API Token First: Before using any function, ensure the user has provided an EODHD API token. The
config.json file must be updated with a valid token. If the token is missing or invalid, ask the user to provide one. - Use the Client: All API interactions MUST go through the provided Python client:
scripts/eodhd_client.py. This client handles authentication, request formation, and basic error handling. - Be Specific: When fetching data, use the most specific function available in the client. For example, use
get_dividends() for dividend data instead of a generic fundamental data call. - Handle Errors: The client returns an
{"error": "..."} dictionary on failure. Always check for this and report errors clearly to the user.
Setup: API Token Configuration
Before the first use, you must configure the API token. The user needs to provide their personal EODHD API key.
- 1. Ask the user for their EODHD API token.
- Write the token to the configuration file using the
file tool:
CODEBLOCK0
Workflow: Fetching Financial Data
Follow this general workflow to retrieve and use financial data from the EODHD API.
Step 1: Understand the User's Request
Identify the specific type of data the user needs. Is it historical prices, company fundamentals, news, or something else? Map their request to one of the available functions in the eodhd_client.py script.
Step 2: Instantiate the Client and Call the Method
Create a Python script to import and use the EODHDClient.
Example: Fetching Historical EOD Prices
CODEBLOCK1
Step 3: Execute the Script
Run the script using the shell tool.
CODEBLOCK2
Step 4: Process and Present the Data
Analyze the JSON output from the script. Present the information to the user in a clear and readable format, often using Markdown tables or summaries.
Available Client Functions
The eodhd_client.py script provides a high-level interface for the most common EODHD API endpoints. Refer to the script's docstrings for detailed usage of each function.
| Function | Description |
|---|
| INLINECODE9 | Fetches end-of-day historical data. |
| INLINECODE10 |
Fetches intraday (1m, 5m, 1h) historical data. |
|
get_real_time_data | Fetches real-time (delayed) price data. |
|
get_fundamental_data | Fetches comprehensive fundamental data for a company. |
|
get_technical_indicator | Calculates and fetches various technical indicators. |
|
get_financial_news | Retrieves financial news for a ticker or topic. |
|
get_sentiment_data | Fetches aggregated sentiment scores. |
|
get_options_data | Retrieves options chain data. |
|
get_screener_data | Filters stocks based on specified criteria. |
|
get_macro_indicator_data | Fetches macroeconomic data for a country. |
|
get_calendar_events | Gets upcoming earnings, IPOs, and splits. |
|
get_exchange_list | Lists all supported exchanges. |
|
get_exchange_symbols | Lists all symbols for a given exchange. |
|
search_instrument | Searches for tickers and instruments. |
|
get_dividends | Fetches historical dividend data. |
|
get_splits | Fetches historical stock split data. |
|
get_bulk_eod | Fetches bulk EOD data for an entire exchange. |
For detailed parameters and options for each function, consult the official EODHD API Documentation.
EODHD API 技能
本技能提供了一套与EOD历史数据(EODHD)API交互的综合工具包,该API是获取广泛金融数据的强大来源。
核心原则
- 1. API令牌优先:在使用任何功能前,确保用户已提供EODHD API令牌。config.json文件必须使用有效令牌进行更新。如果令牌缺失或无效,请要求用户提供。
- 使用客户端:所有API交互必须通过提供的Python客户端:scripts/eodhdclient.py。该客户端处理身份验证、请求构建和基本错误处理。
- 具体明确:获取数据时,使用客户端中最具体的可用函数。例如,获取股息数据应使用getdividends(),而非通用基本面数据调用。
- 处理错误:客户端在失败时返回{error: ...}字典。务必检查此情况,并向用户清晰报告错误。
设置:API令牌配置
首次使用前,必须配置API令牌。用户需要提供其个人EODHD API密钥。
- 1. 询问用户提供其EODHD API令牌。
- 将令牌写入配置文件,使用file工具:
python
default_api.file(
action=write,
path=/home/ubuntu/skills/eodhd-api/config.json,
text=f{{\apitoken\: \{userprovided_token}\}}
)
工作流程:获取金融数据
按照以下通用工作流程从EODHD API检索和使用金融数据。
步骤1:理解用户请求
确定用户所需的具体数据类型。是历史价格、公司基本面、新闻还是其他内容?将其请求映射到eodhd_client.py脚本中的可用函数之一。
步骤2:实例化客户端并调用方法
创建Python脚本以导入并使用EODHDClient。
示例:获取历史EOD价格
python
文件:/home/ubuntu/fetch_eod.py
from skills.eodhd-api.scripts.eodhd_client import EODHDClient
import json
client = EODHDClient()
data = client.geteodhistorical_data(
AAPL.US,
from_date=2023-01-01,
to_date=2023-01-10
)
if error in data:
print(f发生错误:{data[error]})
else:
print(json.dumps(data, indent=2))
步骤3:执行脚本
使用shell工具运行脚本。
bash
python3.11 /home/ubuntu/fetch_eod.py
步骤4:处理并呈现数据
分析脚本输出的JSON数据。以清晰可读的格式(通常使用Markdown表格或摘要)向用户呈现信息。
可用客户端函数
eodhd_client.py脚本为最常见的EODHD API端点提供了高级接口。有关每个函数的详细用法,请参考脚本的文档字符串。
| 函数 | 描述 |
|---|
| geteodhistoricaldata | 获取每日收盘历史数据。 |
| getintradayhistoricaldata |
获取日内(1分钟、5分钟、1小时)历史数据。 |
| get
realtime_data | 获取实时(延迟)价格数据。 |
| get
fundamentaldata | 获取公司的全面基本面数据。 |
| get
technicalindicator | 计算并获取各种技术指标。 |
| get
financialnews | 检索特定股票代码或主题的金融新闻。 |
| get
sentimentdata | 获取聚合情绪评分。 |
| get
optionsdata | 检索期权链数据。 |
| get
screenerdata | 根据指定条件筛选股票。 |
| get
macroindicator_data | 获取某个国家的宏观经济数据。 |
| get
calendarevents | 获取即将到来的财报、IPO和拆股信息。 |
| get
exchangelist | 列出所有支持的交易所。 |
| get
exchangesymbols | 列出给定交易所的所有股票代码。 |
| search_instrument | 搜索股票代码和金融工具。 |
| get_dividends | 获取历史股息数据。 |
| get_splits | 获取历史股票拆股数据。 |
| get
bulkeod | 获取整个交易所的批量EOD数据。 |
有关每个函数的详细参数和选项,请查阅官方EODHD API文档。