JSON响应在一行中,需要转换为数据帧

2024-06-16 09:38:35 发布

您现在位置:Python中文网/ 问答频道 /正文

使用TDAmeritrade API

我提出这样的要求:

urlData = requests.get(url = endpoint).content

请求选项链信息时,输出是一个长JSON字符串

{'symbol': 'AAN', 'status': 'SUCCESS', 'underlying': {'symbol': 'AAN', 'description': 'Aarons Holdings Company, Inc. Common Stock', 'change': 0.29, 'percentChange': 1.45, 'close': 19.97, 'quoteTime': 1613516444153, 'tradeTime': 1613520000004, 'bid': 16.84, 'ask': 20.98, 'last': 20.26, 'mark': 20.26, 'markChange': 0.29, 'markPercentChange': 1.45, 'bidSize': 100, 'askSize': 100, 'highPrice': 20.35, 'lowPrice': 19.5, 'openPrice': 20.03, 'totalVolume': 433998, 'exchangeName': 'NYS', 'fiftyTwoWeekHigh': 22.99, 'fiftyTwoWeekLow': 16.2, 'delayed': True}, 'strategy': 'SINGLE', 'interval': 0.0, 'isDelayed': True, 'isIndex': False, 'interestRate': 0.1, 'underlyingPrice': 18.91, 'volatility': 29.0, 'daysToExpiration': 0.0, 'numberOfContracts': 20, 'putExpDateMap': {}, 'callExpDateMap': {'2021-02-19:3': {'7.5': [{'putCall': 'CALL', 'symbol': 'AAN_021921C7.5', 'description': 'AAN Feb 19 2021 7.5 Call', 'exchangeName': 'OPR', 'bid': 10.8, 'ask': 14.4, 'last': 0.0, 'mark': 12.63, 'bidSize': 71, 'askSize': 12, 'bidAskSize': '71X12', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 12.47, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509199327, 'netChange': 0.0, 'volatility': 267.804, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': -0.16, 'theoreticalOptionValue': 12.76, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 7.5, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.16, 'markPercentChange': 1.28, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '10.0': [{'putCall': 'CALL', 'symbol': 'AAN_021921C10', 'description': 'AAN Feb 19 2021 10 Call', 'exchangeName': 'OPR', 'bid': 8.4, 'ask': 12.0, 'last': 0.0, 'mark': 10.13, 'bidSize': 71, 'askSize': 12, 'bidAskSize': '71X12', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 9.97, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509199327, 'netChange': 0.0, 'volatility': 191.848, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': -0.06, 'theoreticalOptionValue': 10.26, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 10.0, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.16, 'markPercentChange': 1.6, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '12.5': [{'putCall': 'CALL', 'symbol': 'AAN_021921C12.5', 'description': 'AAN Feb 19 2021 12.5 Call', 'exchangeName': 'OPR', 'bid': 5.5, 'ask': 9.7, 'last': 5.62, 'mark': 7.63, 'bidSize': 71, 'askSize': 41, 'bidAskSize': '71X41', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 7.47, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612368669575, 'quoteTimeInLong': 1613509199327, 'netChange': -1.85, 'volatility': 132.641, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': -2.14, 'theoreticalOptionValue': 7.76, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 12.5, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': -24.77, 'markChange': 0.16, 'markPercentChange': 2.14, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '15.0': [{'putCall': 'CALL', 'symbol': 'AAN_021921C15', 'description': 'AAN Feb 19 2021 15 Call', 'exchangeName': 'OPR', 'bid': 3.2, 'ask': 6.9, 'last': 2.32, 'mark': 5.13, 'bidSize': 82, 'askSize': 12, 'bidAskSize': '82X12', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 4.97, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612191062770, 'quoteTimeInLong': 1613509199327, 'netChange': -2.65, 'volatility': 90.654, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': -2.94, 'theoreticalOptionValue': 5.26, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 15.0, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': -53.32, 'markChange': 0.16, 'markPercentChange': 3.22, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '17.5': [{'putCall': 'CALL', 'symbol': 'AAN_021921C17.5', 'description': 'AAN Feb 19 2021 17.5 Call', 'exchangeName': 'OPR', 'bid': 0.7, 'ask': 3.0, 'last': 3.24, 'mark': 2.64, 'bidSize': 75, 'askSize': 12, 'bidAskSize': '75X12', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 2.48, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612969610265, 'quoteTimeInLong': 1613509188876, 'netChange': 0.76, 'volatility': 90.475, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': 0.48, 'theoreticalOptionValue': 2.76, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 17.5, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 30.51, 'markChange': 0.16, 'markPercentChange': 6.36, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '20.0': [{'putCall': 'CALL', 'symbol': 'AAN_021921C20', 'description': 'AAN Feb 19 2021 20 Call', 'exchangeName': 'OPR', 'bid': 0.15, 'ask': 0.8, 'last': 0.5, 'mark': 0.75, 'bidSize': 422, 'askSize': 13, 'bidAskSize': '422X13', 'lastSize': 0, 'highPrice': 0.5, 'lowPrice': 0.5, 'openPrice': 0.0, 'closePrice': 0.52, 'totalVolume': 94, 'tradeDate': None, 'tradeTimeInLong': 1613497959768, 'quoteTimeInLong': 1613509198419, 'netChange': -0.03, 'volatility': 90.707, 'delta': 0.541, 'gamma': 0.231, 'theta': -0.073, 'vega': 0.008, 'rho': 0.001, 'openInterest': 0, 'timeValue': 0.24, 'theoreticalOptionValue': 0.767, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 20.0, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': -4.76, 'markChange': 0.23, 'markPercentChange': 43.68, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '22.5': [{'putCall': 'CALL', 'symbol': 'AAN_021921C22.5', 'description': 'AAN Feb 19 2021 22.5 Call', 'exchangeName': 'OPR', 'bid': 0.0, 'ask': 0.05, 'last': 0.05, 'mark': 0.09, 'bidSize': 0, 'askSize': 2, 'bidAskSize': '0X2', 'lastSize': 0, 'highPrice': 0.05, 'lowPrice': 0.05, 'openPrice': 0.0, 'closePrice': 0.02, 'totalVolume': 5, 'tradeDate': None, 'tradeTimeInLong': 1613507732065, 'quoteTimeInLong': 1613508592347, 'netChange': 0.03, 'volatility': 90.199, 'delta': 0.11, 'gamma': 0.103, 'theta': -0.041, 'vega': 0.004, 'rho': 0.0, 'openInterest': 0, 'timeValue': 0.05, 'theoreticalOptionValue': 0.093, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 22.5, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 121.24, 'markChange': 0.07, 'markPercentChange': 312.39, 'mini': False, 'inTheMoney': False, 'nonStandard': False}], '25.0': [{'putCall': 'CALL', 'symbol': 'AAN_021921C25', 'description': 'AAN Feb 19 2021 25 Call', 'exchangeName': 'OPR', 'bid': 0.0, 'ask': 0.05, 'last': 0.05, 'mark': 0.01, 'bidSize': 0, 'askSize': 13, 'bidAskSize': '0X13', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 0.0, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612976572056, 'quoteTimeInLong': 1613508610431, 'netChange': 0.05, 'volatility': 'NaN', 'delta': 'NaN', 'gamma': 'NaN', 'theta': 'NaN', 'vega': 0.001, 'rho': 'NaN', 'openInterest': 0, 'timeValue': 0.05, 'theoreticalOptionValue': 'NaN', 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 25.0, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 24900.0, 'markChange': 0.0, 'markPercentChange': 2400.0, 'mini': False, 'inTheMoney': False, 'nonStandard': False}], '30.0': [{'putCall': 'CALL', 'symbol': 'AAN_021921C30', 'description': 'AAN Feb 19 2021 30 Call', 'exchangeName': 'OPR', 'bid': 0.0, 'ask': 2.25, 'last': 0.05, 'mark': 0.0, 'bidSize': 0, 'askSize': 110, 'bidAskSize': '0X110', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 0.0, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612986323915, 'quoteTimeInLong': 1613509101800, 'netChange': 0.05, 'volatility': 110.981, 'delta': 0.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': 0.05, 'theoreticalOptionValue': 0.0, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 30.0, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 49900.0, 'markChange': 0.0, 'markPercentChange': 0.0, 'mini': False, 'inTheMoney': False, 'nonStandard': False}], '35.0': [{'putCall': 'CALL', 'symbol': 'AAN_021921C35', 'description': 'AAN Feb 19 2021 35 Call', 'exchangeName': 'OPR', 'bid': 0.0, 'ask': 2.25, 'last': 0.0, 'mark': 0.0, 'bidSize': 0, 'askSize': 110, 'bidAskSize': '0X110', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 0.0, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509101800, 'netChange': 0.0, 'volatility': 149.722, 'delta': 0.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': 1.13, 'theoreticalOptionValue': 0.0, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 35.0, 'expirationDate': 1613768400000, 'daysToExpiration': 3, 'expirationType': 'R', 'lastTradingDay': 1613782800000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.0, 'markPercentChange': 0.0, 'mini': False, 'inTheMoney': False, 'nonStandard': False}]}, '2021-03-19:31': {'7.5': [{'putCall': 'CALL', 'symbol': 'AAN_031921C7.5', 'description': 'AAN Mar 19 2021 7.5 Call', 'exchangeName': 'OPR', 'bid': 10.9, 'ask': 14.2, 'last': 0.0, 'mark': 12.63, 'bidSize': 99, 'askSize': 11, 'bidAskSize': '99X11', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 12.47, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509101578, 'netChange': 0.0, 'volatility': 88.391, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': -0.21, 'theoreticalOptionValue': 12.76, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 7.5, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.16, 'markPercentChange': 1.28, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '10.0': [{'putCall': 'CALL', 'symbol': 'AAN_031921C10', 'description': 'AAN Mar 19 2021 10 Call', 'exchangeName': 'OPR', 'bid': 8.9, 'ask': 11.7, 'last': 0.0, 'mark': 10.13, 'bidSize': 100, 'askSize': 12, 'bidAskSize': '100X12', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 9.97, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509188876, 'netChange': 0.0, 'volatility': 78.986, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': 0.04, 'theoreticalOptionValue': 10.26, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 10.0, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.16, 'markPercentChange': 1.6, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '12.5': [{'putCall': 'CALL', 'symbol': 'AAN_031921C12.5', 'description': 'AAN Mar 19 2021 12.5 Call', 'exchangeName': 'OPR', 'bid': 5.5, 'ask': 10.0, 'last': 0.0, 'mark': 7.63, 'bidSize': 107, 'askSize': 53, 'bidAskSize': '107X53', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 7.47, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509099200, 'netChange': 0.0, 'volatility': 79.232, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': -0.01, 'theoreticalOptionValue': 7.76, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 12.5, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.16, 'markPercentChange': 2.1, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '15.0': [{'putCall': 'CALL', 'symbol': 'AAN_031921C15', 'description': 'AAN Mar 19 2021 15 Call', 'exchangeName': 'OPR', 'bid': 3.2, 'ask': 7.7, 'last': 0.0, 'mark': 5.13, 'bidSize': 119, 'askSize': 47, 'bidAskSize': '119X47', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 5.07, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509099200, 'netChange': 0.0, 'volatility': 79.486, 'delta': 1.0, 'gamma': 0.0, 'theta': 0.0, 'vega': 0.0, 'rho': 0.0, 'openInterest': 0, 'timeValue': 0.19, 'theoreticalOptionValue': 5.26, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 15.0, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.06, 'markPercentChange': 1.14, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '17.5': [{'putCall': 'CALL', 'symbol': 'AAN_031921C17.5', 'description': 'AAN Mar 19 2021 17.5 Call', 'exchangeName': 'OPR', 'bid': 3.1, 'ask': 3.9, 'last': 3.2, 'mark': 3.0, 'bidSize': 34, 'askSize': 12, 'bidAskSize': '34X12', 'lastSize': 0, 'highPrice': 3.2, 'lowPrice': 3.2, 'openPrice': 0.0, 'closePrice': 3.1, 'totalVolume': 2, 'tradeDate': None, 'tradeTimeInLong': 1613489413317, 'quoteTimeInLong': 1613509199528, 'netChange': 0.1, 'volatility': 81.931, 'delta': 0.766, 'gamma': 0.092, 'theta': -0.012, 'vega': 0.016, 'rho': 0.005, 'openInterest': 0, 'timeValue': 0.44, 'theoreticalOptionValue': 3.09, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 17.5, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 3.34, 'markChange': -0.1, 'markPercentChange': -3.12, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '20.0': [{'putCall': 'CALL', 'symbol': 'AAN_031921C20', 'description': 'AAN Mar 19 2021 20 Call', 'exchangeName': 'OPR', 'bid': 1.4, 'ask': 2.3, 'last': 1.73, 'mark': 1.8, 'bidSize': 183, 'askSize': 13, 'bidAskSize': '183X13', 'lastSize': 0, 'highPrice': 1.73, 'lowPrice': 1.73, 'openPrice': 0.0, 'closePrice': 1.75, 'totalVolume': 10, 'tradeDate': None, 'tradeTimeInLong': 1613488729667, 'quoteTimeInLong': 1613509059407, 'netChange': -0.02, 'volatility': 87.441, 'delta': 0.516, 'gamma': 0.085, 'theta': -0.021, 'vega': 0.023, 'rho': 0.006, 'openInterest': 0, 'timeValue': 1.47, 'theoreticalOptionValue': 1.799, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 20.0, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': -1.13, 'markChange': 0.05, 'markPercentChange': 2.82, 'mini': False, 'inTheMoney': True, 'nonStandard': False}], '22.5': [{'putCall': 'CALL', 'symbol': 'AAN_031921C22.5', 'description': 'AAN Mar 19 2021 22.5 Call', 'exchangeName': 'OPR', 'bid': 0.4, 'ask': 1.75, 'last': 1.22, 'mark': 1.15, 'bidSize': 113, 'askSize': 13, 'bidAskSize': '113X13', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 1.1, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612984246845, 'quoteTimeInLong': 1613509186270, 'netChange': 0.12, 'volatility': 96.556, 'delta': 0.35, 'gamma': 0.067, 'theta': -0.025, 'vega': 0.021, 'rho': 0.004, 'openInterest': 0, 'timeValue': 1.22, 'theoreticalOptionValue': 1.154, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 22.5, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 10.89, 'markChange': 0.05, 'markPercentChange': 4.85, 'mini': False, 'inTheMoney': False, 'nonStandard': False}], '25.0': [{'putCall': 'CALL', 'symbol': 'AAN_031921C25', 'description': 'AAN Mar 19 2021 25 Call', 'exchangeName': 'OPR', 'bid': 0.35, 'ask': 1.35, 'last': 0.55, 'mark': 0.82, 'bidSize': 70, 'askSize': 174, 'bidAskSize': '70X174', 'lastSize': 0, 'highPrice': 0.55, 'lowPrice': 0.55, 'openPrice': 0.0, 'closePrice': 0.6, 'totalVolume': 50, 'tradeDate': None, 'tradeTimeInLong': 1613487939133, 'quoteTimeInLong': 1613509199327, 'netChange': -0.05, 'volatility': 106.171, 'delta': 0.251, 'gamma': 0.051, 'theta': -0.025, 'vega': 0.019, 'rho': 0.003, 'openInterest': 0, 'timeValue': 0.55, 'theoreticalOptionValue': 0.815, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 25.0, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': -8.33, 'markChange': 0.22, 'markPercentChange': 35.85, 'mini': False, 'inTheMoney': False, 'nonStandard': False}], '30.0': [{'putCall': 'CALL', 'symbol': 'AAN_031921C30', 'description': 'AAN Mar 19 2021 30 Call', 'exchangeName': 'OPR', 'bid': 0.0, 'ask': 2.3, 'last': 0.9, 'mark': 0.28, 'bidSize': 0, 'askSize': 154, 'bidAskSize': '0X154', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 0.25, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 1612807859375, 'quoteTimeInLong': 1613509101800, 'netChange': 0.65, 'volatility': 106.333, 'delta': 0.105, 'gamma': 0.029, 'theta': -0.015, 'vega': 0.011, 'rho': 0.002, 'openInterest': 0, 'timeValue': 0.9, 'theoreticalOptionValue': 0.28, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 30.0, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 259.14, 'markChange': 0.03, 'markPercentChange': 11.81, 'mini': False, 'inTheMoney': False, 'nonStandard': False}], '35.0': [{'putCall': 'CALL', 'symbol': 'AAN_031921C35', 'description': 'AAN Mar 19 2021 35 Call', 'exchangeName': 'OPR', 'bid': 0.0, 'ask': 2.4, 'last': 0.0, 'mark': 0.09, 'bidSize': 0, 'askSize': 85, 'bidAskSize': '0X85', 'lastSize': 0, 'highPrice': 0.0, 'lowPrice': 0.0, 'openPrice': 0.0, 'closePrice': 0.08, 'totalVolume': 0, 'tradeDate': None, 'tradeTimeInLong': 0, 'quoteTimeInLong': 1613509100100, 'netChange': 0.0, 'volatility': 106.398, 'delta': 0.04, 'gamma': 0.014, 'theta': -0.008, 'vega': 0.005, 'rho': 0.001, 'openInterest': 0, 'timeValue': 1.2, 'theoreticalOptionValue': 0.093, 'theoreticalVolatility': 29.0, 'optionDeliverablesList': None, 'strikePrice': 35.0, 'expirationDate': 1616184000000, 'daysToExpiration': 31, 'expirationType': 'R', 'lastTradingDay': 1616198400000, 'multiplier': 100.0, 'settlementType': ' ', 'deliverableNote': '', 'isIndexOption': None, 'percentChange': 0.0, 'markChange': 0.01, 'markPercentChange': 15.92, 'mini': False, 'inTheMoney': False, 'nonStandard': False}]}}}

我试图用pandas.io.json.json_normalize函数解析它。它不接受我的元列标题

result = pandas.json_normalize(urlData, record_path="symbol", meta=['putCall' ,'symbol' ,'description' ,'exchangeName' ,'bidPrice' ,'askPrice' ,'lastPrice' ,'markPrice' ,'bidSize' ,'askSize' ,'lastSize' ,'highPrice' ,'lowPrice' ,'openPrice' ,'closePrice' ,'totalVolume' ,'quoteTimeInLong' ,'tradeTimeInLong' ,'netChange' ,'volatility' ,'delta' ,'gamma' ,'theta' ,'vega' ,'rho' ,'timeValue' ,'openInterest' ,'isInTheMoney' ,'theoreticalOptionValue' ,'theoreticalVolatility' ,'isMini' ,'isNonStandard' ,'optionDeliverablesList'])

目标是将:左侧的所有字段作为列标题,并将:右侧的信息放在行中


Tags: nonefalsedescriptionsymbolvolatilitybidpercentchangeopenprice
1条回答
网友
1楼 · 发布于 2024-06-16 09:38:35

问题是您的数据不在record_path="symbol"中,而是嵌套在callExpDateMap

enter image description here

您必须创建一个新数组,并遍历callExpDateMap及其子json以获取该数组

callExpDateMap = urlData["callExpDateMap"]
a = []
for x in callExpDateMap:
    for y in callExpDateMap[x]:
        a += callExpDateMap[x][y]
result = pandas.json_normalize(a, meta=['putCall' ,'symbol' ,'description' ,'exchangeName' ,'bidPrice' ,'askPrice' ,'lastPrice' ,'markPrice' ,'bidSize' ,'askSize' ,'lastSize' ,'highPrice' ,'lowPrice' ,'openPrice' ,'closePrice' ,'totalVolume' ,'quoteTimeInLong' ,'tradeTimeInLong' ,'netChange' ,'volatility' ,'delta' ,'gamma' ,'theta' ,'vega' ,'rho' ,'timeValue' ,'openInterest' ,'isInTheMoney' ,'theoreticalOptionValue' ,'theoreticalVolatility' ,'isMini' ,'isNonStandard' ,'optionDeliverablesList'])

Result

相关问题 更多 >