From f94125a325309e867421a66e4a649bedc47d4e1c Mon Sep 17 00:00:00 2001 From: "W. Gustavo Cevallos" Date: Thu, 31 Oct 2024 13:14:06 -0500 Subject: [PATCH] community: Update Polygon.io API (#27552) **Description:** Update the wrapper to support the Polygon API if not you get an error. I keeped `STOCKBUSINESS` for retro-compatbility with older endpoints / other uses Old Code: ``` if status not in ("OK", "STOCKBUSINESS"): raise ValueError(f"API Error: {data}") ``` API Respond: ``` API Error: {'results': {'P': 0.22, 'S': 0, 'T': 'ZOM', 'X': 5, 'p': 0.123, 'q': 0, 's': 200, 't': 1729614422813395456, 'x': 1, 'z': 1}, 'status': 'STOCKSBUSINESS', 'request_id': 'XXXXXX'} ``` - **Issue:** N/A Polygon API update - **Dependencies:** N/A - **Twitter handle:** @wgcv --------- Co-authored-by: ccurme --- libs/community/langchain_community/utilities/polygon.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/community/langchain_community/utilities/polygon.py b/libs/community/langchain_community/utilities/polygon.py index c7ab49f405467..f14069bd4fa61 100644 --- a/libs/community/langchain_community/utilities/polygon.py +++ b/libs/community/langchain_community/utilities/polygon.py @@ -45,7 +45,7 @@ def get_financials(self, ticker: str) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None) @@ -61,7 +61,7 @@ def get_last_quote(self, ticker: str) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None) @@ -82,7 +82,7 @@ def get_ticker_news(self, ticker: str) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None) @@ -116,7 +116,7 @@ def get_aggregates(self, ticker: str, **kwargs: Any) -> Optional[dict]: data = response.json() status = data.get("status", None) - if status not in ("OK", "STOCKBUSINESS"): + if status not in ("OK", "STOCKBUSINESS", "STOCKSBUSINESS"): raise ValueError(f"API Error: {data}") return data.get("results", None)