Spaces:
Running
Running
Update stock.py
Browse files
stock.py
CHANGED
|
@@ -4,6 +4,7 @@ import yfinance as yf
|
|
| 4 |
import pandas as pd
|
| 5 |
import traceback
|
| 6 |
from ta_indi_pat import *
|
|
|
|
| 7 |
|
| 8 |
#file_name = f"bhav/bhav_{date_str.replace('-', '_')}.csv"
|
| 9 |
#upload_file("eshanhf",file_name,df)
|
|
@@ -62,27 +63,33 @@ from ta_indi_pat import talib_df
|
|
| 62 |
# -------------------------- INTRADAY ------------------------------
|
| 63 |
|
| 64 |
def fetch_intraday(symbol, indicators=None):
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
title=f"{symbol} Intraday")
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
return wrap_html(f"<h1>Error:{e}</h1>")
|
| 81 |
-
|
| 82 |
-
|
| 83 |
# -------------------------- DAILY ------------------------------
|
| 84 |
|
| 85 |
def fetch_daily(symbol, source="yfinance", max_rows=200):
|
|
|
|
|
|
|
|
|
|
| 86 |
try:
|
| 87 |
df = daily(symbol)
|
| 88 |
|
|
@@ -104,11 +111,11 @@ def fetch_daily(symbol, source="yfinance", max_rows=200):
|
|
| 104 |
</div>
|
| 105 |
"""
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
except Exception as e:
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
# -------------------------- QUARTERLY ------------------------------
|
| 114 |
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import traceback
|
| 6 |
from ta_indi_pat import *
|
| 7 |
+
from persist import *
|
| 8 |
|
| 9 |
#file_name = f"bhav/bhav_{date_str.replace('-', '_')}.csv"
|
| 10 |
#upload_file("eshanhf",file_name,df)
|
|
|
|
| 63 |
# -------------------------- INTRADAY ------------------------------
|
| 64 |
|
| 65 |
def fetch_intraday(symbol, indicators=None):
|
| 66 |
+
if exists("intraday_"+symbol, "html"):
|
| 67 |
+
intra_html = load("intraday_"+symbol, "html")
|
| 68 |
+
else:
|
| 69 |
+
try:
|
| 70 |
+
df = intraday(symbol)
|
| 71 |
+
if df.empty:
|
| 72 |
+
return wrap_html(f"<h1>No intraday data for {symbol}</h1>")
|
| 73 |
+
|
| 74 |
+
if isinstance(df.columns, pd.MultiIndex):
|
| 75 |
+
df.columns = df.columns.get_level_values(0)
|
| 76 |
+
file_name = f"intraday/{symbol}.csv"
|
| 77 |
+
upload_file("eshanhf",file_name,df)
|
| 78 |
+
#chart_html = build_chart(df, indicators=indicators)
|
| 79 |
+
table_html = make_table(df.tail(50))
|
| 80 |
+
intra_html= wrap_html(f"<h2>Last 50 Rows</h2>{table_html}",
|
| 81 |
title=f"{symbol} Intraday")
|
| 82 |
+
save("intraday_"+symbol,intra_html, "html")
|
| 83 |
+
except Exception as e:
|
| 84 |
+
return wrap_html(f"<h1>Error:{e}</h1>")
|
| 85 |
|
| 86 |
+
return intra_html
|
|
|
|
|
|
|
|
|
|
| 87 |
# -------------------------- DAILY ------------------------------
|
| 88 |
|
| 89 |
def fetch_daily(symbol, source="yfinance", max_rows=200):
|
| 90 |
+
if exists("daily_"+symbol, "html"):
|
| 91 |
+
daily_html = load("daily_"+symbol, "html")
|
| 92 |
+
else:
|
| 93 |
try:
|
| 94 |
df = daily(symbol)
|
| 95 |
|
|
|
|
| 111 |
</div>
|
| 112 |
"""
|
| 113 |
|
| 114 |
+
daily_html= wrap_html(f"<h2>{symbol} Daily</h2>" + html_card("TA-Lib", scroll))
|
| 115 |
+
save("daily_"+symbol,daily_html, "html")
|
| 116 |
except Exception as e:
|
| 117 |
+
daily_html= html_card("Error", str(e))
|
| 118 |
+
return daily_html
|
| 119 |
|
| 120 |
# -------------------------- QUARTERLY ------------------------------
|
| 121 |
|