Open nima opened 3 years ago
Something like:
87 def _get_field(self, endpoint, field):
88 try:
89 data = getattr(self, "get_%s" % endpoint)(filter_=field)
90 except AttributeError:
91 raise NotImplementedError("Endpoint %s not implemented." % endpoint)
92 try:
93 if self.output_format == "json":
94 if self.single_symbol:
95 data = data[field]
96 else:
97 data = {symbol: data[symbol][field] for symbol in self.symbols}
98 else:
99 if self.single_symbol:
100 return data[field][0]
101 except KeyError:
102 raise KeyError("Field %s not found in %s." % (field, endpoint))
103 return data
Format of data that raises the exception:
That is,
data[ticker]['sharesOutstanding']
Traceback:
That's because it's looking for 'sharesOutstanding' directly in the top-level data, which won't have it as it's indexed on ticker for multi-ticker queries.
Might be simpler to, rather than explicitly look for a problem, place this block in a try/except block.