From 2b229cff5f99a00b6cc984f4c1c3c41de7f1e04c Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 17 May 2026 00:06:36 -0700 Subject: Add 1D and 5D intraday periods to overview chart Adds get_intraday_history() to data_service.py (5m/30m bars, ttl=60s) and wires it into the overview chart with HH:MM x-axis formatting, market-hours filtering, intraday-only primary fetch, hidden comparison buttons, and 1D as the default period on load. Co-Authored-By: Claude Sonnet 4.6 --- components/overview.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'components') diff --git a/components/overview.py b/components/overview.py index 53358f0..c52cae2 100644 --- a/components/overview.py +++ b/components/overview.py @@ -6,10 +6,10 @@ import pandas as pd import streamlit as st import streamlit.components.v1 as components -from services.data_service import get_company_info, get_latest_price, get_price_history +from services.data_service import get_company_info, get_intraday_history, get_latest_price, get_price_history from utils.security import json_for_script -PERIODS = {"1mo": "1M", "3mo": "3M", "6mo": "6M", "1y": "1Y", "5y": "5Y"} +PERIODS = {"1d": "1D", "5d": "5D", "1mo": "1M", "3mo": "3M", "1y": "1Y", "5y": "5Y"} SECTOR_ETF_MAP = { "Technology": "XLK", "Communication Services": "XLC", @@ -69,6 +69,21 @@ def _to_int(val): def _series_points(symbol: str, period: str) -> list[dict]: + if period in ("1d", "5d"): + interval = "5m" if period == "1d" else "30m" + df = get_intraday_history(symbol, period=period, interval=interval) + if df is None or df.empty or "Close" not in df.columns: + return [] + closes = pd.to_numeric(df["Close"], errors="coerce") + try: + closes = closes.between_time("09:30", "16:00") + except Exception: + pass + out = [] + for idx, v in closes.dropna().items(): + ts = idx.strftime("%Y-%m-%dT%H:%M") + out.append({"d": ts, "c": float(v)}) + return out hist = get_price_history(symbol, period=period) if hist is None or hist.empty or "Close" not in hist.columns: return [] @@ -216,7 +231,8 @@ def render_overview(ticker: str): series = {} for period in PERIODS.keys(): bucket = {} - for sym in symbols: + fetch_syms = [tkr] if period in ("1d", "5d") else symbols + for sym in fetch_syms: pts = _series_points(sym, period) if pts: bucket[sym] = pts @@ -265,7 +281,7 @@ def render_overview(ticker: str): meta = { "updated_label": datetime.now().strftime("%Y-%m-%d %H:%M"), - "default_period": "1y", + "default_period": "1d", "default_mode": "price", "default_comparisons": ["^GSPC"], } @@ -440,10 +456,11 @@ def render_overview(ticker: str): '
' + '
' + 'Period' + + '' + + '' + '' + '' - + '' - + '' + + '' + '' + "
" + '
' @@ -465,7 +482,7 @@ def render_overview(ticker: str): "