File size: 2,164 Bytes
2df3369 e11cd25 2df3369 e11cd25 2df3369 5ec78f4 2df3369 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
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"""
<div style="overflow-x:auto; overflow-y:auto; max-height:650px; border:1px solid #ccc; padding:8px;">
{table_html}
</div>
"""
content = f"""
<h2>NIFTY 50 (^NSEI) — Daily (OHLCV + Indicators + Patterns)</h2>
{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))
|