Skip to content

KeyError: after_hours with Rest example in readme #69

Description

@satyan-g

from polygon import RESTClient

def main():
key = "your api key"

# RESTClient can be used as a context manager to facilitate closing the underlying http session
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
with RESTClient(key) as client:
    resp = client.stocks_equities_daily_open_close("AAPL", "2018-03-02")
    print(f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}")

if name == 'main':
main()


KeyError Traceback (most recent call last)
in
13
14 if name == 'main':
---> 15 main()

in main()
8 # https://requests.readthedocs.io/en/master/user/advanced/#session-objects
9 with RESTClient(POLYGON_API_KEY) as client:
---> 10 resp = client.stocks_equities_daily_open_close("AAPL", "2018-03-02")
11 print(f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}")
12

~/anaconda3/envs/test/lib/python3.8/site-packages/polygon/rest/client.py in stocks_equities_daily_open_close(self, symbol, date, **query_params)
126 **query_params) -> models.StocksEquitiesDailyOpenCloseApiResponse:
127 endpoint = f"{self.url}/v1/open-close/{symbol}/{date}"
--> 128 return self._handle_response("StocksEquitiesDailyOpenCloseApiResponse", endpoint, query_params)
129
130 def stocks_equities_condition_mappings(self, ticktype,

~/anaconda3/envs/test/lib/python3.8/site-packages/polygon/rest/client.py in _handle_response(self, response_type, endpoint, params)
31 resp: requests.Response = self._session.get(endpoint, params=params, timeout=self.timeout)
32 if resp.status_code == 200:
---> 33 return unmarshal.unmarshal_json(response_type, resp.json())
34 else:
35 resp.raise_for_status()

~/anaconda3/envs/test/lib/python3.8/site-packages/polygon/rest/models/unmarshal.py in unmarshal_json(response_type, resp_json)
6 def unmarshal_json(response_type, resp_json) -> Type[models.AnyDefinition]:
7 obj = models.name_to_classresponse_type
----> 8 obj.unmarshal_json(resp_json)
9 return obj

~/anaconda3/envs/test/lib/python3.8/site-packages/polygon/rest/models/definitions.py in unmarshal_json(self, input_json)
22 return self
23 elif isinstance(input_json, dict):
---> 24 self._unmarshal_json_object(input_json)
25 return self
26 elif isinstance(input_json, float) or isinstance(input_json, int):

~/anaconda3/envs/test/lib/python3.8/site-packages/polygon/rest/models/definitions.py in _unmarshal_json_object(self, input_json)
40 if key in self._swagger_name_to_python:
41 attribute_name = self._swagger_name_to_python[key]
---> 42 if not self._attribute_is_primitive[attribute_name]:
43 if attribute_name in self._attributes_to_types:
44 attribute_type = self._attributes_to_types[attribute_name]

KeyError: 'after_hours'

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions