Python client for the Polygon.io Stocks API
For a basic product overview, check out our setup and use documentation
pip install polygon-api-client
polygon-api-client
supports python version >= 3.6
import time
from polygon import WebSocketClient, STOCKS_CLUSTER
def my_customer_process_message(message):
print("this is my custom message processing", message)
def main():
key = 'your api key'
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_customer_process_message)
my_client.run_async()
my_client.subscribe("T.MSFT", "T.AAPL", "T.AMD", "T.NVDA")
time.sleep(2)
my_client.close_connection()
if __name__ == "__main__":
main()
from polygon import RESTClient
def main():
key = "your api key"
# RESTClient can be used as a context manager to facilitate closing the underlying http session
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
with RESTClient(key) as client:
resp = client.stocks_equities_daily_open_close("AAPL", "2018-03-02")
print(f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}")
if __name__ == '__main__':
main()
We use swagger as our API spec and we used this swagger to generate most of the code that defines the REST client. We made this decision due to the size of our API, many endpoints and object definitions, and to accommodate future changes.