genaibeauty commited on
Commit
0ef0ab3
Β·
verified Β·
1 Parent(s): 3b0bc72

Create stock_data.py

Browse files
Files changed (1) hide show
  1. stock_data.py +11 -0
stock_data.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import yfinance as yf
2
+
3
+ def get_stock_data(ticker):
4
+ """Fetch real-time stock price from Yahoo Finance."""
5
+ stock = yf.Ticker(ticker)
6
+ data = stock.history(period="1d")
7
+
8
+ return {
9
+ "ticker": ticker,
10
+ "price": data["Close"].iloc[-1] if not data.empty else None
11
+ }