Spaces:
Runtime error
Runtime error
File size: 291 Bytes
0ef0ab3 |
1 2 3 4 5 6 7 8 9 10 11 12 |
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
}
|