I have a question regarding the json string returned from the "price history" api from td ameritrade. In my python code I am able to get the candle data into a pd dataframe. I use various sites like CBOE/NYSE to get create my ticker lists, however I've noticed some of the tickers, such as AACQ, don't return any data. This could be handled if create an If loop on the "empty = true" portion of the json string. This is the generic json response summary
//CandleList:
{
"candles": [
{
"close": 0,
"datetime": 0,
"high": 0,
"low": 0,
"open": 0,
"volume": 0
}
],
"empty": false,
"symbol": "string"
}
I get the OHLC data via
# define the payload
payload = {'apikey':client_id,
'periodType':'day',
'period':'10',
'frequencyType':'minute',
'frequency':'1',
'needExtendedHoursData':'false'}
# make a request content
time.sleep(0.501)
content = requests.get(url = endpoint, params = payload)
# convert it dictionary object
data = content.json()
#print(data)
hist = pd.DataFrame(data['candles'])
It appears to me that the json string could be made into 3 objects, 1 'candles' 2 'empty' and 3 'symbol'. Am I correct in this thinking and how might I do that. I have tried just coping my code and creating a dataframe using 'empty' but that did not work.
I was able to use the if and continue statement to accomplish what I wanted in my while loop
but I'm still curious if I how to handle the latter two objects and even more curious about the option chain json response, which is
I have been trying to figure out how to bring this data into my database.