alexgolec / tda-api

A TD Ameritrade API client for Python. Includes historical data for equities and ETFs, options chains, streaming order book data, complex order construction, and more.
https://tda-api.readthedocs.io
MIT License
1.26k stars 335 forks source link

tda.client.get_price_history call is failing for weekly data with start and end date #331

Closed chotaGit closed 1 year ago

chotaGit commented 1 year ago

Description of Bug tda.client.get_price_history call is failing for weekly data with start and end date

Code to Reproduce tda.client.get_price_history('AAPL', start_datetime=datetime.datetime.strptime('20200115','%Y%m%d'), end_datetime=datetime.datetime.strptime('20230114','%Y%m%d'), frequency_type=Client.PriceHistory.FrequencyType.WEEKLY, frequency=Client.PriceHistory.Frequency.WEEKLY)

Expected Behavior code should return weekly data candles

Actual Behavior Code is throwing the following error: Traceback (most recent call last): File "D:\pyproj\tradepkg\tradeSvc\tdaTradeSvc.py", line 450, in dfRaw = tda.getPriceHistoryDF('TSLA',freq=Client.PriceHistory.Frequency.WEEKLY,freqType='weekly',startDate='20210115',endDate='20230114') File "D:\pyproj\tradepkg\tradeSvc\tdaTradeSvc.py", line 143, in getPriceHistoryDF df = pd.json_normalize(self.getPriceHistory(ticker, freq=freq, freqType=freqType, startDate=startDate, endDate=endDate, extHoursData=extHoursData)['candles']) KeyError: 'candles'

Error/Exception Log, If Applicable NA

chotaGit commented 1 year ago

Error on my part. I did not specify the period type.