Skip to content

Commit ee015a0

Browse files
committed
Added pagination flag and fixed base url parsing
1 parent 5915d03 commit ee015a0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

polygon/rest/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(
4646
num_pools: int = 10,
4747
retries: int = 3,
4848
base: str = BASE,
49+
pagination: bool = True,
4950
verbose: bool = False,
5051
trace: bool = False,
5152
custom_json: Optional[Any] = None,
@@ -57,6 +58,7 @@ def __init__(
5758
num_pools=num_pools,
5859
retries=retries,
5960
base=base,
61+
pagination=pagination,
6062
verbose=verbose,
6163
trace=trace,
6264
custom_json=custom_json,
@@ -68,6 +70,7 @@ def __init__(
6870
num_pools=num_pools,
6971
retries=retries,
7072
base=base,
73+
pagination=pagination,
7174
verbose=verbose,
7275
trace=trace,
7376
custom_json=custom_json,

polygon/rest/base.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .models.request import RequestOptionBuilder
1111
from ..logging import get_logger
1212
import logging
13-
from urllib.parse import urlencode
13+
from urllib.parse import urlencode, urlparse
1414
from ..exceptions import AuthError, BadResponse
1515

1616
logger = get_logger("RESTClient")
@@ -30,6 +30,7 @@ def __init__(
3030
num_pools: int,
3131
retries: int,
3232
base: str,
33+
pagination: bool,
3334
verbose: bool,
3435
trace: bool,
3536
custom_json: Optional[Any] = None,
@@ -41,6 +42,7 @@ def __init__(
4142

4243
self.API_KEY = api_key
4344
self.BASE = base
45+
self.pagination = pagination
4446

4547
self.headers = {
4648
"Authorization": "Bearer " + self.API_KEY,
@@ -227,11 +229,14 @@ def _paginate_iter(
227229
return []
228230
for t in decoded[result_key]:
229231
yield deserializer(t)
230-
if "next_url" in decoded:
231-
path = decoded["next_url"].replace(self.BASE, "")
232-
params = {}
233-
else:
232+
if not self.pagination or "next_url" not in decoded:
234233
return
234+
next_url = decoded["next_url"]
235+
parsed = urlparse(next_url)
236+
path = parsed.path
237+
if parsed.query:
238+
path += "?" + parsed.query
239+
params = {}
235240

236241
def _paginate(
237242
self,

0 commit comments

Comments
 (0)