Getting Options data in JSON format from Yahoo
Author: sedelstein
Creation Date: 12/14/2017 7:40 PM
profile picture

sedelstein

#1
Hi Eugene and WL Community

It turns out you can get options data from Yahoo and I'd like to incorporate it into one of my WL routines

For example https://query1.finance.yahoo.com/v7/finance/options/QQQ171215C00156000
will get you data on the Dec-15 156 call on QQQ

It returns JSON output which can be parsed in C# using a JavaScriptSerializer class, which is part of the System.Web.Script

Examples of how to do this can be found here https://www.codementor.io/andrewbuchan/how-to-parse-json-into-a-c-object-4ui1o0bx8

A link here http://json2csharp.com/# will create C# classes for you from the JSON output (example below)

I am unable to find a reference to this within the C# editor in WL
Anyone have some ideas how to get access to this? (or perhaps this has already been discussed)
Thanks for the help

Steve


CODE:
Please log in to see this code.
profile picture

Eugene

#2
Hi Steve,

QUOTE:
I am unable to find a reference to this within the C# editor in WL

How come? References > .NET framework. If something's not listed, look for the DLL file to refer under:

c:\Windows\Microsoft.NET\Framework64\v4.0.30319\

You can even skip the generation of classes as .NET's JavaScriptSerializer will do a great job on dynamic deserialization of JSON:

CODE:
Please log in to see this code.


Take a look at Community Components:

\ExtensionMethods\InternetEx.cs > GetExchange
\Classes\Sentiment.cs > ParseStockTwitsJson
profile picture

sedelstein

#3
Thanks for the help Eugene


Went looking in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\

I have the directory though System.Web.Script and JavaScriptSerializer don't appear.

I don't mean to be thick about this but not sure why that is. I do see a serializer for XML unless it is in System.Runtime.Serialization
profile picture

Eugene

#4
Steve,

If something "does not appear" don't ask me, instead do some Google-fu. This is how answers are found.

At the very least you have to check System.Web and System.Core (for LINQ) in References, and refer to these DLLs on the other tab from the directory I pointed at above:

Microsoft.CSharp.dll
System.Runtime.Serialization.dll
System.Web.Extensions.dll

Microsoft scattered those namespaces across assemblies this way, so your job is to google the correct DLL in MSDN - it's thoroughly documented (or on StackOverflow - this usually is the shortcut).
profile picture

sedelstein

#5
Thanks Eugene
Believe me, I've spent considerable amount of time googling. It's not for lack of effort that's at issue.
Will keep plugging away.
profile picture

Eugene

#6
Steve, here's a quick and dirty demo for you.

1. Check System.Web and System.Core (for LINQ) in References
2. Add references to these DLLs on the other tab from the directory I pointed at above:

Microsoft.CSharp.dll
System.Runtime.Serialization.dll
System.Web.Extensions.dll

CODE:
Please log in to see this code.


Obviously you'll want to add some error handling and some sort of anonymous type to get more properties than the "regularMarketPrice".
profile picture

sedelstein

#7
Thank you Eugene.

I greatly appreciate your help and as I said, I do spend a lot of time researching before coming here and asking. I'm generally reluctant to waste others people's time. I do hope other WL users will find this handy.
profile picture

Eugene

#8
Glad to help you Steve.
profile picture

sedelstein

#9
Thanks again for the help. When using just a ticker e.g. QQQ rather than a specific option ticker e.g. QQQ171215C00156000 you can grab the whole chain of series of option for each expiration date. Your code gave me enough of a head start to put a serious dent in my project.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).