Skip to content

Commit ddd5cfb

Browse files
Updated Examples and Docs to Support Agg Pagination (#460)
* Updated Examples and Docs to Support Agg Pagination * turn trace off
1 parent e9754bf commit ddd5cfb

8 files changed

+54
-23
lines changed

docs/source/Aggs.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
Aggs
44
==========
55

6+
===========
7+
List aggs
8+
===========
9+
10+
- `Stocks aggs`_
11+
- `Options aggs`_
12+
- `Forex aggs`_
13+
- `Crypto aggs`_
14+
15+
.. automethod:: polygon.RESTClient.list_aggs
16+
617
===========
718
Get aggs
819
===========

examples/rest/crypto-aggregates_bars.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# docs
44
# https://polygon.io/docs/crypto/get_v2_aggs_ticker__cryptoticker__range__multiplier___timespan___from___to
5-
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs
5+
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.list_aggs
66

77
# API key injected below for easy use. If not provided, the script will attempt
88
# to use the environment variable "POLYGON_API_KEY".
@@ -16,12 +16,15 @@
1616
# client = RESTClient("XXXXXX") # hardcoded api_key is used
1717
client = RESTClient() # POLYGON_API_KEY environment variable is used
1818

19-
aggs = client.get_aggs(
19+
aggs = []
20+
for a in client.list_aggs(
2021
"X:BTCUSD",
2122
1,
2223
"day",
2324
"2023-01-30",
2425
"2023-02-03",
25-
)
26+
limit=50000,
27+
):
28+
aggs.append(a)
2629

2730
print(aggs)

examples/rest/forex-aggregates_bars.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# docs
44
# https://polygon.io/docs/forex/get_v2_aggs_ticker__forexticker__range__multiplier___timespan___from___to
5-
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs
5+
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.list_aggs
66

77
# API key injected below for easy use. If not provided, the script will attempt
88
# to use the environment variable "POLYGON_API_KEY".
@@ -16,12 +16,15 @@
1616
# client = RESTClient("XXXXXX") # hardcoded api_key is used
1717
client = RESTClient() # POLYGON_API_KEY environment variable is used
1818

19-
aggs = client.get_aggs(
19+
aggs = []
20+
for a in client.list_aggs(
2021
"C:EURUSD",
2122
1,
2223
"day",
2324
"2023-01-30",
2425
"2023-02-03",
25-
)
26+
limit=50000,
27+
):
28+
aggs.append(a)
2629

2730
print(aggs)

examples/rest/indices-aggregates_bars.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# docs
44
# https://polygon.io/docs/indices/get_v2_aggs_ticker__indicesticker__range__multiplier___timespan___from___to
5-
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs
5+
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.list_aggs
66

77
# API key injected below for easy use. If not provided, the script will attempt
88
# to use the environment variable "POLYGON_API_KEY".
@@ -16,12 +16,15 @@
1616
# client = RESTClient("XXXXXX") # hardcoded api_key is used
1717
client = RESTClient() # POLYGON_API_KEY environment variable is used
1818

19-
aggs = client.get_aggs(
19+
aggs = []
20+
for a in client.list_aggs(
2021
"I:SPX",
2122
1,
2223
"day",
2324
"2023-03-10",
24-
"2023-03-10",
25-
)
25+
"2023-05-12",
26+
limit=50000,
27+
):
28+
aggs.append(a)
2629

2730
print(aggs)

examples/rest/options-aggregates_bars.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# docs
44
# https://polygon.io/docs/options/get_v2_aggs_ticker__optionsticker__range__multiplier___timespan___from___to
5-
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs
5+
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.list_aggs
66

77
# API key injected below for easy use. If not provided, the script will attempt
88
# to use the environment variable "POLYGON_API_KEY".
@@ -16,12 +16,15 @@
1616
# client = RESTClient("XXXXXX") # hardcoded api_key is used
1717
client = RESTClient() # POLYGON_API_KEY environment variable is used
1818

19-
aggs = client.get_aggs(
19+
aggs = []
20+
for a in client.list_aggs(
2021
"O:SPY251219C00650000",
2122
1,
2223
"day",
2324
"2023-01-30",
2425
"2023-02-03",
25-
)
26+
limit=50000,
27+
):
28+
aggs.append(a)
2629

2730
print(aggs)

examples/rest/stocks-aggregates_bars.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# docs
44
# https://polygon.io/docs/stocks/get_v2_aggs_ticker__stocksticker__range__multiplier___timespan___from___to
5-
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs
5+
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.list_aggs
66

77
# API key injected below for easy use. If not provided, the script will attempt
88
# to use the environment variable "POLYGON_API_KEY".
@@ -16,12 +16,15 @@
1616
# client = RESTClient("XXXXXX") # hardcoded api_key is used
1717
client = RESTClient() # POLYGON_API_KEY environment variable is used
1818

19-
aggs = client.get_aggs(
19+
aggs = []
20+
for a in client.list_aggs(
2021
"AAPL",
2122
1,
22-
"day",
23-
"2023-01-30",
23+
"minute",
24+
"2022-01-01",
2425
"2023-02-03",
25-
)
26+
limit=50000,
27+
):
28+
aggs.append(a)
2629

2730
print(aggs)

examples/rest/stocks-aggregates_bars_extra.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@
1616

1717
# docs
1818
# https://polygon.io/docs/stocks/get_v2_aggs_ticker__stocksticker__range__multiplier___timespan___from___to
19-
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs
19+
# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.list_aggs
2020

2121
# client = RESTClient("XXXXXX") # hardcoded api_key is used
2222
client = RESTClient() # POLYGON_API_KEY environment variable is used
2323

24-
aggs = client.get_aggs(
24+
aggs = []
25+
for a in client.list_aggs(
2526
"AAPL",
2627
1,
2728
"hour",
2829
"2023-01-30",
2930
"2023-02-03",
30-
)
31+
limit=50000,
32+
):
33+
aggs.append(a)
3134

3235
print(aggs)
3336

examples/rest/stocks-aggregates_bars_highcharts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@
7070

7171
client = RESTClient() # POLYGON_API_KEY environment variable is used
7272

73-
aggs = client.get_aggs(
73+
aggs = []
74+
for a in client.list_aggs(
7475
"AAPL",
7576
1,
7677
"day",
7778
"2019-01-01",
7879
"2023-02-16",
7980
limit=50000,
80-
)
81+
):
82+
aggs.append(a)
8183

8284
# print(aggs)
8385

0 commit comments

Comments
 (0)