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.
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
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");
}
}
}
}
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