eshan6704 commited on
Commit
8edc019
·
verified ·
1 Parent(s): 9d9865a

Update daily.py

Browse files
Files changed (1) hide show
  1. daily.py +19 -7
daily.py CHANGED
@@ -4,16 +4,14 @@ import pandas as pd
4
  from ta_indi_pat import patterns, indicators
5
  from common import html_card, wrap_html
6
 
7
- def fetch_daily(symbol):
8
  """
9
- Fetch daily OHLCV data, calculate indicators + patterns, return as HTML table.
 
10
  """
11
  try:
12
  # --- Fetch historical data ---
13
- df = yf.download(symbol + ".NS", period="1y", interval="1d").round(2)
14
- # Reset MultiIndex if exists
15
- if isinstance(df.columns, pd.MultiIndex):
16
- df.columns = df.columns.get_level_values(0)
17
  if df.empty:
18
  return html_card("Error", f"No daily data found for {symbol}")
19
  df.reset_index(inplace=True)
@@ -25,13 +23,27 @@ def fetch_daily(symbol):
25
  # --- Combine OHLCV + indicators + patterns ---
26
  combined_df = pd.concat([df, indicator_df, pattern_df], axis=1)
27
 
 
 
 
 
 
 
 
28
  # --- Convert to HTML table ---
29
  table_html = combined_df.to_html(classes="table table-striped table-bordered", border=0, index=False)
30
 
 
 
 
 
 
 
 
31
  # --- Wrap in card and full HTML ---
32
  content = f"""
33
  <h2>{symbol} - Daily Data</h2>
34
- {html_card("Data Table", table_html)}
35
  """
36
 
37
  return wrap_html(content, title=f"{symbol} Daily Data")
 
4
  from ta_indi_pat import patterns, indicators
5
  from common import html_card, wrap_html
6
 
7
+ def fetch_daily_full_table(symbol, max_rows=200):
8
  """
9
+ Fetch daily OHLCV data, calculate indicators + patterns, handle multilevel headers,
10
+ and return a scrollable HTML table (x and y).
11
  """
12
  try:
13
  # --- Fetch historical data ---
14
+ df = yf.download(symbol + ".NS", period="6mo", interval="1d")
 
 
 
15
  if df.empty:
16
  return html_card("Error", f"No daily data found for {symbol}")
17
  df.reset_index(inplace=True)
 
23
  # --- Combine OHLCV + indicators + patterns ---
24
  combined_df = pd.concat([df, indicator_df, pattern_df], axis=1)
25
 
26
+ # --- Handle MultiIndex columns: take only 0th level ---
27
+ if isinstance(combined_df.columns, pd.MultiIndex):
28
+ combined_df.columns = combined_df.columns.get_level_values(0)
29
+
30
+ # --- Limit rows for display ---
31
+ combined_df = combined_df.head(max_rows)
32
+
33
  # --- Convert to HTML table ---
34
  table_html = combined_df.to_html(classes="table table-striped table-bordered", border=0, index=False)
35
 
36
+ # --- Wrap table in scrollable div ---
37
+ scrollable_table_html = f"""
38
+ <div style="overflow-x:auto; overflow-y:auto; max-height:600px; border:1px solid #ccc; padding:5px;">
39
+ {table_html}
40
+ </div>
41
+ """
42
+
43
  # --- Wrap in card and full HTML ---
44
  content = f"""
45
  <h2>{symbol} - Daily Data</h2>
46
+ {html_card("Data Table", scrollable_table_html)}
47
  """
48
 
49
  return wrap_html(content, title=f"{symbol} Daily Data")