Agathe1489 commited on
Commit
e8c11cc
·
verified ·
1 Parent(s): c99a6b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
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.info.get("regularMarketPrice", "N/A") # Ensure correct field
26
- currency = stock.info.get("currency", "USD") # Get currency
 
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