I can't figure out how to get data for a given day. Using the annual line in my code, I know the milisecond value of give date.
1612159200000.00 AAPL 2/1/2021 6:00
1612418400000.00 AAPL 2/4/2021 6:00
But putting these value in the code doesn't work
data=get_price_history(symbol=i, endDate=1612418400000 , startDate=1612159200000, frequency=1, frequencyType='daily')import requests
import pandas as pd
import time
import datetime
# tickers_list= ['AAPL', 'AMGN', 'AXP']
# print(len(tickers_list))
key = '****'
def get_price_history(**kwargs): url = '(kwargs.get('symbol')) params = {} params.update({'apikey': key}) for arg in kwargs: parameter = {arg: kwargs.get(arg)} params.update(parameter) return requests.get(url, params=params).json()
tickers_list= ['AAPL', 'AMGN','WMT']
for i in tickers_list: # get data 1 year 1 day frequency -- good # data=get_price_history(symbol=i, period=1, periodType='year', frequency=1, frequencyType='daily') data=get_price_history(symbol=i, endDate=1612418400000 , startDate=1612159200000, frequency=1, frequencyType='daily') historical['date'] = pd.to_datetime(historical['datetime'], unit='ms') info=pd.DataFrame(data['candles']) historical=pd.concat([historical,info])
historical 1 1 Answer
From the Ameritrade Price History API documentation:
6 Months / 1 Day, including today's data:
Note that periodType=month is specified because the default periodType is day which is not compatible with the frequencyType daily
So it seems that this line in your code:
data=get_price_history(symbol=i, endDate=1612418400000 , startDate=1612159200000, frequency=1, frequencyType='daily')is missing a valid periodType parameter. Try:
data=get_price_history(symbol=i, endDate=1612418400000 , startDate=1612159200000, frequency=1, periodType='month', frequencyType='daily') 1