import io import requests import pandas as pd import yfinance as yf from datetime import datetime, timedelta from common import html_card, wrap_html from ta_indi_pat import talib_df import datetime date = datetime.date(2025, 11, 27) # Trying a past date where data is likely available df = nse_preopen_df("NIFTY") df_bhav, act_date = fetch_bhavcopy_df(date) df_ce, df_pe = fetch_option_chain_df("NIFTY") df_m, df_a, df_meta, df_data = nse_index_df("NIFTY 50") fno = nse_fno_df("RELIANCE") def fetch_index(max_rows=200): """ Fetch NIFTY 50 (^NSEI) 1-year OHLCV data from Yahoo Finance, add TA-Lib indicators + candlestick patterns, return HTML table inside a scrollable container. """ try: # ---------------------------------- # Fetch NIFTY 50 data # ---------------------------------- df = yf.download("^NSEI", period="1y", interval="1d").round(2) if df.empty: return html_card("Error", "No data found for NIFTY 50 (^NSEI).") # Standardize column names df.columns = ["Close", "High", "Low", "Open", "Volume"] df.reset_index(inplace=True) # make Date a column # Limit display rows df_display = df.head(max_rows) # ---------------------------------- # Generate TA-Lib indicators # ---------------------------------- combined_df = talib_df(df_display) # ---------------------------------- # Convert to HTML # ---------------------------------- table_html = combined_df.to_html( classes="table table-striped table-bordered", index=False ) scrollable_html = f"""
{table_html}
""" content = f"""

NIFTY 50 (^NSEI) — Daily (OHLCV + Indicators + Patterns)

{html_card("Technical Analysis Table", scrollable_html)} """ return wrap_html(content, title="NIFTY 50 Daily Data") except Exception as e: return html_card("Error", str(e))