From 232678dc06c639e5bbdd43b51ac1994c146606c0 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:40:30 -0700 Subject: [PATCH 1/3] Fix parameter naming and add missing parameters in list_universal_snapshots --- examples/rest/universal-snapshot.py | 14 ++++++++------ polygon/rest/snapshot.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/rest/universal-snapshot.py b/examples/rest/universal-snapshot.py index 8f4d9be6..44cd6d68 100644 --- a/examples/rest/universal-snapshot.py +++ b/examples/rest/universal-snapshot.py @@ -1,7 +1,5 @@ from typing import cast, Iterator, Union - from urllib3 import HTTPResponse - from polygon import RESTClient from polygon.rest.models import UniversalSnapshot, SnapshotMarketType @@ -10,8 +8,7 @@ # https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html # client = RESTClient("XXXXXX") # hardcoded api_key is used -client = RESTClient() # POLYGON_API_KEY environment variable is used - +client = RESTClient(trace=True) # POLYGON_API_KEY environment variable is used def print_snapshots(iterator: Union[Iterator[UniversalSnapshot], HTTPResponse]): snapshots = [s for s in iterator] @@ -36,11 +33,16 @@ def print_snapshots(iterator: Union[Iterator[UniversalSnapshot], HTTPResponse]): print_snapshots(it) it = client.list_universal_snapshots( - market_type=SnapshotMarketType.STOCKS, ticker_gt="A", ticker_lt="AAPL" + type="stocks", ticker_gt="A", ticker_lt="AAPL" ) print_snapshots(it) it = client.list_universal_snapshots( - market_type=SnapshotMarketType.STOCKS, ticker_gte="AAPL", ticker_lte="ABB" + type="stocks", ticker_gte="AAPL", ticker_lte="ABB" ) print_snapshots(it) + +it = client.list_universal_snapshots( + type="options", ticker_gte="O:AAPL230804C00050000", ticker_lte="O:AAPL230804C00070000" +) +print_snapshots(it) \ No newline at end of file diff --git a/polygon/rest/snapshot.py b/polygon/rest/snapshot.py index 0fb19fd0..3d6a6ce7 100644 --- a/polygon/rest/snapshot.py +++ b/polygon/rest/snapshot.py @@ -8,6 +8,8 @@ SnapshotTickerFullBook, UniversalSnapshot, IndicesSnapshot, + Sort, + Order, ) from urllib3 import HTTPResponse @@ -24,8 +26,11 @@ def get_locale(market_type: Union[SnapshotMarketType, str]): class SnapshotClient(BaseClient): def list_universal_snapshots( self, - market_type: Optional[Union[str, SnapshotMarketType]] = None, + type: Optional[Union[str, SnapshotMarketType]] = None, ticker_any_of: Optional[List[str]] = None, + order: Optional[Union[str, Order]] = None, + limit: Optional[int] = 10, + sort: Optional[Union[str, Sort]] = None, ticker_lt: Optional[str] = None, ticker_lte: Optional[str] = None, ticker_gt: Optional[str] = None, @@ -42,8 +47,11 @@ def list_universal_snapshots( - https://polygon.io/docs/forex/get_v3_snapshot - https://polygon.io/docs/crypto/get_v3_snapshot - :param market_type: the type of the asset + :param type: the type of the asset :param ticker_any_of: Comma-separated list of tickers, up to a maximum of 250. If no tickers are passed then all + :param order: The order to sort the results on. Default is asc (ascending). + :param limit: Limit the size of the response per-page, default is 10 and max is 250. + :param sort: The field to sort the results on. Default is ticker. If the search query parameter is present, sort is ignored and results are ordered by relevance. results will be returned in a paginated manner. Warning: The maximum number of characters allowed in a URL are subject to your technology stack. :param ticker_lt search for tickers less than From eab6fc0df4c93771608b1c8968d0a34cf2701ecb Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:43:12 -0700 Subject: [PATCH 2/3] Turn request tracing off --- examples/rest/universal-snapshot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rest/universal-snapshot.py b/examples/rest/universal-snapshot.py index 44cd6d68..1abc60fc 100644 --- a/examples/rest/universal-snapshot.py +++ b/examples/rest/universal-snapshot.py @@ -8,7 +8,7 @@ # https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html # client = RESTClient("XXXXXX") # hardcoded api_key is used -client = RESTClient(trace=True) # POLYGON_API_KEY environment variable is used +client = RESTClient() # POLYGON_API_KEY environment variable is used def print_snapshots(iterator: Union[Iterator[UniversalSnapshot], HTTPResponse]): snapshots = [s for s in iterator] From 67a75a8a54671742d77f7d8d6a59829c6dd14faf Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:45:07 -0700 Subject: [PATCH 3/3] Fix linting --- examples/rest/universal-snapshot.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/rest/universal-snapshot.py b/examples/rest/universal-snapshot.py index 1abc60fc..1ab5e804 100644 --- a/examples/rest/universal-snapshot.py +++ b/examples/rest/universal-snapshot.py @@ -10,6 +10,7 @@ # client = RESTClient("XXXXXX") # hardcoded api_key is used client = RESTClient() # POLYGON_API_KEY environment variable is used + def print_snapshots(iterator: Union[Iterator[UniversalSnapshot], HTTPResponse]): snapshots = [s for s in iterator] @@ -32,17 +33,15 @@ def print_snapshots(iterator: Union[Iterator[UniversalSnapshot], HTTPResponse]): ) print_snapshots(it) -it = client.list_universal_snapshots( - type="stocks", ticker_gt="A", ticker_lt="AAPL" -) +it = client.list_universal_snapshots(type="stocks", ticker_gt="A", ticker_lt="AAPL") print_snapshots(it) -it = client.list_universal_snapshots( - type="stocks", ticker_gte="AAPL", ticker_lte="ABB" -) +it = client.list_universal_snapshots(type="stocks", ticker_gte="AAPL", ticker_lte="ABB") print_snapshots(it) it = client.list_universal_snapshots( - type="options", ticker_gte="O:AAPL230804C00050000", ticker_lte="O:AAPL230804C00070000" + type="options", + ticker_gte="O:AAPL230804C00050000", + ticker_lte="O:AAPL230804C00070000", ) -print_snapshots(it) \ No newline at end of file +print_snapshots(it)