Tuesday, March 31, 2009

Get Stock Quotes from Yahoo

My previous two posts alluded to this project. This file contains a Visual Studio 2008 solution. It is a class library written in vb.NET. You can use it to get basic stock quote information from Yahoo finance. It is working as of March 31, 2009. When Yahoo changes their format, the code may have to be modified to adapt.

The goal of this project was not stock quotes. Instead, I was learning, and practicing in these topics:

A general provider pattern
A provider factory pattern
Using linq and reflection
Benefits of using interfaces
Microsoft.VisualBasic.FileIO.TextFieldParser
HttpWebRequest , HttpWebRequest

If you would like to add a new stock quote provider, add a class in the Providers folder and have it implement the IStockQuoteProvider interface. That is all you have to do; but you could also add unit tests for your new provider. Note that the existing providers are implemented as “Friend.” This enforces callers who reference the assembly to create instances of providers by using the StockQuoteProviderFactory.

Thanks to Ryan Cromwell for pairing with me and providing the starting template. I’m sure this code can be improved. If you see opportunities to make it better please let me know.

Ryan Cromwell's blog

No comments: