10000 make examples simpler (#172) · Raptorly1/client-python@8baca91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8baca91

Browse files
author
clickingbuttons
authored
make examples simpler (polygon-io#172)
* make examples simpler * remove api key
1 parent 77a7a7e commit 8baca91

File tree

6 files changed

+24
-28
lines changed

6 files changed

+24
-28
lines changed

examples/rest/raw-get.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
from typing import cast
33
from urllib3 import HTTPResponse
44

5-
client = RESTClient(verbose=True)
5+
client = RESTClient()
66

77
aggs = cast(
88
HTTPResponse,
99
client.get_aggs(
10-
ticker="AAPL",
11-
multiplier=1,
12-
timespan="day",
13-
from_="2022-04-01",
14-
to="2022-04-04",
10+
"AAPL",
11+
1,
12+
"day",
13+
"2022-04-01",
14+
"2022-04-04",
1515
raw=True,
1616
),
1717
)

examples/rest/raw-list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from typing import cast
33
from urllib3 import HTTPResponse
44

5-
client = RESTClient(verbose=True)
5+
client = RESTClient()
66

77
trades = cast(
88
HTTPResponse,
9-
client.list_trades(ticker="AAA", timestamp="2022-04-20", limit=5, raw=True),
9+
client.list_trades("AAA", "2022-04-20", 5, raw=True),
1010
)
1111
print(trades.data)
1212
# b'{

examples/rest/simple-get.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
from polygon import RESTClient
2-
from datetime import date, datetime
32

4-
client = RESTClient(verbose=True)
3+
client = RESTClient()
54

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-
)
16-
17-
if aggs1 != aggs2:
18-
print(aggs1, aggs2)
19-
assert False
20-
else:
21-
print(aggs1)
5+
aggs = client.get_aggs("AAPL", 1, "day", "2004-04-04", "2004-04-04")
6+
print(aggs)

examples/rest/simple-list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from polygon import RESTClient
22

3-
client = RESTClient(verbose=True)
3+
client = RESTClient()
44

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

polygon/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .rest import RESTClient
2+
from .rest.base import NoResults
23
from .websocket import WebSocketClient, AuthError

polygon/rest/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
pass
1515

1616

17+
class NoResults(Exception):
18+
pass
19+
20+
1721
class BaseClient:
1822
def __init__(
1923
self,
@@ -79,6 +83,12 @@ def _get(
7983
obj = self._decode(resp)
8084

8185
if result_key:
86+
if result_key not in obj:
87+
raise NoResults(
88+
f'Expected key "{result_key}" in response {obj}.'
89+
+ "Make sure you have sufficient permissions and your request parameters are valid."
90+
+ f"This is the url that returned no results: {resp.geturl()}"
91+
)
8292
obj = obj[result_key]
8393

8494
if deserializer:

0 commit comments

Comments
 (0)
0