Monthly Archives: April 2009

MarketClose Twitterobot – Step 1: Yahoo!

So, I am a recovering stockoholic. I’ve been out of the markets for about 2 years now, but I am still facsinated by their daily fluctuations. I found myself hovering over the address bar and habitually typing to find out what was happening. But that only satiated my fix when I was firefox. So, I added the keyword “stocks” to slickrun so I could quickly open up from anywhere. Bah – too many keystrokes – I used winkey to assign it to Win+C.  But what to do before 10am? I started checking the future markets before getting to work.

It was too much – I had to go cold turkey! I changed Win+C back to being a command prompt, and re-aliased stocks to take me to proggit. I decided that instead, I would write a simple C# program to send me the stock price at the end of the day. I’ve been meaning to play around with the Twitter API for a while now, so it finally gave me an excuse.

However, before the fun started, I first had to get the data.

Step 1 – Yahoo!

Yahoo have a nice little rest based CSV generation system for stock quotes. Basically, all you need to do is request urls in the following format:

The s query string parameter defines the tickers you want to retrieve (separated by spaces) and the f defines what fields you want back – you can find a listing of all those commands here.

So, for my needs, I just needed to request:^IXIC+^DJI+^GSPC&f=sl1o

Fortunately, .net makes rest request a piece of cake:

using (WebClient wc = new WebClient())
return wc.DownloadString(@”^IXIC+^DJI+^GSPC&f=sl1o”);

So all that was left to do was to write something to quickly parse the csv (unit tests are your friend for things like this) and to move some things out to config files (such as the url)

Next Step – Twitter!