8000 GitHub - tehcoderer/client-python at patch-1
[go: up one dir, main page]

Skip to content

tehcoderer/client-python

 
 

Repository files navigation

PyPI version Docs

Polygon Python Client - WebSocket & RESTful APIs

Python client for the Polygon.io API.

Getting started

Install

pip install polygon-api-client

Requires python version >= 3.7

Getting aggs

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")

Getting trades

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)

Getting raw response

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)

Streaming websockets

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))

About

A python client library for accessing Polygon's APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.3%
  • Other 0.7%
0