polygon-io / client-python

The official Python client library for the Polygon REST and WebSocket API.
https://polygon-api-client.readthedocs.io/
MIT License
744 stars 204 forks source link

Added support for related companies endpoint #685

Closed justinpolygon closed 2 weeks ago

justinpolygon commented 2 weeks ago

Update client with related companies support. This PR updates the spec, adds a get_ticker_details function, a RelatedCompany model class, and a working example. This also fixes https://github.com/polygon-io/client-python/issues/682 for the spec changes.

from polygon import RESTClient

# docs
# https://polygon.io/docs/stocks/get_v1_related-companies__ticker

client = RESTClient()  # POLYGON_API_KEY environment variable is used

related_companies = client.get_related_companies("AAPL")
print(related_companies)
$ python examples/rest/stocks-related_companies.py
[
    RelatedCompany(ticker="MSFT"),
    RelatedCompany(ticker="GOOGL"),
    RelatedCompany(ticker="AMZN"),
    RelatedCompany(ticker="GOOG"),
    RelatedCompany(ticker="TSLA"),
    RelatedCompany(ticker="NVDA"),
    RelatedCompany(ticker="META"),
    RelatedCompany(ticker="NFLX"),
    RelatedCompany(ticker="DIS"),
    RelatedCompany(ticker="BRK.B"),
]