From 090fe0b4605a0d8786584aa108d15cda4cf6c2fe Mon Sep 17 00:00:00 2001 From: StephanAkkerman Date: Fri, 2 Aug 2024 17:10:52 +0200 Subject: [PATCH] Hopefully fixed yahoo blocking error --- src/util/yf_data.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util/yf_data.py b/src/util/yf_data.py index e2d6be0..bde33dc 100644 --- a/src/util/yf_data.py +++ b/src/util/yf_data.py @@ -15,10 +15,11 @@ from util.vars import logger -def yf_info(ticker: str, do_format_change: bool = True): +async def yf_info(ticker: str, do_format_change: bool = True): # This can be blocking try: - stock_info = Ticker(ticker, asynchronous=True).price + # No results when asynchronous=True + stock_info = Ticker(ticker, asynchronous=False).price except Exception as e: logger.error(f"Error in getting Yahoo Finance data for {ticker}: {e}") return None @@ -97,7 +98,7 @@ async def get_stock_info( """ if asset_type == "stock": - stock_info = yf_info(ticker, do_format_change) + stock_info = await yf_info(ticker, do_format_change) if stock_info and stock_info[0] > 0: # or price == [] return stock_info