Skip to content

unexpected error when iterate option aggs which has no trade data #474

@xuewei4d

Description

@xuewei4d

Describe the bug

Hi,

when I iterate this line

option_aggs = polygon_client.list_aggs("O:MSFT230106C00165000", 1, "day", "2023-01-01", "2023-07-21", limit=50000)

list(option_aggs) # for example

It reports an internal error

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[5], line 49
     47 option_aggs = polygon_client.list_aggs(option_contract.ticker, 1, "day", from_, to_, limit=50000)
     48 print(option_contract)
---> 49 print(len(list(option_aggs)))

File [~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0/LocalCache/local-packages/Python310/site-packages/polygon/rest/base.py:201), in BaseClient._paginate_iter(self, path, params, deserializer, result_key, options)
    192 resp = self._get(
    193     path=path,
    194     params=params,
   (...)
    198     options=options,
    199 )
    200 decoded = self._decode(resp)
--> 201 for t in decoded[result_key]:
    202     yield deserializer(t)
    203 if "next_url" in decoded:

KeyError: 'results'

To Reproduce

see above

Expected behavior

I checked the option contract, it does not have any trade as of 2023-01-01 all the way to its expiration date.

Should we raise StopIteration ?

Screenshots

Additional context

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions