Update daily.py
Browse files
daily.py
CHANGED
|
@@ -1,40 +1,37 @@
|
|
| 1 |
# daily.py
|
| 2 |
-
import yfinance as yf
|
| 3 |
import pandas as pd
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
from chart_builder import build_chart
|
| 6 |
|
| 7 |
-
|
| 8 |
-
# DAILY DATA PROCESSING
|
| 9 |
-
# ============================================================
|
| 10 |
-
|
| 11 |
-
def fetch_daily(symbol, indicators=None):
|
| 12 |
"""
|
| 13 |
-
|
|
|
|
| 14 |
"""
|
| 15 |
-
yfsymbol = f"{symbol}.NS"
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
if df.empty:
|
| 20 |
-
return
|
| 21 |
|
| 22 |
-
|
| 23 |
-
if isinstance(df.columns, pd.MultiIndex):
|
| 24 |
-
df.columns = df.columns.get_level_values(0)
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
|
| 29 |
-
#
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
table_html = make_table(df
|
| 33 |
|
| 34 |
-
# Wrap
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
return full_html
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
-
return
|
|
|
|
| 1 |
# daily.py
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
import yfinance as yf
|
| 4 |
+
from common import wrap_html, html_error, clean_df, make_table
|
| 5 |
+
from indicater import calculate_indicators
|
| 6 |
from chart_builder import build_chart
|
| 7 |
|
| 8 |
+
def fetch_daily(symbol):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
+
Fetches daily OHLCV data, calculates indicators, builds chart,
|
| 11 |
+
and returns the complete HTML for Gradio UI.
|
| 12 |
"""
|
|
|
|
| 13 |
try:
|
| 14 |
+
yfsymbol = symbol + ".NS"
|
| 15 |
+
|
| 16 |
+
# ---------------- Fetch daily data ----------------
|
| 17 |
+
df = yf.download(yfsymbol, period="6mo", interval="1d")
|
| 18 |
if df.empty:
|
| 19 |
+
return html_error(f"No daily data found for {symbol}")
|
| 20 |
|
| 21 |
+
df = clean_df(df)
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# ---------------- Calculate indicators ----------------
|
| 24 |
+
indicators = calculate_indicators(df)
|
| 25 |
|
| 26 |
+
# ---------------- Build chart ----------------
|
| 27 |
+
html_chart = build_chart(df, indicators)
|
| 28 |
|
| 29 |
+
# ---------------- Build table ----------------
|
| 30 |
+
table_html = make_table(df)
|
| 31 |
|
| 32 |
+
# ---------------- Wrap into full HTML ----------------
|
| 33 |
+
html = wrap_html(f"{html_chart}<br>{table_html}", title=f"{symbol} Daily Chart")
|
| 34 |
+
return html
|
|
|
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
+
return html_error(f"Error generating daily chart for {symbol}: {e}")
|