genaibeauty's picture
Create stock_data.py
0ef0ab3 verified
raw
history blame contribute delete
291 Bytes
import yfinance as yf
def get_stock_data(ticker):
"""Fetch real-time stock price from Yahoo Finance."""
stock = yf.Ticker(ticker)
data = stock.history(period="1d")
return {
"ticker": ticker,
"price": data["Close"].iloc[-1] if not data.empty else None
}