Spaces:
Sleeping
Sleeping
Update daily.py
Browse files
daily.py
CHANGED
|
@@ -1,42 +1,40 @@
|
|
| 1 |
# daily.py
|
| 2 |
-
import pandas as pd
|
| 3 |
import yfinance as yf
|
| 4 |
-
|
|
|
|
| 5 |
from indicater import calculate_indicators
|
| 6 |
from chart_builder import build_chart
|
| 7 |
|
| 8 |
def fetch_daily(symbol):
|
| 9 |
"""
|
| 10 |
-
Fetch
|
| 11 |
-
|
| 12 |
"""
|
|
|
|
| 13 |
try:
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
if df.empty:
|
| 18 |
-
return f"<
|
| 19 |
|
| 20 |
-
#
|
| 21 |
if isinstance(df.columns, pd.MultiIndex):
|
| 22 |
df.columns = df.columns.get_level_values(0)
|
| 23 |
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
#
|
| 27 |
indicators = calculate_indicators(df)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
chart_html = build_chart(df, indicators, symbol
|
| 31 |
-
|
| 32 |
-
# 5. Format table
|
| 33 |
-
table_html = make_table(df)
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
return wrap_html(content_html, title=f"{symbol} Daily Data")
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
-
return f"<
|
|
|
|
| 1 |
# daily.py
|
|
|
|
| 2 |
import yfinance as yf
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from common import wrap_plotly_html, make_table
|
| 5 |
from indicater import calculate_indicators
|
| 6 |
from chart_builder import build_chart
|
| 7 |
|
| 8 |
def fetch_daily(symbol):
|
| 9 |
"""
|
| 10 |
+
Fetch daily OHLC + volume data for the past 1 year and render as HTML chart + table
|
| 11 |
+
with selectable indicators (via script in chart_builder).
|
| 12 |
"""
|
| 13 |
+
yfsymbol = f"{symbol}.NS"
|
| 14 |
try:
|
| 15 |
+
# Download daily data
|
| 16 |
+
df = yf.download(yfsymbol, period="1y", interval="1d").round(2)
|
| 17 |
+
|
| 18 |
if df.empty:
|
| 19 |
+
return f"<h1>No daily data for {symbol}</h1>"
|
| 20 |
|
| 21 |
+
# Handle multilevel columns (take 0th level)
|
| 22 |
if isinstance(df.columns, pd.MultiIndex):
|
| 23 |
df.columns = df.columns.get_level_values(0)
|
| 24 |
|
| 25 |
+
# Format table HTML for last 30 rows
|
| 26 |
+
table_html = make_table(df.tail(30))
|
| 27 |
|
| 28 |
+
# Calculate indicators
|
| 29 |
indicators = calculate_indicators(df)
|
| 30 |
|
| 31 |
+
# Build Plotly chart with main + volume subplot + subplots for indicators
|
| 32 |
+
chart_html = build_chart(df, indicators, symbol)
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Wrap chart + table together
|
| 35 |
+
full_html = wrap_plotly_html(chart_html, table_html)
|
| 36 |
|
| 37 |
+
return full_html
|
|
|
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
+
return f"<h1>Error fetching daily data</h1><p>{str(e)}</p>"
|