Spaces:
Sleeping
Sleeping
Update actor with yahooquery to search actions in yahoo finance
Browse files
app.py
CHANGED
@@ -5,37 +5,39 @@ import pytz
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from Gradio_UI import GradioUI
|
8 |
-
|
9 |
|
10 |
@tool
|
11 |
-
def busqueda_valor_accion(
|
12 |
-
"""A tool that looks up the value of stocks within yahoo, this requires the
|
13 |
-
Example company_name could take a value like Amazon and it will return the name of the company, the symbol within the stock, the market it belongs to and the value of the stock.
|
14 |
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
|
|
|
|
|
|
|
19 |
try:
|
20 |
-
|
21 |
-
|
22 |
-
primer_resultado = resultado["quotes"][0]
|
23 |
-
ticker = primer_resultado["symbol"]
|
24 |
-
precio_accion = Ticker(ticker)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
Symbol (Ticker): {ticker}
|
29 |
-
Market: {primer_resultado['exchange']}
|
30 |
-
The stock price is: ${precio_accion.price[ticker]['regularMarketPrice']}
|
31 |
-
"""
|
32 |
-
else:
|
33 |
-
return "No results found. Please check the company name and try again."
|
34 |
-
|
35 |
-
except Exception as e:
|
36 |
-
return f"Error when querying yahooquery please try changing the value of the company_name parameter, in case this error persists consider not giving an answer. For more information about the error you can look at the following trace {e}"
|
37 |
|
|
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
@tool
|
41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from Gradio_UI import GradioUI
|
8 |
+
import yfinance as yf
|
9 |
|
10 |
@tool
|
11 |
+
def busqueda_valor_accion(company_ticker: str) -> str:
|
12 |
+
"""A tool that looks up the value of stocks within yahoo, this requires the ticker of the specific company (Amazon example would be AMZN).
|
|
|
13 |
|
14 |
Args:
|
15 |
+
company_ticker:str Ticker of the company you want to query to perform the stock search.
|
16 |
+
|
17 |
|
18 |
+
Example use:
|
19 |
+
busqueda_valor_accion(company_ticker="AMZN")
|
20 |
+
"""
|
21 |
try:
|
22 |
+
stock = yf.Ticker(company_ticker)
|
23 |
+
stock_info = stock.info
|
|
|
|
|
|
|
24 |
|
25 |
+
if not stock_info:
|
26 |
+
return "No se encontraron datos para el ticker proporcionado."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
longname = stock_info.get("longName", "N/A")
|
29 |
+
exchange = stock_info.get("exchange", "N/A")
|
30 |
+
currency = stock_info.get("currency", "USD")
|
31 |
+
stock_price = stock.history(period="1d")["Close"].iloc[-1] # Último precio de cierre
|
32 |
|
33 |
+
return f"""
|
34 |
+
Nombre: {longname}
|
35 |
+
Símbolo (Ticker): {company_ticker}
|
36 |
+
Mercado: {exchange}
|
37 |
+
Precio de la acción: {round(stock_price,3)} {currency}
|
38 |
+
"""
|
39 |
+
except Exception as e:
|
40 |
+
return f"Error al obtener la información de la acción: {e}"
|
41 |
|
42 |
@tool
|
43 |
def get_current_time_in_timezone(timezone: str) -> str:
|