Environment:AI4Finance Foundation FinGPT Finnhub API
| Knowledge Sources | |
|---|---|
| Domains | Financial_Data, API |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Finnhub financial data API for company news, basic financials, and stock profiles, accessed via the `finnhub-python` client.
Description
This environment provides access to the Finnhub API, which supplies company news headlines and summaries, quarterly basic financials, and company profile data. The Forecaster data pipeline uses it to enrich stock price data with news and fundamentals for GPT-4 label distillation. A free-tier API key has rate limits (queries per minute).
Usage
Use this environment for Market Data Acquisition workflows — fetching company news, basic financials, and stock profiles. Required by `prepare_data_for_symbol` and `construct_prompt` (inference app).
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Any | API is HTTP-based |
| Hardware | CPU sufficient | No GPU needed |
| Network | Internet | Required for API calls |
Dependencies
Python Packages
- `finnhub-python` (latest)
- `pandas`
- `yfinance` >= 0.2.49
Credentials
The following environment variables must be set:
- `FINNHUB_API_KEY` (or `FINNHUB_KEY`): Finnhub API key. Must not be placeholder value `"your finnhub key"`.
Quick Install
pip install finnhub-python pandas yfinance>=0.2.49
Code Evidence
Client initialization from `fingpt/FinGPT_Forecaster/data.py:21`:
finnhub_client = finnhub.Client(api_key=os.environ.get("FINNHUB_KEY"))
Rate limiting with `time.sleep` from `fingpt/FinGPT_Forecaster/data.py:69`:
time.sleep(1) # control qpm
weekly_news = finnhub_client.company_news(symbol, _from=start_date, to=end_date)
API key diagnostic from `fingpt/FinGPT_Forecaster/test_api_keys.py:17-27`:
finnhub_key = os.environ.get("FINNHUB_API_KEY")
if finnhub_key and finnhub_key != "your finnhub key":
print("✅ FINNHUB_API_KEY is set")
client = finnhub.Client(api_key=finnhub_key)
client.company_profile2(symbol="AAPL")
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `num_rows is zero` | API key not set or invalid | Set `FINNHUB_API_KEY`; run `test_api_keys.py` |
| `HTTP 429 Too Many Requests` | QPM rate limit exceeded | Add `time.sleep(1)` between calls (already in code) |
| `finnhub not found` | Package not installed | `pip install finnhub-python` |
Compatibility Notes
- Variable name inconsistency: `data.py` uses `FINNHUB_KEY` while `test_api_keys.py` and `app.py` use `FINNHUB_API_KEY`. Ensure the correct variable is set.
- Free tier limits: Finnhub free tier has QPM limits; the code includes `time.sleep(1)` to throttle.
- Crypto symbols: Use CRYPTO list from `indices.py` for crypto-specific data.