C# code to get live updates from NSE:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Web;
using Newtonsoft.Json.Linq; //download Newtonsoft dll from web
using Newtonsoft.Json;
namespace Check
{
class Program
{
static void Main(string[] args)
{
//IDFCBANK
string[] item = {"ICICIBANK","HDFCBANK"};
foreach(string str in item )
{
string url = "http://finance.google.com/finance/info?client=ig&q=NSE:" + str;
string output = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
try
{
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
output = reader.ReadToEnd();
write(output);
}
}
catch (WebException ex)
{
Console.WriteLine("Item invalid : " + str);
}
}
Console.ReadKey();
}
static void write(string res)
{
try
{
if (res.Length > 0)
{
res = res.Replace("[", "").Replace("]", "");
JObject rss = JObject.Parse(res);
string Title = (string)rss["t"];
string Time = (string)rss["ltt"];
string Charge = (string)rss["l"];
string Change = (string)rss["c"];
// James Newton-King
Console.WriteLine(Title.Substring(0,3) + " " + Time + " " + Charge + " " + Change);
}
}
catch (Exception ex)
{
}
}
}
}