Implementation:HKUDS AI Trader Get Daily Price
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, Financial_Data |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for fetching daily US stock OHLCV data from Alpha Vantage API provided by the AI-Trader data pipeline.
Description
The get_daily_price function queries Alpha Vantage's TIME_SERIES_DAILY endpoint for a given stock ticker symbol. It retrieves the full daily price history (open, high, low, close, volume) and writes it to a JSON file in the local data directory. For the QQQ ETF (used as a benchmark), it additionally writes an alternate copy prefixed with "A".
Usage
Import and call this function when populating the local data directory with US stock price data prior to running the JSONL merge step. Typically invoked in a loop over all NASDAQ-100 symbols during the data pipeline's Step 1.
Code Reference
Source Location
- Repository: AI-Trader
- File: data/get_daily_price.py
- Lines: L114-131
Signature
def get_daily_price(SYMBOL: str):
"""
Fetches daily OHLCV data from Alpha Vantage for the given ticker symbol.
Args:
SYMBOL: Stock ticker symbol (e.g. "AAPL", "NVDA", "QQQ")
Returns:
None. Writes data to ./daily_prices_{SYMBOL}.json
"""
Import
from data.get_daily_price import get_daily_price
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| SYMBOL | str | Yes | Stock ticker symbol (e.g. "AAPL", "NVDA") |
| ALPHAADVANTAGE_API_KEY | str (env) | Yes | API key loaded from environment via dotenv |
Outputs
| Name | Type | Description |
|---|---|---|
| daily_prices_{SYMBOL}.json | File | JSON file containing OHLCV time series keyed by date |
| Adaily_prices_QQQ.json | File | Additional copy created only when SYMBOL is "QQQ" (benchmark) |
Usage Examples
Fetch Single Symbol
from data.get_daily_price import get_daily_price
# Fetch Apple daily prices
get_daily_price("AAPL")
# Creates: ./daily_prices_AAPL.json
Fetch All NASDAQ-100 Symbols
from data.get_daily_price import get_daily_price
all_nasdaq_100_symbols = ["AAPL", "MSFT", "NVDA", "AMZN", ...] # 102 symbols
for symbol in all_nasdaq_100_symbols:
get_daily_price(symbol)
# Rate limit: Alpha Vantage free tier allows 5 calls/minute