diff --git a/openbb_sdk/extensions/charting/openbb_charting/core/backend.py b/openbb_sdk/extensions/charting/openbb_charting/core/backend.py index 0b29cb3d532..7b87d89ceb8 100644 --- a/openbb_sdk/extensions/charting/openbb_charting/core/backend.py +++ b/openbb_sdk/extensions/charting/openbb_charting/core/backend.py @@ -475,14 +475,13 @@ async def download_plotly_js(): # this is so we don't have to block the main thread async with aiohttp.ClientSession( connector=aiohttp.TCPConnector(verify_ssl=False) - ) as session: - async with session.get(f"https://cdn.plot.ly/{js_filename}") as resp: - with open(str(PLOTLYJS_PATH), "wb") as f: - while True: - chunk = await resp.content.read(1024) - if not chunk: - break - f.write(chunk) + ) as session, session.get(f"https://cdn.plot.ly/{js_filename}") as resp: + with open(str(PLOTLYJS_PATH), "wb") as f: + while True: + chunk = await resp.content.read(1024) + if not chunk: + break + f.write(chunk) # We delete the old version of plotly.js for file in (PLOTS_CORE_PATH / "assets").glob("plotly*.js"): diff --git a/openbb_sdk/openbb/package/crypto.py b/openbb_sdk/openbb/package/crypto.py index e9ce4f98298..fb69de72c93 100644 --- a/openbb_sdk/openbb/package/crypto.py +++ b/openbb_sdk/openbb/package/crypto.py @@ -42,7 +42,7 @@ class CLASS_crypto(Container): provider: Optional[Literal["fmp", "polygon", "yfinance"]] = None, **kwargs ) -> OBBject[List]: - """Crypto EOD Price. + r"""Crypto EOD Price. Parameters ---------- @@ -118,11 +118,11 @@ class CLASS_crypto(Container): change : Optional[float] Change in the price of the symbol from the previous day. (provider: fmp) change_percent : Optional[float] - Change \\% in the price of the symbol. (provider: fmp) + Change \% in the price of the symbol. (provider: fmp) label : Optional[str] Human readable format of the date. (provider: fmp) change_over_time : Optional[float] - Change \\% in the price of the symbol over a period of time. (provider: fmp) + Change \% in the price of the symbol over a period of time. (provider: fmp) n : Optional[PositiveInt] Number of transactions for the symbol in the time period. (provider: polygon) """ # noqa: E501 diff --git a/openbb_sdk/openbb/package/economy.py b/openbb_sdk/openbb/package/economy.py index 4aee01085c5..26c43a16351 100644 --- a/openbb_sdk/openbb/package/economy.py +++ b/openbb_sdk/openbb/package/economy.py @@ -674,7 +674,7 @@ class CLASS_economy(Container): provider: Optional[Literal["fmp", "polygon", "yfinance"]] = None, **kwargs ) -> OBBject[List]: - """Get OHLCV data for an index. + r"""Get OHLCV data for an index. Parameters ---------- @@ -750,11 +750,11 @@ class CLASS_economy(Container): change : Optional[float] Change in the price of the symbol from the previous day. (provider: fmp) change_percent : Optional[float] - Change \\% in the price of the symbol. (provider: fmp) + Change \% in the price of the symbol. (provider: fmp) label : Optional[str] Human readable format of the date. (provider: fmp) change_over_time : Optional[float] - Change \\% in the price of the symbol over a period of time. (provider: fmp) + Change \% in the price of the symbol over a period of time. (provider: fmp) n : Optional[PositiveInt] Number of transactions for the symbol in the time period. (provider: polygon) """ # noqa: E501 diff --git a/openbb_sdk/openbb/package/forex.py b/openbb_sdk/openbb/package/forex.py index 97cb89fb98f..e29f0af02a6 100644 --- a/openbb_sdk/openbb/package/forex.py +++ b/openbb_sdk/openbb/package/forex.py @@ -43,7 +43,7 @@ class CLASS_forex(Container): provider: Optional[Literal["fmp", "polygon", "yfinance"]] = None, **kwargs ) -> OBBject[List]: - """Forex Intraday Price. + r"""Forex Intraday Price. Parameters ---------- @@ -117,11 +117,11 @@ class CLASS_forex(Container): change : Optional[float] Change in the price of the symbol from the previous day. (provider: fmp) change_percent : Optional[float] - Change \\% in the price of the symbol. (provider: fmp) + Change \% in the price of the symbol. (provider: fmp) label : Optional[str] Human readable format of the date. (provider: fmp) change_over_time : Optional[float] - Change \\% in the price of the symbol over a period of time. (provider: fmp) + Change \% in the price of the symbol over a period of time. (provider: fmp) n : Optional[PositiveInt] Number of transactions for the symbol in the time period. (provider: polygon) """ # noqa: E501 diff --git a/openbb_sdk/openbb/package/stocks.py b/openbb_sdk/openbb/package/stocks.py index 389497806c2..ccb41b36572 100644 --- a/openbb_sdk/openbb/package/stocks.py +++ b/openbb_sdk/openbb/package/stocks.py @@ -218,7 +218,7 @@ class CLASS_stocks(Container): provider: Optional[Literal["cboe", "fmp", "polygon", "yfinance"]] = None, **kwargs ) -> OBBject[List]: - """Load stock data for a specific ticker. + r"""Load stock data for a specific ticker. Parameters ---------- @@ -294,11 +294,11 @@ class CLASS_stocks(Container): change : Optional[float] Change in the price of the symbol from the previous day. (provider: fmp) change_percent : Optional[float] - Change \\% in the price of the symbol. (provider: fmp) + Change \% in the price of the symbol. (provider: fmp) label : Optional[str] Human readable format of the date. (provider: fmp) change_over_time : Optional[float] - Change \\% in the price of the symbol over a period of time. (provider: fmp) + Change \% in the price of the symbol over a period of time. (provider: fmp) n : Optional[PositiveInt] Number of transactions for the symbol in the time period. (provider: polygon) """ # noqa: E501 diff --git a/openbb_sdk/providers/yfinance/openbb_yfinance/models/futures_curve.py b/openbb_sdk/providers/yfinance/openbb_yfinance/models/futures_curve.py index 0f27b9a0c09..cd3ad04a1a7 100644 --- a/openbb_sdk/providers/yfinance/openbb_yfinance/models/futures_curve.py +++ b/openbb_sdk/providers/yfinance/openbb_yfinance/models/futures_curve.py @@ -1,6 +1,5 @@ """yfinance Futures End of Day fetcher.""" - - +import warnings from typing import Any, Dict, List, Optional from openbb_provider.abstract.fetcher import Fetcher @@ -45,13 +44,23 @@ class YFinanceFuturesCurveFetcher( query: YFinanceFuturesCurveQueryParams, credentials: Optional[Dict[str, str]], **kwargs: Any, - ) -> dict: + ) -> List[dict]: """Return the raw data from the yfinance endpoint.""" - return get_futures_curve(query.symbol, query.date).to_dict(orient="records") + data = get_futures_curve(query.symbol, query.date).to_dict(orient="records") + if len(data) == 0: + warnings.warn(f"Symbol {query.symbol} not found in yfinance") + + return data @staticmethod def transform_data( data: dict, ) -> List[YFinanceFuturesCurveData]: """Transform the data to the standard format.""" - return [YFinanceFuturesCurveData.parse_obj(d) for d in data] + return [ + YFinanceFuturesCurveData( + expiration=curve["expiration"], + price=curve["Last Price"], + ) + for curve in data + ] diff --git a/openbb_sdk/providers/yfinance/openbb_yfinance/utils/helpers.py b/openbb_sdk/providers/yfinance/openbb_yfinance/utils/helpers.py index 6e6090901c6..eb2eb873aea 100644 --- a/openbb_sdk/providers/yfinance/openbb_yfinance/utils/helpers.py +++ b/openbb_sdk/providers/yfinance/openbb_yfinance/utils/helpers.py @@ -16,7 +16,7 @@ from openbb_yfinance.utils.references import MONTHS def get_futures_data() -> pd.DataFrame: - """Return the dataframe of the futures csv file""" + """Return the dataframe of the futures csv file.""" return pd.read_csv(Path(__file__).resolve().parent / "futures.csv") @@ -36,7 +36,11 @@ def get_futures_curve(symbol: str, date: Optional[dateType]) -> pd.DataFrame: DataFrame with futures curve """ futures_data = get_futures_data() - exchange = futures_data[futures_data["Ticker"] == symbol]["Exchange"].values[0] + try: + exchange = futures_data[futures_data["Ticker"] == symbol]["Exchange"].values[0] + except IndexError: + return pd.DataFrame({"Last Price": [], "expiration": []}) + today = datetime.today() futures_index = [] futures_curve = [] diff --git a/openbb_sdk/sdk/core/tests/app/test_charting_manager.py b/openbb_sdk/sdk/core/tests/app/test_charting_manager.py index 11f611a5008..6af3851e72c 100644 --- a/openbb_sdk/sdk/core/tests/app/test_charting_manager.py +++ b/openbb_sdk/sdk/core/tests/app/test_charting_manager.py @@ -1,10 +1,8 @@ +import pytest from openbb_core.app.charting_manager import ChartingManager from openbb_core.app.model.system_settings import SystemSettings from openbb_core.app.model.user_settings import UserSettings -import pytest -from unittest.mock import MagicMock, patch - @pytest.fixture(scope="function", autouse=True) def setup_and_teardown():