Tool to download months old NSE BhavCopy in one go

#1
hi guys,
I visited this site today itself and found it quite helpful for myself.
I also installed MetaStock tool and wanted to gather some historic data which ofcourse is not always uptodate.
So I quickly wrote a utility to download the set of 3 month old BhavCopies from NSE-India.com. (Thankfully MS quotes till 14-Jun are already available).

Here I'm posting the simple C# Code which will download all the bhavcopies into your C:\NSE folder.
I'm posting the code so you can tweak it according to your requirments.

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] monthList = new string[3] { "JUN", "JUL", "AUG" };
            try
            {                
                Uri uri = new Uri(@"http://www.nse-india.com/content/historical/EQUITIES/2007/");
                Uri tempUri;
                foreach (string month in monthList)
                {
                    WebClient client = new WebClient();
                    FileStream writer;
                    for(int i = 1; i <31; i++)
                    {
                        try
                        {
                            string iStr = (i <= 9) ? "0" + i.ToString() : i.ToString();
                            tempUri = new Uri(uri, month + "/cm" + iStr + month + "2007bhav.csv");
                            Debug.WriteLine("Downloading " + tempUri.ToString());
                            byte[] data = client.DownloadData(tempUri);
                            using (writer = File.Create(@"C:\NSE\cm" + i.ToString() + month + "2007bhav.csv"))
                            {
                                try
                                {
                                    writer.Write(data, 0, data.Length);
                                }
                                finally
                                {
                                    if (writer != null)
                                        writer.Close();
                                }
                            }
                        }
                        catch (WebException ex)
                        {
                            if (ex.Status == WebExceptionStatus.ProtocolError && ex.Message.Contains("404"))
                                Debug.WriteLine("FileNotFound");
                            continue;                            
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed");
            }

        }
    }
}
Also attached is an executable file which upon doubleclicking will download the files to C:\NSE folder.
Note - You will have to create the NSE folder in C drive manually.

I'm also trying to write a CSV converter so that it will be easy to import from Downloader. If I get some time I'll post it in few hours.

For any queries you can contact me at talksandy AT airtelbroadband.in
 

pokrate

Active Member
#3
Install .net 1.0 or higher and it will work fine. Nice utility which solves the major problem. Now we must write a utility to convert CSV file to metastock format.
 
#4
Install .net 1.0 or higher and it will work fine. Nice utility which solves the major problem. Now we must write a utility to convert CSV file to metastock format.
Someone has already wrote a nice tool to do all that stuff. Its a GUI tool that converts file to MetaStock format csv
Link is
http://www.traderji.com/software/5966-eod-download-convert-nse-bse-12.html

Anyway I like command line tool that will do that automatically for me. So if anyone knows about the Downloader's command line option it will be very helpful.
 
#8
Hearty thanks !
I think, I have found the right person who can guide me in using METASTOCK. :)
I hope its not me. :D
I recently started using this myself but I'm feelin comfortable with it. AmiBroker is good too and a lil bit more user friendly.

Gotta go a long way before doing some serious stuff with it.
 

pokrate

Active Member
#9
I hope its not me. :D
I recently started using this myself but I'm feelin comfortable with it. AmiBroker is good too and a lil bit more user friendly.

Gotta go a long way before doing some serious stuff with it.
Hi buddy,
I have got Amibroker now. Kindly help me in managing it.
How to get historical data and how to update data ?
Eagerly awaiting your friendly reply. ;)
 

rajuwaste

Active Member
#10
When I refer NSE bhavcopy there is a mix of EQ and BE series how do you people handle this.For example several entries of same date's data exist in NSE Bhavcopy what should I do to solve this problem.
 

Similar threads