Skip to content

Commit 49442ae

Browse files
author
clickingbuttons
authored
use kw arg names (#171)
1 parent aee3465 commit 49442ae

File tree

10 files changed

+55
-20
lines changed

10 files changed

+55
-20
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ help:
2222

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

2727
## Check static types
2828
static:
29-
poetry run mypy polygon test_*
29+
poetry run mypy polygon test_* examples
3030

3131
## Check code style and static types
3232
lint: style static

examples/rest/raw-get.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
from polygon import RESTClient
2+
from typing import cast
3+
from urllib3 import HTTPResponse
24

35
client = RESTClient(verbose=True)
46

5-
aggs = client.get_aggs("AAPL", 1, "day", "2022-04-01", "2022-04-04", raw=True)
7+
aggs = cast(
8+
HTTPResponse,
9+
client.get_aggs(
10+
ticker="AAPL",
11+
multiplier=1,
12+
timespan="day",
13+
from_="2022-04-01",
14+
to="2022-04-04",
15+
raw=True,
16+
),
17+
)
618
print(aggs.geturl())
719
# https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2022-04-01/2022-04-04
820
print(aggs.status)

examples/rest/raw-list.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from polygon import RESTClient
2+
from typing import cast
3+
from urllib3 import HTTPResponse
24

35
client = RESTClient(verbose=True)
46

5-
trades = client.list_trades("AAA", timestamp="2022-04-20", limit=5, raw=True)
7+
trades = cast(
8+
HTTPResponse,
9+
client.list_trades(ticker="AAA", timestamp="2022-04-20", limit=5, raw=True),
10+
)
611
print(trades.data)
712
# b'{
813
# "results": [

examples/rest/simple-get.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33

44
client = RESTClient(verbose=True)
55

6-
aggs1 = client.get_aggs("AAPL", 1, "day", "2005-04-04", "2005-04-04")
7-
aggs2 = client.get_aggs("AAPL", 1, "day", date(2005, 4, 4), datetime(2005, 4, 4))
6+
aggs1 = client.get_aggs(
7+
ticker="AAPL", multiplier=1, timespan="day", from_="2005-04-04", to="2005-04-04"
8+
)
9+
aggs2 = client.get_aggs(
10+
ticker="AAPL",
11+
multiplier=1,
12+
timespan="day",
13+
from_=date(2005, 4, 4),
14+
to=datetime(2005, 4, 4),
15+
)
816

917
if aggs1 != aggs2:
1018
print(aggs1, aggs2)
11-
assert(False)
19+
assert False
1220
else:
1321
print(aggs1)
14-

examples/rest/simple-list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
client = RESTClient(verbose=True)
44

55
trades = []
6-
for t in client.list_trades("AAA", timestamp="2022-04-20", limit=5):
6+
for t in client.list_trades(ticker="AAA", timestamp="2022-04-20", limit=5):
77
trades.append(t)
88
print(trades)

examples/websocket/aggs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from polygon.websocket.models import WebSocketMessage, EquityTrade
33
from typing import List
44

5-
c = WebSocketClient(subscriptions=['T.*'])
5+
c = WebSocketClient(subscriptions=["T.*"])
6+
67

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

17+
1618
h = MessageHandler()
1719

20+
1821
def handle_msg(msgs: List[WebSocketMessage]):
1922
h.handle_msg(msgs)
2023

24+
2125
c.run(handle_msg)

examples/websocket/async.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
from typing import List
44
import asyncio
55

6-
c = WebSocketClient(subscriptions=['T.*'])
6+
c = WebSocketClient(subscriptions=["T.*"])
7+
78

89
async def handle_msg(msgs: List[WebSocketMessage]):
910
for m in msgs:
1011
print(m)
1112

13+
1214
async def timeout():
1315
await asyncio.sleep(1)
14-
print('unsubscribe_all')
16+
print("unsubscribe_all")
1517
c.unsubscribe_all()
1618
await asyncio.sleep(1)
17-
print('close')
19+
print("close")
1820
await c.close()
1921

22+
2023
async def main():
21-
await asyncio.gather(
22-
c.connect(handle_msg),
23-
timeout()
24-
)
24+
await asyncio.gather(c.connect(handle_msg), timeout())
25+
2526

2627
asyncio.run(main())

examples/websocket/crypto.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from polygon.websocket.models import WebSocketMessage, Market
33
from typing import List
44

5-
c = WebSocketClient(market=Market.Crypto, subscriptions=['XT.*'])
5+
c = WebSocketClient(market=Market.Crypto, subscriptions=["XT.*"])
6+
67

78
def handle_msg(msgs: List[WebSocketMessage]):
89
for m in msgs:
910
print(m)
1011

12+
1113
c.run(handle_msg)

examples/websocket/raw.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
from typing import Union
33
import json
44

5-
c = WebSocketClient(subscriptions=['T.*'], raw=True)
5+
c = WebSocketClient(subscriptions=["T.*"], raw=True)
6+
67

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

11+
1012
c.run(handle_msg)

examples/websocket/simple.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
from polygon.websocket.models import WebSocketMessage
33
from typing import List
44

5-
c = WebSocketClient(subscriptions=['T.*'])
5+
c = WebSocketClient(subscriptions=["T.*"])
6+
67

78
def handle_msg(msgs: List[WebSocketMessage]):
89
for m in msgs:
910
print(m)
1011

12+
1113
c.run(handle_msg)

0 commit comments

Comments
 (0)