0

我对 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,以便以后可以在任何我想引用的地方引用它吗?

4

1 回答 1

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
  });
});
于 2013-11-05T03:49:35.030 回答