From fbf5bc37df61c0349647217cbbf0ad7a9d197fc5 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 17 May 2026 00:24:43 -0700 Subject: Add QuoteTable as empty-state landing page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renders watchlist tickers as a styled psm-card data table (Symbol, Sector, Last, Δ, % Day, Volume) when no ticker is selected. Falls back to the existing placeholder when the watchlist is empty. Uses the same JS hidden-input click pattern as the sidebar watchlist. Co-Authored-By: Claude Sonnet 4.6 --- components/quotetable.py | 169 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 components/quotetable.py (limited to 'components') diff --git a/components/quotetable.py b/components/quotetable.py new file mode 100644 index 0000000..e85c335 --- /dev/null +++ b/components/quotetable.py @@ -0,0 +1,169 @@ +"""QuoteTable — watchlist tickers as a full-width styled data table (empty-state landing page).""" +import streamlit as st +import streamlit.components.v1 as components +from services.data_service import get_latest_price, get_company_info +from utils.security import escape_html + + +def render_quotetable(watchlist: list[str]) -> None: + """Render watchlist tickers as a styled quote table. + + Shows Symbol · Sector · Last · Δ · % Day · Volume. Clicking a row sets + st.session_state["ticker"] and reruns. Uses the same hidden-input JS + pattern as the sidebar watchlist. + """ + # Process any pending row click + clicked = st.session_state.get("_qt_click", "") + if clicked and clicked in watchlist: + st.session_state["ticker"] = clicked + st.session_state["_qt_click"] = "" + st.rerun() + + st.text_input("qt_click_receiver", key="_qt_click", label_visibility="collapsed") + + # Build row data + rows_html = "" + for sym in watchlist: + try: + price = get_latest_price(sym) + info = get_company_info(sym) or {} + prev = info.get("regularMarketPreviousClose") or info.get("previousClose") + sector = info.get("sector") or info.get("quoteType") or "" + vol = info.get("volume") + sym_e = escape_html(sym) + sector_e = escape_html(sector) + + if price is not None and prev and prev > 0: + chg = price - prev + pct = chg / prev * 100 + sign = "+" if chg >= 0 else "−" + arrow = "▲" if chg >= 0 else "▼" + chg_cls = "pos" if chg >= 0 else "neg" + px_str = "$" + f"{price:,.2f}" + chg_str = arrow + " " + f"{abs(chg):.2f}" + pct_str = sign + f"{abs(pct):.2f}%" + elif price is not None: + chg_cls = "flat" + px_str = "$" + f"{price:,.2f}" + chg_str = "—" + pct_str = "—" + else: + chg_cls = "flat" + px_str = "—" + chg_str = "—" + pct_str = "—" + + if vol is not None: + if vol >= 1_000_000: + vol_str = f"{vol/1_000_000:.1f}M" + elif vol >= 1_000: + vol_str = f"{vol/1_000:.0f}K" + else: + vol_str = str(vol) + else: + vol_str = "—" + + rows_html += ( + "" + "" + sym_e + "" + "" + sector_e + "" + "" + px_str + "" + "" + chg_str + "" + "" + pct_str + "" + "" + vol_str + "" + "" + ) + except Exception: + sym_e = escape_html(sym) + rows_html += ( + "" + "" + sym_e + "" + "—" + "—" + "—" + "—" + "—" + "" + ) + + n = len(watchlist) + height = 40 + 36 + n * 47 + 24 # card-head + thead + rows + buffer + + html = ( + "" + "
" + "
" + "
Watchlist

Positions

" + "
" + "" + "" + "" + "" + "" + "" + "" + rows_html + "" + "
SymbolSectorLastΔ% DayVolume
" + "
" + "" + ) + + components.html(html, height=height, scrolling=False) -- cgit v1.3-2-g0d8e