股票市场API Node.JS

我对Node.JS有点新鲜,想了解如何利用另一个人的API提供的信息。 例如。

下面是我想要使用的API http://live-nse.herokuapp.com/?symbol=AMAR 可以在https://github.com/ashwanthkumar/Live-NSE-Stockfind源代码。

我真的很感兴趣,我可以如何使用这些信息,例如,如果你使用该链接来获取符号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,所以我可以引用它,无论我以后想?

你可以像这样创build一个请求:

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