eshan6704 commited on
Commit
f094bae
·
verified ·
1 Parent(s): 0a97160

Delete app/stock.py

Browse files
Files changed (1) hide show
  1. app/stock.py +0 -289
app/stock.py DELETED
@@ -1,289 +0,0 @@
1
- # stock.py — compact, merged, single-file (collision-safe)
2
-
3
- import traceback
4
- import pandas as pd
5
- import yfinance as yf
6
- from datetime import datetime as dt
7
-
8
- # persist helpers
9
- from . import persist
10
- from .common import *
11
- from . import backblaze as b2
12
- #from . import ta_indi_pat
13
-
14
-
15
-
16
- # ================================================================
17
- # BASIC YFINANCE FETCHERS
18
- # ================================================================
19
-
20
- def yfinfo(symbol):
21
- return yf.Ticker(symbol + ".NS").info
22
-
23
-
24
- def qresult(symbol):
25
- return yf.Ticker(symbol + ".NS").quarterly_financials
26
-
27
-
28
- def result(symbol):
29
- return yf.Ticker(symbol + ".NS").financials
30
-
31
-
32
- def balance(symbol):
33
- return yf.Ticker(symbol + ".NS").balance_sheet
34
-
35
-
36
- def cashflow(symbol):
37
- return yf.Ticker(symbol + ".NS").cashflow
38
-
39
-
40
- def dividend(symbol):
41
- return yf.Ticker(symbol + ".NS").dividends.to_frame("Dividend")
42
-
43
-
44
- def split(symbol):
45
- return yf.Ticker(symbol + ".NS").splits.to_frame("Split")
46
-
47
-
48
- def intraday(symbol):
49
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] yf called for {symbol}")
50
- return yf.download(symbol + ".NS", period="1d", interval="5m").round(2)
51
-
52
-
53
-
54
- # ================================================================
55
- # INTRADAY
56
- # ================================================================
57
-
58
- def fetch_intraday(symbol, indicators=None):
59
- key = f"intraday_{symbol}"
60
-
61
-
62
-
63
- try:
64
- df = intraday(symbol)
65
- if df is None or df is False or df.empty:
66
- return wrap_html(f"<h1>No intraday data for {symbol}</h1>")
67
-
68
- if isinstance(df.columns, pd.MultiIndex):
69
- df.columns = df.columns.get_level_values(0)
70
-
71
-
72
- df_display = df.copy()
73
- df_display.reset_index(inplace=True)
74
-
75
- html = wrap_html(
76
- f"<h2>Last 50 Rows</h2>{make_table(df_display)}",
77
- title=f"{symbol} Intraday"
78
- )
79
-
80
-
81
- return html
82
-
83
- except Exception as e:
84
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_intraday: {e}")
85
- return wrap_html(f"<h1>Error: {e}</h1>")
86
-
87
-
88
- # ================================================================
89
- # DAILY
90
- # ================================================================
91
-
92
- # ================================================================
93
- # QUARTERLY
94
- # ================================================================
95
-
96
- def fetch_qresult(symbol):
97
- key = f"qresult_{symbol}"
98
-
99
-
100
- try:
101
- df = qresult(symbol)
102
- if df.empty:
103
- return wrap_html(f"<h1>No quarterly results for {symbol}</h1>")
104
-
105
- df_display = df.copy()
106
- for col in df_display.columns:
107
- df_display[col] = df_display[col].apply(
108
- lambda x: format_large_number(x) if isinstance(x, (int, float)) else x
109
- )
110
-
111
- df_display.reset_index(inplace=True)
112
-
113
- html = wrap_html(make_table(df_display), title=f"{symbol} Quarterly Results")
114
-
115
- return html
116
-
117
- except Exception as e:
118
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_qresult: {e}")
119
- return wrap_html(html_error(f"Quarterly Error: {e}"))
120
-
121
-
122
- # ================================================================
123
- # ANNUAL
124
- # ================================================================
125
-
126
- def fetch_result(symbol):
127
- key = f"result_{symbol}"
128
-
129
-
130
-
131
- try:
132
- df = result(symbol)
133
- if df.empty:
134
- return wrap_html(f"<h1>No annual results for {symbol}</h1>")
135
-
136
-
137
- df_display = df.copy()
138
- for col in df_display.columns:
139
- df_display[col] = df_display[col].apply(
140
- lambda x: format_large_number(x) if isinstance(x, (int, float)) else x
141
- )
142
-
143
- df_display.reset_index(inplace=True)
144
-
145
- html = wrap_html(make_table(df_display), title=f"{symbol} Annual Results")
146
-
147
- return html
148
-
149
- except Exception as e:
150
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_result: {e}")
151
- return wrap_html(html_error(f"Annual Error: {e}"))
152
-
153
-
154
- # ================================================================
155
- # BALANCE SHEET
156
- # ================================================================
157
-
158
- def fetch_balance(symbol):
159
- key = f"balance_{symbol}"
160
-
161
-
162
- try:
163
- df = balance(symbol)
164
- if df.empty:
165
- return wrap_html(f"<h1>No balance sheet for {symbol}</h1>")
166
-
167
- df_display = df.copy()
168
- for col in df_display.columns:
169
- df_display[col] = df_display[col].apply(
170
- lambda x: format_large_number(x) if isinstance(x, (int, float)) else x
171
- )
172
-
173
- df_display.reset_index(inplace=True)
174
-
175
- html = wrap_html(make_table(df_display), title=f"{symbol} Balance Sheet")
176
-
177
- return html
178
-
179
- except Exception as e:
180
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_balance: {e}")
181
- return wrap_html(html_error(f"Balance Error: {e}"))
182
-
183
-
184
- # ================================================================
185
- # CASHFLOW
186
- # ================================================================
187
-
188
- def fetch_cashflow(symbol):
189
- key = f"cashflow_{symbol}"
190
-
191
-
192
- try:
193
- df = cashflow(symbol)
194
- if df.empty:
195
- return wrap_html(f"<h1>No cashflow for {symbol}</h1>")
196
-
197
-
198
- df_display = df.copy()
199
- for col in df_display.columns:
200
- df_display[col] = df_display[col].apply(
201
- lambda x: format_large_number(x) if isinstance(x, (int, float)) else x
202
- )
203
-
204
- df_display.reset_index(inplace=True)
205
-
206
- html = wrap_html(make_table(df_display), title=f"{symbol} Cash Flow")
207
-
208
- return html
209
-
210
- except Exception as e:
211
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_cashflow: {e}")
212
- return wrap_html(html_error(f"Cash Flow Error: {e}"))
213
-
214
-
215
- # ================================================================
216
- # DIVIDEND
217
- # ================================================================
218
-
219
- def fetch_dividend(symbol):
220
- key = f"dividend_{symbol}"
221
-
222
-
223
- try:
224
- df = dividend(symbol)
225
- if df.empty:
226
- return wrap_html(f"<h1>No dividend history for {symbol}</h1>")
227
-
228
- df_display = df.copy()
229
- df_display.reset_index(inplace=True)
230
-
231
- html = wrap_html(make_table(df_display), title=f"{symbol} Dividends")
232
-
233
- return html
234
-
235
- except Exception as e:
236
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_dividend: {e}")
237
- return wrap_html(html_error(f"Dividend Error: {e}"))
238
-
239
-
240
- # ================================================================
241
- # SPLIT
242
- # ================================================================
243
-
244
- def fetch_split(symbol):
245
- key = f"split_{symbol}"
246
-
247
-
248
- try:
249
- df = split(symbol)
250
- if df.empty:
251
- return wrap_html(f"<h1>No splits for {symbol}</h1>")
252
-
253
- df_display = df.copy()
254
- df_display.reset_index(inplace=True)
255
-
256
- html = wrap_html(make_table(df_display), title=f"{symbol} Splits")
257
-
258
- return html
259
-
260
- except Exception as e:
261
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_split: {e}")
262
- return wrap_html(html_error(f"Split Error: {e}"))
263
-
264
-
265
- # ================================================================
266
- # EARNINGS
267
- # ================================================================
268
-
269
- def fetch_other(symbol):
270
- key = f"other_{symbol}"
271
-
272
-
273
- try:
274
- ticker = yf.Ticker(symbol + ".NS")
275
- df = ticker.earnings
276
-
277
- if df.empty:
278
- return wrap_html(f"<h1>No earnings data for {symbol}</h1>")
279
-
280
- df_display = df.copy()
281
- df_display.reset_index(inplace=True)
282
-
283
- html = wrap_html(make_table(df_display), title=f"{symbol} Earnings")
284
-
285
- return html
286
-
287
- except Exception as e:
288
- print(f"[{dt.now().strftime('%Y-%m-%d %H:%M:%S')}] Error fetch_other: {e}")
289
- return wrap_html(html_error(f"Earnings Error: {e}"))