Python client for the Polygon.io API.
pip install polygon-api-client
Requires python version >= 3.7
from polygon import RESTClient
client = RESTClient() # Uses POLYGON_API_KEY env var. Can optionally supply your key.
aggs = client.get_aggs("AAPL", 1, "day", "2005-04-01", "2005-04-04")from polygon import RESTClient
from polygon.rest.models import Sort
client = RESTClient() # Uses POLYGON_API_KEY env var. Can optionally supply your key.
trades = []
for t in client.list_trades("AAA", timestamp="2022-04-20", limit=5, sort=Sort.ASC):
trades.append(t)To handle the raw urllib3 response yourself, pass raw=True:
from polygon import RESTClient
client = RESTClient() # Uses POLYGON_API_KEY env var. Can optionally supply your key.
response = client.get_aggs("AAPL", 1, "day", "2005-04-01", "2005-04-04", raw=True)from polygon import WebSocketClient
from polygon.websocket.models import Market, Feed, WebSocketMessage
import asyncio
client = WebSocketClient(market=Market.Stocks, feed=Feed.RealTime) # Uses POLYGON_API_KEY env var. Can optionally supply your key.
client.subscribe('T.AAPL')
def handle_msg(msg: WebSocketMessage):
print(msg)
asyncio.run(client.connect(handle_msg))