你好,我试图从雅虎财经API获得外国的Currey Pairs价值, 我已经咨询过以下答案 FinanceAPI
我选择了雅虎财务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软件对价值进行了比较,我发现雅虎数据和MT4数据有很多差异,而且我也想要这个价格, ask和bib对象是五位小数,目前值为1.2584
我希望它像1.25849
现在我遇到了两个大问题请建议我如何实现我的目标,即使用YAHOO API获得五个小数值和更大的差异,或者我是否需要使用其他人?因为其他人的主要问题是每月或每天有限的点击量。
请建议并帮助我。
提前致谢;)