javascript - 股票市场 API Node.JS

标签 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,以便我以后可以在任何需要的地方引用它?

最佳答案

您可以像这样创建一个请求:

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

关于javascript - 股票市场 API Node.JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19778590/

相关文章:

node.js - 导出 Typescript 模块 Nodejs 中的所有内容

java - 是否有访问 bugzilla 的 java api?

api - 如何在 Google map 中显示多个位置?

javascript - Redux - 让不可能的状态成为可能

javascript - 使用 javascript 访问函数中的对象

javascript - 如何从主 node.js 脚本运行多个 node.js 脚本?

javascript - NodeJs 等到循环中的所有调用都完成

javascript - 使用来自 react-router 的 <Route/> 时, child 是未定义的

javascript - CosmosDB 资源未定义

python - 如何在 FastAPI 中将查询参数的模式编写为变量