1

こんにちは、Yahoo Finance API から外国の Currey Pairs Values を取得しようとしています。次の回答 FinanceAPIを参照しました。

yahoo ファイナンス 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);
        }
    })
}

Yahoo Finance から受け取った応答は次のようなものです

"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 の数値に多くの違いがあることがわかりました。また、rate、ask、bib オブジェクトを 5 にしたい現在のような小数の値は、次の1.2584ようになりたい1.25849

2 つの大きな問題があるので、YAHOO API を使用して 5 つの 10 進値とより大きな差を取得するという目標を達成する方法を教えてください。または、他のものを使用する必要がありますか? 他のユーザーの主な問題は、1 か月または 1 日あたりのヒット数が限られていることです。

提案して助けてください。

前もって感謝します ;)

4

0 に答える 0