I am using option chain output from TD Ameritrade and would like to access various values such as bid, ask, etc. and the symbol and price from underlying header.
My problem seems to be the date and strike price are keys and not fixed.
The JSON format looks as follows:
(I couldn't post my question the json text looked like code... not sure how to post that)
The output I desire should look like this:
symbol underlyingprice putCall expdate strike bid ask
-------------------------------------------------------------------------
AMZN 90.965 PUT 2023-03-17:6 90.0 1.83 1.88
AMZN 90.965 PUT 2023-03-17:6 91.0 2.27 2.36
.
In the interests of brevity the JSON in the following code is a much reduced example of the JSON presented in a previous Stack Overflow question, Parse Nested JSON Data of Share Market Data, which also seems to be using data returned from Ameritrade's Get Open Chain method:
Which yields the output:
So how does this query work? The property keys inside
putExpDateMapare dynamic so we cannot use a hardcoded JSON path to access their contents. I use two CTE expressions to enumerate the keys:putExpDateMapKeysenumerates the date keys, e.g.:"2021-01-08:8"strikePriceKeysenumerates the strike price keys, e.g.:"132.0"and"133.0"Each CTE expression also returns a JSON path which then allows the final invocation of
openjson()to access theputCall,bid,askandstrikePricevalues.