股票市场API Node.JS

时间:2013-11-04 22:34:38

标签: javascript node.js api http

我对Node.JS有些新意,寻找有关如何利用其他人的API提供的信息的一些见解。例如。

继承我想要使用的API http://live-nse.herokuapp.com/?symbol=AMAR 源代码可在https://github.com/ashwanthkumar/Live-NSE-Stock

找到

我真的对如何使用这些信息感兴趣,例如,如果您使用该链接获取符号AMAR的统计信息,它会以JSON响应我相信吗? (如果我错了,请纠正我。)

以下是它给出的示例响应。

{"lastUpdateTime":"03-NOV-2013 19:50:03","tradedDate":"03NOV2013","data":[{"extremeLossMargin":"-","cm_ffm":"15.47","bcStartDate":"19-DEC-12","change":"0.35","buyQuantity3":"200","sellPrice1":"-","buyQuantity4":"181","sellPrice2":"-","priceBand":"5","buyQuantity1":"530","deliveryQuantity":"-","buyQuantity2":"1","cm_adj_low":"6.00","sellPrice5":"-","quantityTraded":"-","buyQuantity5":"1,000","sellPrice3":"-","sellPrice4":"-","open":"7.55","cm_adj_high":"48.20","low52":"6.00","securityVar":"-","marketType":"N","pricebandupper":"8.25","totalTradedValue":"0.11","faceValue":"10.00","ndStartDate":"-","previousClose":"7.55","symbol":"AMAR","varMargin":"100.00","lastPrice":"7.90","pChange":"4.64","adhocMargin":"-","companyName":"Amar Remedies Limited","averagePrice":"7.78","secDate":"-","series":"BE","isinCode":"INE787G01011","indexVar":"-","pricebandlower":"7.55","totalBuyQuantity":"2,113","high52":"48.20","purpose":"ANNUAL GENERAL MEETING","cm_adj_low_dt":"28-JUN-13","closePrice":"7.90","recordDate":"-","cm_adj_high_dt":"08-JAN-13","totalSellQuantity":"-","dayHigh":"7.90","exDate":"17-DEC-12","sellQuantity5":"-","bcEndDate":"26-DEC-12","ndEndDate":"-","sellQuantity2":"-","sellQuantity1":"-","buyPrice1":"7.85","sellQuantity4":"-","buyPrice2":"7.40","sellQuantity3":"-","applicableMargin":"100.00","buyPrice4":"7.30","buyPrice3":"7.35","buyPrice5":"7.25","dayLow":"7.55","deliveryToTradedQuantity":"-","totalTradedVolume":"1,352"}]}

我想知道如何让我的Node.JS应用程序接收这些信息。我可以将其设置为VAR,以便我可以在以后的任何地方引用它吗?

1 个答案:

答案 0 :(得分:2)

您可以创建如下请求:

var http = require('http');

var options = {
  host: 'live-nse.herokuapp.com',
  port: 80,
  path: '/?symbol=AMAR'
};

http.get(options, function(res){
  res.setEncoding('utf8');
  var data="";
  res.on('data', function(chunk){
    data += chunk;
  });
  res.on('end', function(){
  var obj = JSON.parse(data);
  //do whatever with obj
  });
});