|
|
|
|
|
import yfinance as yf |
|
|
import pandas as pd |
|
|
from common import format_large_number, wrap_html, make_table |
|
|
from chart_builder import build_chart |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_intraday(symbol, indicators=None): |
|
|
""" |
|
|
Fetch intraday (5-min) data for a symbol from Yahoo Finance, |
|
|
format it, apply indicators, and return full HTML. |
|
|
""" |
|
|
yfsymbol = f"{symbol}.NS" |
|
|
try: |
|
|
|
|
|
df = yf.download(yfsymbol, period="1d", interval="5m").round(2) |
|
|
if df.empty: |
|
|
return wrap_html(f"<h1>No intraday data available for {symbol}</h1>") |
|
|
|
|
|
|
|
|
if isinstance(df.columns, pd.MultiIndex): |
|
|
df.columns = df.columns.get_level_values(0) |
|
|
|
|
|
|
|
|
chart_html = build_chart(df, indicators=indicators, volume=True) |
|
|
|
|
|
|
|
|
table_html = make_table(df.tail(50)) |
|
|
|
|
|
|
|
|
full_html = wrap_html(f"{chart_html}<h2>Recent Intraday Data (last 50 rows)</h2>{table_html}", |
|
|
title=f"Intraday Data for {symbol}") |
|
|
return full_html |
|
|
|
|
|
except Exception as e: |
|
|
return wrap_html(f"<h1>Error fetching intraday data for {symbol}</h1><p>{str(e)}</p>") |
|
|
|