所以我一直在使用sailsjs从外部网站请求json数据,然后将这些数据发布到创建路由.当我第一次运行它时,它将工作大约10-12次,然后应用程序将崩溃与event.js抛出;连接ETIMEDOUT 寻找从https://c
寻找从https://cex.io/api/ticker/GHS/BTC请求json数据的更好方法.
所以我正在使用sailsjs并在文件config / bootstrap.js中添加了我的服务来运行.
module.exports.bootstrap = function (cb) {
// My
tickerService.ticker();
// Runs the app
cb();
};
这是我的尝试之一~file api / services / tickerservice.js
function storeTicker(){
console.log('Running!');
//retrieves info from https://cex.io/api/ticker/GHS/BTC
require("cexapi").ticker('GHS/BTC', function(param){
console.log(param);
Tickerchart.create( param, function tickerchartCreated (err, tickerchart) {});
});
}
module.exports.ticker = function(){
setInterval(storeTicker, 6000);
};
Cex.io Library Github
https://github.com/matveyco/cex.io-api-node.js/blob/master/cexapi.js
function storeTickerchart(){
//console.log('Running!');
var request = require("request");
var url = "https://cex.io/api/ticker/GHS/BTC";
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
//console.log(body); //Print the json response
Tickerchart.create(body, function tickerchartCreated (error, tickerchart) {
if(error) console.log("Oops Error");
});
}
});
}
module.exports.ticker = function(){
setInterval(storeTickerchart, 5000);
};
