Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ help:

## Check code style
style:
poetry run black $(if $(CI),--check,) polygon test_*
poetry run black $(if $(CI),--check,) polygon test_* examples

## Check static types
static:
poetry run mypy polygon test_*
poetry run mypy polygon test_* examples

## Check code style and static types
lint: style static
Expand Down
14 changes: 13 additions & 1 deletion examples/rest/raw-get.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from polygon import RESTClient
from typing import cast
from urllib3 import HTTPResponse

client = RESTClient(verbose=True)

aggs = client.get_aggs("AAPL", 1, "day", "2022-04-01", "2022-04-04", raw=True)
aggs = cast(
HTTPResponse,
client.get_aggs(
ticker="AAPL",
multiplier=1,
timespan="day",
from_="2022-04-01",
to="2022-04-04",
raw=True,
),
)
print(aggs.geturl())
# https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2022-04-01/2022-04-04
print(aggs.status)
Expand Down
7 changes: 6 additions & 1 deletion examples/rest/raw-list.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from polygon import RESTClient
from typing import cast
from urllib3 import HTTPResponse

client = RESTClient(verbose=True)

trades = client.list_trades("AAA", timestamp="2022-04-20", limit=5, raw=True)
trades = cast(
HTTPResponse,
client.list_trades(ticker="AAA", timestamp="2022-04-20", limit=5, raw=True),
)
print(trades.data)
# b'{
# "results": [
Expand Down
15 changes: 11 additions & 4 deletions examples/rest/simple-get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

client = RESTClient(verbose=True)

aggs1 = client.get_aggs("AAPL", 1, "day", "2005-04-04", "2005-04-04")
aggs2 = client.get_aggs("AAPL", 1, "day", date(2005, 4, 4), datetime(2005, 4, 4))
aggs1 = client.get_aggs(
ticker="AAPL", multiplier=1, timespan="day", from_="2005-04-04", to="2005-04-04"
)
aggs2 = client.get_aggs(
ticker="AAPL",
multiplier=1,
timespan="day",
from_=date(2005, 4, 4),
to=datetime(2005, 4, 4),
)

if aggs1 != aggs2:
print(aggs1, aggs2)
assert(False)
assert False
else:
print(aggs1)

2 changes: 1 addition & 1 deletion examples/rest/simple-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
client = RESTClient(verbose=True)

trades = []
for t in client.list_trades("AAA", timestamp="2022-04-20", limit=5):
for t in client.list_trades(ticker="AAA", timestamp="2022-04-20", limit=5):
trades.append(t)
print(trades)
6 changes: 5 additions & 1 deletion examples/websocket/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from polygon.websocket.models import WebSocketMessage, EquityTrade
from typing import List

c = WebSocketClient(subscriptions=['T.*'])
c = WebSocketClient(subscriptions=["T.*"])


class MessageHandler:
count = 0
Expand All @@ -13,9 +14,12 @@ def handle_msg(self, msgs: List[WebSocketMessage]):
print(self.count, m)
self.count += 1


h = MessageHandler()


def handle_msg(msgs: List[WebSocketMessage]):
h.handle_msg(msgs)


c.run(handle_msg)
15 changes: 8 additions & 7 deletions examples/websocket/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
from typing import List
import asyncio

c = WebSocketClient(subscriptions=['T.*'])
c = WebSocketClient(subscriptions=["T.*"])


async def handle_msg(msgs: List[WebSocketMessage]):
for m in msgs:
print(m)


async def timeout():
await asyncio.sleep(1)
print('unsubscribe_all')
print("unsubscribe_all")
c.unsubscribe_all()
await asyncio.sleep(1)
print('close')
print("close")
await c.close()


async def main():
await asyncio.gather(
c.connect(handle_msg),
timeout()
)
await asyncio.gather(c.connect(handle_msg), timeout())


asyncio.run(main())
4 changes: 3 additions & 1 deletion examples/websocket/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from polygon.websocket.models import WebSocketMessage, Market
from typing import List

c = WebSocketClient(market=Market.Crypto, subscriptions=['XT.*'])
c = WebSocketClient(market=Market.Crypto, subscriptions=["XT.*"])


def handle_msg(msgs: List[WebSocketMessage]):
for m in msgs:
print(m)


c.run(handle_msg)
4 changes: 3 additions & 1 deletion examples/websocket/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from typing import Union
import json

c = WebSocketClient(subscriptions=['T.*'], raw=True)
c = WebSocketClient(subscriptions=["T.*"], raw=True)


def handle_msg(msgs: Union[str, bytes]):
print(json.loads(msgs))


c.run(handle_msg)
4 changes: 3 additions & 1 deletion examples/websocket/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from polygon.websocket.models import WebSocketMessage
from typing import List

c = WebSocketClient(subscriptions=['T.*'])
c = WebSocketClient(subscriptions=["T.*"])


def handle_msg(msgs: List[WebSocketMessage]):
for m in msgs:
print(m)


c.run(handle_msg)