Update daily.py
Browse files
daily.py
CHANGED
|
@@ -3,39 +3,48 @@ import yfinance as yf
|
|
| 3 |
import pandas as pd
|
| 4 |
from indicater import calculate_indicators
|
| 5 |
from chart_builder import build_chart
|
| 6 |
-
from common import html_card,
|
| 7 |
|
| 8 |
def fetch_daily(symbol):
|
| 9 |
try:
|
| 10 |
-
# --- Fetch data
|
| 11 |
-
|
| 12 |
-
if
|
| 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 |
return wrap_html(content, title=f"{symbol} Daily Data")
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
-
return
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
from indicater import calculate_indicators
|
| 5 |
from chart_builder import build_chart
|
| 6 |
+
from common import html_card, make_table, wrap_html
|
| 7 |
|
| 8 |
def fetch_daily(symbol):
|
| 9 |
try:
|
| 10 |
+
# --- Fetch historical data ---
|
| 11 |
+
df = yf.download(symbol + ".NS", period="6mo", interval="1d")
|
| 12 |
+
if df.empty:
|
| 13 |
+
return html_card("Error", f"No daily data found for {symbol}")
|
| 14 |
+
df.reset_index(inplace=True)
|
| 15 |
+
|
| 16 |
+
# --- Calculate indicators ---
|
| 17 |
+
indicators = calculate_indicators(df)
|
| 18 |
+
|
| 19 |
+
# --- Build chart with injected checkbox script ---
|
| 20 |
+
chart_html = build_chart(df, indicators)
|
| 21 |
+
|
| 22 |
+
# --- Format table ---
|
| 23 |
+
table_html = make_table(df)
|
| 24 |
+
|
| 25 |
+
# --- Combine everything in HTML ---
|
| 26 |
+
content = f"""
|
| 27 |
+
<h2>{symbol} - Daily Data</h2>
|
| 28 |
+
|
| 29 |
+
<div>
|
| 30 |
+
<b>Select Indicators to Display:</b><br>
|
| 31 |
+
<input type="checkbox" class="indicator-toggle" data-trace="1" checked> SMA20
|
| 32 |
+
<input type="checkbox" class="indicator-toggle" data-trace="2" checked> SMA50
|
| 33 |
+
<input type="checkbox" class="indicator-toggle" data-trace="3"> EMA20
|
| 34 |
+
<input type="checkbox" class="indicator-toggle" data-trace="4"> EMA50
|
| 35 |
+
<input type="checkbox" class="indicator-toggle" data-trace="5"> MACD
|
| 36 |
+
<input type="checkbox" class="indicator-toggle" data-trace="6"> RSI
|
| 37 |
+
<input type="checkbox" class="indicator-toggle" data-trace="7"> Stochastic
|
| 38 |
+
<button onclick="applyIndicators()">Apply</button>
|
| 39 |
+
</div>
|
| 40 |
+
<br>
|
| 41 |
+
|
| 42 |
+
{chart_html}
|
| 43 |
+
<br>
|
| 44 |
+
{html_card("Data Table", table_html)}
|
| 45 |
+
"""
|
| 46 |
|
| 47 |
return wrap_html(content, title=f"{symbol} Daily Data")
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
+
return html_card("Error", str(e))
|