addisonlynch / iexfinance

Python SDK for IEX Cloud
https://addisonlynch.github.io/iexfinance
Apache License 2.0
648 stars 136 forks source link

Failure in `get_sector` in bulk query when batch size is greater than one #267

Open nima opened 3 years ago

nima commented 3 years ago

Summary (include Python version)

Bulk calls to get_sector fail as soon as the list is larger than size 1.

Date/time of issue

Fri Apr 23 18:55:26 PDT 2021

Expected behavior

In [48]: tickers = ['AAPL','NIO']

In [49]: stocks = api.iex.Stock(tickers)

In [50]: stocks.get_sector()
{ 'AAPL': 'Foo', 'NIO': 'Bar' }

Actual behavior

In [35]: print(tickers)
['A', 'AAPL', 'ABBV', 'ACB', 'ACMR', 'ALB', 'ALK', 'ALL', 'ALXN', 'AMC', 'AMCX', 'AMD', 'AMZN', 'APPS', 'ARKK', 'ATVI', 'AXP', 'AZN', 'BA', 'BABA', 'BAC', 'BAR', 'BE', 'BFST', 'BIDU', 'BILI', 'BKI', 'BLDP', 'BND', 'BRK.B', 'BWA', 'C', 'CBOE', 'CCF', 'CMCSA', 'CNK', 'CNQ', 'COST', 'CRON', 'CSCO', 'CSL', 'CVX', 'CYD', 'D', 'DAL', 'DAN', 'DBX', 'DELL', 'DHT', 'DIS', 'DLTR', 'DVY', 'EA', 'EB', 'EBAY', 'EDV', 'ENBL', 'ESGC', 'ETSY', 'EXPE', 'EXPI', 'F', 'FB', 'FCAU', 'FEYE', 'FFIV', 'FGD', 'FHN', 'FI', 'FIT', 'FLEX', 'FLXS', 'FNF', 'FNKO', 'FOX', 'FOXA', 'FOXF', 'FPE', 'FSI', 'FTI', 'GDX', 'GE', 'GLMD', 'GM', 'GME', 'GOOG', 'GOOGL', 'GPRO', 'GRMN', 'GRPN', 'GS', 'GT', 'GTXMQ', 'GUNR', 'HAS', 'HNDL', 'HOG', 'HON', 'HUYA', 'IAU']

In [36]: fn_name = 'get_sector'

In [37]: stocks = api.iex.Stock(tickers)

In [38]: stocks
Out[38]: Stock(symbols=A,AAPL,ABBV,ACB,ACMR,ALB,ALK,ALL,ALXN,AMC,AMCX,AMD,AMZN,APPS,ARKK,ATVI,AXP,AZN,BA,BABA,BAC,BAR,BE,BFST,BIDU,BILI,BKI,BLDP,BND,BRK.B,BWA,C,CBOE,CCF,CMCSA,CNK,CNQ,COST,CRON,CSCO,CSL,CVX,CYD,D,DAL,DAN,DBX,DELL,DHT,DIS,DLTR,DVY,EA,EB,EBAY,EDV,ENBL,ESGC,ETSY,EXPE,EXPI,F,FB,FCAU,FEYE,FFIV,FGD,FHN,FI,FIT,FLEX,FLXS,FNF,FNKO,FOX,FOXA,FOXF,FPE,FSI,FTI,GDX,GE,GLMD,GM,GME,GOOG,GOOGL,GPRO,GRMN,GRPN,GS,GT,GTXMQ,GUNR,HAS,HNDL,HOG,HON,HUYA,IAU, output_format='json')

In [39]: stocks.get_sector()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-39-673ac3dd0b08> in <module>
----> 1 stocks.get_sector()

~/Development/rh/.venv/lib/python3.9/site-packages/iexfinance/stocks/base.py in get_sector(self)
    846 
    847     def get_sector(self):
--> 848         return self._get_field("company", "sector")
    849 
    850     def get_open(self):

~/Development/rh/.venv/lib/python3.9/site-packages/iexfinance/stocks/base.py in _get_field(self, endpoint, field)
     91             raise NotImplementedError("Endpoint %s not implemented." % endpoint)
     92         if field not in data:
---> 93             raise KeyError("Field %s not found in %s." % (field, endpoint))
     94         if self.output_format == "json":
     95             if self.single_symbol:

KeyError: 'Field sector not found in company.'

In [40]: stocks.get_sector?
Signature: stocks.get_sector()
Docstring: <no docstring>
File:      ~/Development/rh/.venv/lib/python3.9/site-packages/iexfinance/stocks/base.py
Type:      method

In [41]: