eshan6704 commited on
Commit
cb01b9e
·
verified ·
1 Parent(s): 73d8213

Update daily.py

Browse files
Files changed (1) hide show
  1. daily.py +19 -21
daily.py CHANGED
@@ -1,42 +1,40 @@
1
  # daily.py
2
- import pandas as pd
3
  import yfinance as yf
4
- from common import format_number, format_large_number, html_card, make_table, wrap_html, clean_df
 
5
  from indicater import calculate_indicators
6
  from chart_builder import build_chart
7
 
8
  def fetch_daily(symbol):
9
  """
10
- Fetch real daily stock data from Yahoo Finance, calculate indicators,
11
- build chart and table, and return full HTML.
12
  """
 
13
  try:
14
- # 1. Fetch daily OHLCV data
15
- yf_symbol = f"{symbol}.NS" # NSE stocks; adjust for your exchange
16
- df = yf.download(yf_symbol, period="1y", interval="1d", progress=False)
17
  if df.empty:
18
- return f"<h3>No daily data found for {symbol}</h3>"
19
 
20
- # 2. Handle multi-level columns (take 0th level)
21
  if isinstance(df.columns, pd.MultiIndex):
22
  df.columns = df.columns.get_level_values(0)
23
 
24
- df = clean_df(df)
 
25
 
26
- # 3. Calculate indicators
27
  indicators = calculate_indicators(df)
28
 
29
- # 4. Build Plotly chart with indicators
30
- chart_html = build_chart(df, indicators, symbol=symbol)
31
-
32
- # 5. Format table
33
- table_html = make_table(df)
34
 
35
- # 6. Wrap chart + table in card layout
36
- content_html = html_card(f"{symbol} Daily Data", chart_html + table_html)
37
 
38
- # 7. Return full HTML
39
- return wrap_html(content_html, title=f"{symbol} Daily Data")
40
 
41
  except Exception as e:
42
- return f"<h3>Error fetching daily data for {symbol}:</h3><pre>{e}</pre>"
 
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>"