Click here to Skip to main content
Click here to Skip to main content

StockBag

By , 19 Jan 2008
 

Introduction

StockBag is a desktop utility wherein you can define your stock portfolio/watch-list and view live stock data.

Background

I was trying, for some time, to access live stock market data through a desktop utility, and found that we need to pay for getting live stock data. Then, I found that Yahoo! Finance gives a 15 minutes delayed data through its CSV service. Then, I thought of writing my own little gadget to have a portfolio and watch list. Currently, StockBag can be used to get live stock data from the Indian stock market. However, it can be modified to get live stock data from any stock market over the world which Yahoo! Finance supports.

Using the code

Most of the action happens in the StockBagMainForm class. There are two timers, one for getting live stock data from Yahoo! Finance and the other for refreshing the list. The live stock data timer creates a thread which will access Yahoo! Finance to get a CSV format string with live data.

The key method is GetStockData(), which is used to get stock data.

private void GetStockData(string stockCode, StockData stockData)
{
    string serverUrl = @"http://in.finance.yahoo.com/d/quotes.csv?s="+stockCode+
            "&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUrl);

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    StreamReader reader = new StreamReader(response.GetResponseStream(), 
        Encoding.ASCII);

    string stockDataString = reader.ReadLine();
    string[] stockDataContents = stockDataString.Split(',');

    stockData.Code = stockCode;
    stockData.Last = stockDataContents[1];
    stockData.Date = stockDataContents[2];
    stockData.Time = stockDataContents[3];
    stockData.Change = stockDataContents[4];
    stockData.Open = stockDataContents[5];
    stockData.High = stockDataContents[6];
    stockData.Low = stockDataContents[7];
    stockData.Volume = stockDataContents[8];
    stockData.MarketCapital = stockDataContents[9];
    stockData.PreviousClose = stockDataContents[10];
    stockData.PctChange = stockDataContents[11];
    stockData.AnnRange = stockDataContents[12];
    stockData.Earnings = stockDataContents[13];
    stockData.PERatio = stockDataContents[14];

    response.Close();
}

The tool uses the HttpWebRequest and HttpWebResponse .NET classes, which, by default, use the IE proxy settings. If you don't have IE installed, and proxy is configured via some other browser, this tool might not work. Also, if you have a firewall installed, you need to give access to StockBag to access the Web. If Yahoo! finance is blocked by your firewall, then this tool will not work.

Points of interest

Getting live stock data will be of interest to many to write analysis tools on their own. However, it should be noted that at least for NSE/BSE (Indian stock markets), Yahoo! Finance is giving 15 minutes delayed data.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Prashanth Uppunda
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow do i retrieve Gold rates?memberJαved20 Feb '12 - 21:14 
Generalproblem while getting live quotesmemberhardik28200622 Aug '09 - 21:18 
Generalsaving data in csv formemberanilk526 Jun '09 - 7:16 
Questionpls suggest me the code to retrive stock data directly from "nseindia" website?memberarun p r20 Mar '09 - 20:26 
QuestionGood ProjectmemberDoncp27 Feb '09 - 9:18 
GeneralStick to desktopmemberSiavash Mortazavi12 Dec '08 - 6:28 
GeneralSimilar gadgetmembermichbex16 Apr '08 - 5:57 
GeneralRe: Similar gadgetmemberRavi Bhavnani6 Apr '08 - 6:36 
GeneralRe: Similar gadgetmembermichbex16 Apr '08 - 6:51 
GeneralNice articlememberAKNR Chandra Sekhar26 Jan '08 - 10:45 
GeneralI have already build one with actual live data...memberAshutosh Bhawasinka19 Jan '08 - 20:42 
GeneralRe: I have already build one with actual live data...memberAshutosh Bhawasinka19 Jan '08 - 20:45 
GeneralRe: I have already build one with actual live data...memberdharam20 Jan '08 - 17:12 
GeneralRe: I have already build one with actual live data...memberSeetharam22 Jan '08 - 12:13 
GeneralRe: I have already build one with actual live data...memberdharam24 Jan '08 - 4:44 
GeneralRe: I have already build one with actual live data...memberAshutosh Bhawasinka3 Sep '08 - 8:07 
GeneralRe: I have already build one with actual live data...memberAshutosh Bhawasinka3 Sep '08 - 8:08 
GeneralRe: I have already build one with actual live data...memberAshutosh Bhawasinka3 Sep '08 - 8:09 
NewsRe: I have already build one with actual live data...memberme_ramkumar17 Feb '08 - 7:19 
GeneralRe: I have already build one with actual live data...memberAajaraja20 Feb '08 - 8:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 19 Jan 2008
Article Copyright 2008 by Prashanth Uppunda
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid