I am trying to create a function that returns a days historical data for a certain symbol in python and have run across an error where whenever I call this function it return to me:
JavaScript
x
2
1
[{'candles': [], 'symbol': 'snap', 'empty': True}, {'candles': [], 'symbol': 'fb', 'empty': True}]
2
My expected output would be one where the candles list is filled with data for that certain stock. Here is my code so far:
JavaScript
1
19
19
1
def historical(symbols, key=TD_KEY, periodType="day", period=1, frequency="minute", needExtended=False):
2
# Gets historical data
3
return_list = []
4
for symbol in symbols:
5
url = f"/marketdata/{symbol}/pricehistory"
6
endpoint = f"{TD_URL}{url}"
7
payload = {"apikey":key,
8
"periodType": periodType,
9
"period": period,
10
"frequencyType": frequency,
11
"needExtendedHoursData": needExtended}
12
response = requests.get(url=endpoint, params=payload)
13
14
if str(response) == "<Response [200]>":
15
return_list.append(response.json())
16
else:
17
return f"Could not seccusfully connect http code {response}"
18
time.sleep(0.5)
19
Advertisement
Answer
The reason behind this strange behavior was because when I was requesting historical data I put my query in lower case and only I changed that to upper case it was able to pull down the data I needed.