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.
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'
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