Switch to candlestick charts with 30-day daily data
- Replace line charts with candlestick charts for better visualization - Green candles for up days, red for down days - Daily resolution (30 days) - free tier compatible - Auto-detect intraday vs daily data for proper time/date formatting - Note: 5-min intraday requires paid Polygon tier ($199/month) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,23 +26,44 @@ class PolygonAPI:
|
||||
|
||||
Args:
|
||||
ticker: Stock ticker symbol
|
||||
days: Number of days of historical data to fetch
|
||||
resolution: Candle resolution (ignored, always daily)
|
||||
days: Number of days of historical data to fetch (ignored for intraday)
|
||||
resolution: Candle resolution ('D' for daily, '5min' requires paid tier)
|
||||
|
||||
Returns:
|
||||
Dictionary with OHLCV data or None if unavailable
|
||||
"""
|
||||
try:
|
||||
# Calculate date range (end yesterday to avoid missing today's data)
|
||||
end_date = datetime.now() - timedelta(days=1)
|
||||
start_date = end_date - timedelta(days=days)
|
||||
if resolution == '5min':
|
||||
# For 5-minute bars, get current day data
|
||||
# Start at market open (9:30 AM ET)
|
||||
import pytz
|
||||
et_tz = pytz.timezone('America/New_York')
|
||||
now_et = datetime.now(et_tz)
|
||||
|
||||
# Format dates as YYYY-MM-DD
|
||||
from_date = start_date.strftime('%Y-%m-%d')
|
||||
to_date = end_date.strftime('%Y-%m-%d')
|
||||
# Set to today at 9:30 AM ET
|
||||
market_open = now_et.replace(hour=9, minute=30, second=0, microsecond=0)
|
||||
|
||||
# Build API URL
|
||||
url = f"{self.base_url}/v2/aggs/ticker/{ticker}/range/1/day/{from_date}/{to_date}"
|
||||
# If current time is before market open, use yesterday
|
||||
if now_et < market_open:
|
||||
market_open = market_open - timedelta(days=1)
|
||||
now_et = market_open.replace(hour=16, minute=0) # Use previous day's close
|
||||
|
||||
from_date = market_open.strftime('%Y-%m-%d')
|
||||
to_date = now_et.strftime('%Y-%m-%d')
|
||||
|
||||
# Build API URL for 5-minute bars
|
||||
url = f"{self.base_url}/v2/aggs/ticker/{ticker}/range/5/minute/{from_date}/{to_date}"
|
||||
else:
|
||||
# Daily bars - Calculate date range (end yesterday to avoid missing today's data)
|
||||
end_date = datetime.now() - timedelta(days=1)
|
||||
start_date = end_date - timedelta(days=days)
|
||||
|
||||
# Format dates as YYYY-MM-DD
|
||||
from_date = start_date.strftime('%Y-%m-%d')
|
||||
to_date = end_date.strftime('%Y-%m-%d')
|
||||
|
||||
# Build API URL for daily bars
|
||||
url = f"{self.base_url}/v2/aggs/ticker/{ticker}/range/1/day/{from_date}/{to_date}"
|
||||
|
||||
# Make request
|
||||
params = {
|
||||
|
||||
Reference in New Issue
Block a user