Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,18 +19,14 @@ def get_stock_price(ticker: str) -> str:
|
|
19 |
ticker: A string representing the stock ticker symbol (e.g., "AAPL" for Apple).
|
20 |
"""
|
21 |
|
22 |
-
|
23 |
try:
|
24 |
stock = yf.Ticker(ticker)
|
25 |
-
price = stock.
|
26 |
-
currency = stock.
|
|
|
27 |
return f"{currency} {price:,.2f}" if price != "N/A" else "Price unavailable"
|
28 |
except Exception as e:
|
29 |
return f"Error fetching price: {e}"
|
30 |
-
|
31 |
-
if price_span:
|
32 |
-
return f"The current price of {ticker} is ${price_span.text}"
|
33 |
-
return f"Could not find price for {ticker}"
|
34 |
|
35 |
|
36 |
@tool
|
|
|
19 |
ticker: A string representing the stock ticker symbol (e.g., "AAPL" for Apple).
|
20 |
"""
|
21 |
|
|
|
22 |
try:
|
23 |
stock = yf.Ticker(ticker)
|
24 |
+
price = stock.fast_info.get("last_price", "N/A") # Alternative field
|
25 |
+
currency = stock.fast_info.get("currency", "USD") # Alternative currency field
|
26 |
+
|
27 |
return f"{currency} {price:,.2f}" if price != "N/A" else "Price unavailable"
|
28 |
except Exception as e:
|
29 |
return f"Error fetching price: {e}"
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
@tool
|