8
8
9
9
10
10
class YahooFinance :
11
+ NUMBER_ROWS = 4
12
+
11
13
@staticmethod
12
14
def is_valid_ticker (ticker : str ) -> bool :
13
15
stock = yf .Ticker (ticker )
@@ -46,23 +48,9 @@ def get_balance_sheet(
46
48
)
47
49
48
50
try :
49
- fields = [
50
- "Current Assets" ,
51
- "Current Liabilities" ,
52
- "Total Assets" ,
53
- "Total Liabilities Net Minority Interest" ,
54
- "Total Capitalization" ,
55
- "Working Capital" ,
56
- "Invested Capital" ,
57
- "Total Debt" ,
58
- "Net Debt" ,
59
- "Stockholders Equity" ,
60
- ]
61
-
62
51
df_balance_sheet = balance_sheet .transpose ()
63
- df_balance_sheet = df_balance_sheet .reindex (columns = fields , fill_value = 0 )
64
52
65
- return df_balance_sheet .sort_index ().tail (4 )
53
+ return df_balance_sheet .sort_index ().tail (YahooFinance . NUMBER_ROWS )
66
54
except Exception as e :
67
55
logging .error (f"Error fetching balance sheet for { stock } : { e } " )
68
56
@@ -96,7 +84,7 @@ def get_income_statement(
96
84
df_income_stmt = income_statement .transpose ()
97
85
df_income_stmt = df_income_stmt .reindex (columns = fields , fill_value = 0 )
98
86
99
- return df_income_stmt .sort_index ().tail (4 )
87
+ return df_income_stmt .sort_index ().tail (YahooFinance . NUMBER_ROWS )
100
88
101
89
except Exception as e :
102
90
logging .error (f"Error fetching income statement for { stock } : { e } " )
@@ -122,7 +110,7 @@ def get_cashflow(
122
110
df_cashflow = cashflow .transpose ()
123
111
df_cashflow = df_cashflow .reindex (columns = fields , fill_value = 0 )
124
112
125
- return df_cashflow .sort_index ().tail (4 )
113
+ return df_cashflow .sort_index ().tail (YahooFinance . NUMBER_ROWS )
126
114
127
115
except Exception as e :
128
116
logging .error (f"Error fetching cash flow for { stock } : { e } " )
0 commit comments