Skip to content

Commit

Permalink
Hopefully fixed yahoo blocking error
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanAkkerman committed Aug 2, 2024
1 parent 0137bed commit 090fe0b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/util/yf_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 090fe0b

Please sign in to comment.