Agathe1489 commited on
Commit
a636d55
·
verified ·
1 Parent(s): 11945f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -21,8 +21,8 @@ def get_stock_price(ticker: str) -> str:
21
 
22
  try:
23
  stock = yf.Ticker(ticker)
24
- print(stock.fast_info) # Debugging: Print full response
25
- price = stock.fast_info.get("last_price", "N/A") # Alternative field
26
  currency = stock.fast_info.get("currency", "USD") # Alternative currency field
27
 
28
  return f"{currency} {price:,.2f}" if price != "N/A" else "Price unavailable"
 
21
 
22
  try:
23
  stock = yf.Ticker(ticker)
24
+ hist = stock.history(period="1d") # Get 1-day historical price
25
+ price = hist["Close"].iloc[-1] # Get last closing price
26
  currency = stock.fast_info.get("currency", "USD") # Alternative currency field
27
 
28
  return f"{currency} {price:,.2f}" if price != "N/A" else "Price unavailable"