Skip to content

Commit

Permalink
community: Update Polygon.io API (#27552)
Browse files Browse the repository at this point in the history
**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 <[email protected]>
  • Loading branch information
wgcv and ccurme authored Oct 31, 2024
1 parent 621f78b commit f94125a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libs/community/langchain_community/utilities/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f94125a

Please sign in to comment.