Update daily.py
Browse files
daily.py
CHANGED
|
@@ -6,48 +6,51 @@ from common import html_card, wrap_html
|
|
| 6 |
|
| 7 |
def fetch_daily(symbol, max_rows=200):
|
| 8 |
"""
|
| 9 |
-
Fetch daily OHLCV data, calculate indicators + patterns,
|
| 10 |
-
and return
|
| 11 |
"""
|
| 12 |
try:
|
| 13 |
# --- Fetch historical data ---
|
| 14 |
df = yf.download(symbol + ".NS", period="1y", interval="1d").round(2)
|
| 15 |
-
|
| 16 |
if isinstance(df.columns, pd.MultiIndex):
|
| 17 |
-
|
| 18 |
-
|
| 19 |
if df.empty:
|
| 20 |
return html_card("Error", f"No daily data found for {symbol}")
|
| 21 |
df.reset_index(inplace=True)
|
|
|
|
| 22 |
|
| 23 |
# --- Calculate indicators and patterns ---
|
| 24 |
-
indicator_df = indicators(df)
|
| 25 |
-
pattern_df = patterns(df)
|
| 26 |
-
|
| 27 |
-
# --- Combine OHLCV + indicators + patterns ---
|
| 28 |
-
combined_df = pd.concat([df, indicator_df, pattern_df], axis=1)
|
| 29 |
|
| 30 |
# --- Handle MultiIndex columns: take only 0th level ---
|
| 31 |
-
if isinstance(combined_df.columns, pd.MultiIndex):
|
| 32 |
-
combined_df.columns = combined_df.columns.get_level_values(0)
|
| 33 |
|
| 34 |
-
# --- Limit rows for display ---
|
| 35 |
-
combined_df = combined_df.head(max_rows)
|
| 36 |
|
| 37 |
-
# --- Convert to HTML table ---
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
</div>
|
| 45 |
"""
|
| 46 |
|
| 47 |
-
# --- Wrap in card
|
| 48 |
content = f"""
|
| 49 |
<h2>{symbol} - Daily Data</h2>
|
| 50 |
-
{html_card("Data
|
|
|
|
|
|
|
| 51 |
"""
|
| 52 |
|
| 53 |
return wrap_html(content, title=f"{symbol} Daily Data")
|
|
|
|
| 6 |
|
| 7 |
def fetch_daily(symbol, max_rows=200):
|
| 8 |
"""
|
| 9 |
+
Fetch daily OHLCV data, calculate indicators + patterns,
|
| 10 |
+
and return 3 separate scrollable HTML tables: OHLCV, indicators, patterns.
|
| 11 |
"""
|
| 12 |
try:
|
| 13 |
# --- Fetch historical data ---
|
| 14 |
df = yf.download(symbol + ".NS", period="1y", interval="1d").round(2)
|
| 15 |
+
|
| 16 |
if isinstance(df.columns, pd.MultiIndex):
|
| 17 |
+
df.columns = df.columns.get_level_values(0)
|
| 18 |
+
|
| 19 |
if df.empty:
|
| 20 |
return html_card("Error", f"No daily data found for {symbol}")
|
| 21 |
df.reset_index(inplace=True)
|
| 22 |
+
df = df.head(max_rows)
|
| 23 |
|
| 24 |
# --- Calculate indicators and patterns ---
|
| 25 |
+
indicator_df = indicators(df).head(max_rows)
|
| 26 |
+
pattern_df = patterns(df).head(max_rows)
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# --- Handle MultiIndex columns: take only 0th level ---
|
|
|
|
|
|
|
| 29 |
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# --- Convert each DataFrame to HTML table ---
|
| 32 |
+
daily_table_html = f"""
|
| 33 |
+
<div style="overflow-x:auto; overflow-y:auto; max-height:400px; border:1px solid #ccc; padding:5px;">
|
| 34 |
+
{df.to_html(classes="table table-striped table-bordered", index=False)}
|
| 35 |
+
</div>
|
| 36 |
+
"""
|
| 37 |
+
indicator_table_html = f"""
|
| 38 |
+
<div style="overflow-x:auto; overflow-y:auto; max-height:400px; border:1px solid #ccc; padding:5px;">
|
| 39 |
+
{indicator_df.to_html(classes="table table-striped table-bordered", index=False)}
|
| 40 |
+
</div>
|
| 41 |
+
"""
|
| 42 |
+
pattern_table_html = f"""
|
| 43 |
+
<div style="overflow-x:auto; overflow-y:auto; max-height:400px; border:1px solid #ccc; padding:5px;">
|
| 44 |
+
{pattern_df.to_html(classes="table table-striped table-bordered", index=False)}
|
| 45 |
</div>
|
| 46 |
"""
|
| 47 |
|
| 48 |
+
# --- Wrap each in card ---
|
| 49 |
content = f"""
|
| 50 |
<h2>{symbol} - Daily Data</h2>
|
| 51 |
+
{html_card("Daily OHLCV Data", daily_table_html)}
|
| 52 |
+
{html_card("Indicator Data", indicator_table_html)}
|
| 53 |
+
{html_card("Pattern Data", pattern_table_html)}
|
| 54 |
"""
|
| 55 |
|
| 56 |
return wrap_html(content, title=f"{symbol} Daily Data")
|