Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,16 +21,21 @@ def get_last_prices(ticker: str) -> str:
|
|
| 21 |
Returns:
|
| 22 |
str: The last available closing price as a string.
|
| 23 |
"""
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
@tool
|
| 36 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 21 |
Returns:
|
| 22 |
str: The last available closing price as a string.
|
| 23 |
"""
|
| 24 |
+
try:
|
| 25 |
+
|
| 26 |
+
stock = yf.Ticker(ticker)
|
| 27 |
+
|
| 28 |
+
# Retrieve intraday data for the current day at one-minute intervals
|
| 29 |
+
df = stock.history(period="1d", interval="1m")
|
| 30 |
+
|
| 31 |
+
if df.empty:
|
| 32 |
+
raise ValueError("No data available for the specified ticker.")
|
| 33 |
+
|
| 34 |
+
last_price = df['Close'].iloc[-1]
|
| 35 |
+
return f"The currente price is {str(last_price)}"
|
| 36 |
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error fetching price: {str(e)}"
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|