嗨,我正在尝试从 Yahoo Finance API 获取外国的 Currey Pairs Values,我已经咨询了以下答案 FinanceAPI
我选择了 yahoo Finance api,我创建了一个sailsjs 项目并使用请求模块来获取当前货币对值,我获取当前货币对值的函数是
/*TradeService.js*/
var request = require('request')
module.exports = {
getPairValService: function(req, res, pair, callbacl) {
getPairVal(pair, function(err, data) {
if (data) {
callbacl(null, data);
}
})
}
};
function getPairVal(pair, pairValue) {
var yahoodefaultapisquery = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("EURUSD", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&format=json&env=store://datatables.org/alltableswithkeys';
var yahoocustomapisquery = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("' + pair + '")&format=json&env=store://datatables.org/alltableswithkeys'
var yahooapisquery = pair == '' ? yahoodefaultapisquery : yahoocustomapisquery;
request(yahooapisquery, function(error, response, body) {
if (error && response.statusCode != 200) {
sails.log.error(error) // Show the HTML for the Google homepage.
pairValue(error, null);
} else if (!error && response.statusCode == 200) {
sails.log.info(body);
pairValue(null, body);
}
})
}
我从雅虎财经收到的回复类似于
"query": {
"count": 2,
"created": "2015-07-20T11:24:14Z",
"lang": "en-US",
"diagnostics": {
"url": [{
"execution-start-time": "1",
"execution-stop-time": "3",
"execution-time": "2",
"content": "http://www.datatables.org/yahoo/finance/yahoo.finance.xchange.xml"
}, {
"execution-start-time": "12",
"execution-stop-time": "15",
"execution-time": "3",
"content": "http://download.finance.yahoo.com/d/quotes.csv?s=USDMXN=X&f=snl1d1t1ab"
}, {
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "http://download.finance.yahoo.com/d/quotes.csv?s=USDCHF=X&f=snl1d1t1ab"
}],
"publiclyCallable": "true",
"cache": [{
"execution-start-time": "10",
"execution-stop-time": "11",
"execution-time": "1",
"method": "GET",
"type": "MEMCACHED",
"content": "8bb0e407e3bb00d83b039c07d63130d0"
}, {
"execution-start-time": "11",
"execution-stop-time": "12",
"execution-time": "1",
"method": "GET",
"type": "MEMCACHED",
"content": "d69f38521719d58f343c9657edf0ad59"
}],
"query": [{
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=USDCHF=X&f=snl1d1t1ab' and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'"
}, {
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=USDMXN=X&f=snl1d1t1ab' and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'"
}],
"javascript": [{
"execution-start-time": "10",
"execution-stop-time": "17",
"execution-time": "6",
"instructions-used": "37334",
"table-name": "yahoo.finance.xchange"
}, {
"execution-start-time": "10",
"execution-stop-time": "17",
"execution-time": "7",
"instructions-used": "37334",
"table-name": "yahoo.finance.xchange"
}],
"user-time": "18",
"service-time": "11",
"build-version": "0.2.154"
},
"results": {
"rate": [{
"id": "USDMXN",
"Name": "USD/MXN",
"Rate": "15.9260",
"Date": "7/20/2015",
"Time": "12:24pm",
"Ask": "15.9270",
"Bid": "15.9260"
}, {
"id": "USDCHF",
"Name": "USD/CHF",
"Rate": "0.9626",
"Date": "7/20/2015",
"Time": "12:24pm",
"Ask": "0.9628",
"Bid": "0.9626"
}]
}
}
}
现在我已经比较了不同经纪商的 MT4 软件的配对值,我发现 yahoo 数据和 MT4 数据有很大差异,而且我希望汇率、询问和围兜对象为 5小数现在的值是1.2584
我希望它像1.25849
现在我有两个大问题请建议我如何使用YAHOO API实现获得五个十进制值和更大差异的目标,还是我需要使用其他一些?因为其他人的主要问题是每月或每天的点击次数有限。
请建议并帮助我。
提前致谢 ;)