Get stock quotes of NSE and BSE using web-service and parse it using json [closed]

試著忘記壹切 提交于 2019-12-03 10:14:58

If you want to fetch the data from NSE web service, then below is the link:

http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/ajaxGetQuoteJSON.jsp?symbol=dhfl

But I'm not sure whether you can use this link or not for non commercial as well as commercial purpose.

For a free service you can call google finance web services or yahoo finance web services, but both are deprecated but are still working.

http://finance.yahoo.com/webservice/v1/symbols/IDFC.NS/quote?format=json&view=detail

in above URL: IDFC is the symbol of security .NS stands for NSE

For BSE just modify NS to BO

for google web service: NSE: http://finance.google.com/finance/info?client=ig&q=NSE:DHFL

for BSE just modify NSE to BOM

Just copy pate above links in a browser to see json output.

Please go to this GitHub library. It will surely help.

Currently it gives live stock from the official NSE site.

This services will give you a json response, you can parse this JSON to get the appropriate value, by just replacing the symbol with a valid NSE code.

Google provide a free web services for NSC and BOM data.

https://finance.google.com/finance?q=NSE:KELLTONTEC&output=json

For google web service NSE data- https://finance.google.com/finance?q=NSE:KELLTONTEC&output=json

For google web service BSE (BOM) data- https://finance.google.com/finance?q=BSE:KELLTONTEC&output=json

In PHP

$bse = file_get_contents("https://finance.google.com/finance?q=BSE:KELLTONTEC&output=json");
$split_slash= str_replace('//','',$bse );
$split_data = stripslashes(html_entity_decode($split_slash));
$data = json_decode($split_data);
$equity = $data[0]->l;
print_r($data[0]->l);

Its return BSE data

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)
       {
       }
        }

    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!