diff --git a/polygon/rest/aggs.py b/polygon/rest/aggs.py index c23dd66f..19472e45 100644 --- a/polygon/rest/aggs.py +++ b/polygon/rest/aggs.py @@ -86,8 +86,6 @@ def get_grouped_daily_aggs( options=options, ) - # TODO: next breaking change release move "market_type" to be 2nd mandatory - # param def get_daily_open_close_agg( self, ticker: str, diff --git a/polygon/rest/base.py b/polygon/rest/base.py index dedc2ea6..afef424e 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -86,10 +86,9 @@ def _get( self.BASE + path, fields=params, retries=self.retries, - headers={ - **option.edge_headers, - **self.headers, - }, # merge supplied headers with standard headers + headers=self._concat_headers( + option.edge_headers + ), # merge supplied headers with standard headers ) if resp.status != 200: @@ -160,6 +159,9 @@ def _get_params( return params + def _concat_headers(self, headers: Dict[str, str]) -> Dict[str, str]: + return {**headers, **self.headers} + def _paginate_iter( self, path: str, diff --git a/test_rest/models/test_requests.py b/test_rest/models/test_requests.py index 1fa4472c..597a2415 100644 --- a/test_rest/models/test_requests.py +++ b/test_rest/models/test_requests.py @@ -1,5 +1,6 @@ import unittest +from polygon import RESTClient from polygon.rest.models.request import ( RequestOptionBuilder, X_POLYGON_EDGE_ID, @@ -48,3 +49,23 @@ def test_request_options_builder(self): options = options.optional_edge_headers("test") self.assertDictEqual(all_options, options.edge_headers) + + def test_header_combination(self): + client = RESTClient(api_key="test") + options = RequestOptionBuilder( + edge_id="test", edge_ip_address="test", edge_user="test" + ) + + # this mocks the expected behavior during the request.get function call + # in the BaseClient. + headers = client._concat_headers(options.edge_headers) + + expected_headers = { + "Authorization": "Bearer test", + "User-Agent": "Polygon.io PythonClient/0.0.0", + "X-Polygon-Edge-ID": "test", + "X-Polygon-Edge-IP-Address": "test", + "X-Polygon-Edge-User-Agent": "test", + } + + self.assertDictEqual(headers, expected_headers)