[英]TD Amertirade API price history - json string return
I have a question regarding the json string returned from the "price history" api from td ameritrade.我有一个关于从 td ameritrade 的“价格历史”api 返回的 json 字符串的问题。 In my python code I am able to get the candle data into a pd dataframe.
在我的 python 代码中,我能够将蜡烛数据放入 pd 数据帧中。 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.
我使用 CBOE/NYSE 等各种网站来创建我的股票代码列表,但是我注意到一些股票代码,例如 AACQ,不返回任何数据。 This could be handled if create an If loop on the "empty = true" portion of the json string.
如果在 json 字符串的“empty = true”部分创建 If 循环,则可以处理此问题。 This is the generic json response summary
这是通用的 json 响应摘要
//CandleList:
{
"candles": [
{
"close": 0,
"datetime": 0,
"high": 0,
"low": 0,
"open": 0,
"volume": 0
}
],
"empty": false,
"symbol": "string"
}
I get the OHLC data via我通过以下方式获得 OHLC 数据
# 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'.在我看来,json 字符串可以制成 3 个对象,1 个“蜡烛”、2 个“空”和 3 个“符号”。 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我能够使用 if 和 continue 语句在我的 while 循环中完成我想要的
if df1.empty == 1:
continue
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但我仍然很好奇是否如何处理后两个对象,甚至对选项链 json 响应更加好奇,即
//OptionChain:
{
"symbol": "string",
"status": "string",
"underlying": {
"ask": 0,
"askSize": 0,
"bid": 0,
"bidSize": 0,
"change": 0,
"close": 0,
"delayed": false,
"description": "string",
"exchangeName": "string",
"fiftyTwoWeekHigh": 0,
"fiftyTwoWeekLow": 0,
"highPrice": 0,
"last": 0,
"lowPrice": 0,
"mark": 0,
"markChange": 0,
"markPercentChange": 0,
"openPrice": 0,
"percentChange": 0,
"quoteTime": 0,
"symbol": "string",
"totalVolume": 0,
"tradeTime": 0
},
"strategy": "'SINGLE' or 'ANALYTICAL' or 'COVERED' or 'VERTICAL' or 'CALENDAR' or 'STRANGLE' or 'STRADDLE' or 'BUTTERFLY' or 'CONDOR' or 'DIAGONAL' or 'COLLAR' or 'ROLL'",
"interval": 0,
"isDelayed": false,
"isIndex": false,
"daysToExpiration": 0,
"interestRate": 0,
"underlyingPrice": 0,
"volatility": 0,
"callExpDateMap": "object",
"putExpDateMap": "object"
}
//StrikePriceMap:
{}
//Option:
{
"putCall": "'PUT' or 'CALL'",
"symbol": "string",
"description": "string",
"exchangeName": "string",
"bidPrice": 0,
"askPrice": 0,
"lastPrice": 0,
"markPrice": 0,
"bidSize": 0,
"askSize": 0,
"lastSize": 0,
"highPrice": 0,
"lowPrice": 0,
"openPrice": 0,
"closePrice": 0,
"totalVolume": 0,
"quoteTimeInLong": 0,
"tradeTimeInLong": 0,
"netChange": 0,
"volatility": 0,
"delta": 0,
"gamma": 0,
"theta": 0,
"vega": 0,
"rho": 0,
"timeValue": 0,
"openInterest": 0,
"isInTheMoney": false,
"theoreticalOptionValue": 0,
"theoreticalVolatility": 0,
"isMini": false,
"isNonStandard": false,
"optionDeliverablesList": [
{
"symbol": "string",
"assetType": "string",
"deliverableUnits": "string",
"currencyType": "string"
}
],
"strikePrice": 0,
"expirationDate": "string",
"expirationType": "string",
"multiplier": 0,
"settlementType": "string",
"deliverableNote": "string",
"isIndexOption": false,
"percentChange": 0,
"markChange": 0,
"markPercentChange": 0
}
//Underlying:
{
"ask": 0,
"askSize": 0,
"bid": 0,
"bidSize": 0,
"change": 0,
"close": 0,
"delayed": false,
"description": "string",
"exchangeName": "'IND' or 'ASE' or 'NYS' or 'NAS' or 'NAP' or 'PAC' or 'OPR' or 'BATS'",
"fiftyTwoWeekHigh": 0,
"fiftyTwoWeekLow": 0,
"highPrice": 0,
"last": 0,
"lowPrice": 0,
"mark": 0,
"markChange": 0,
"markPercentChange": 0,
"openPrice": 0,
"percentChange": 0,
"quoteTime": 0,
"symbol": "string",
"totalVolume": 0,
"tradeTime": 0
}
//ExpirationDate:
{
"date": "string"
}
//OptionDeliverables:
{
"symbol": "string",
"assetType": "string",
"deliverableUnits": "string",
"currencyType": "string"
}
I have been trying to figure out how to bring this data into my database.我一直在试图弄清楚如何将这些数据带入我的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.