1

Hi i'm trying to get Currey Pairs Values of foreign from the Yahoo Finance API , I've consulted the following answer FinanceAPI

and i've choosed the yahoo finance api, I've created a sailsjs project and have used request module to get the Current pair value, my function to get get current currency pair value is

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

and the response i receive from Yahoo Finance is something like

"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"
        }]
    }
}

}

Now that I've compare the pair values with MT4 software of different brokers I've came to see there is a lot of difference in yahoo figures and the MT4 figures of, and also i want the rate, ask and bib object to be five decimals like currently the value is 1.2584 i want it to be like 1.25849

Now that I've two big problems with it Please suggest how can i achieve my objectives of getting five decimal values and bigger difference using YAHOO API or do i need to use some one else ? because the major problem with others are limited hits per month or day.

Please Suggest and help me out.

Thanks in advance ;)

Community
  • 1
  • 1
Ahsan Hussain
  • 952
  • 4
  • 21
  • 42
  • Considering it updates per second, I wouldn't be surprised if the exchange rates given could be off by `.00001` per request. Considering it doesn't seem they provide any additional info through their API, you're probably gonna have to go with someone else. You have to admit it's pretty good for being free. – Alyssa Haroldsen Jul 27 '15 at 21:33
  • can i get the value in 5 decimals like `1.25252` ? @Kupiakos – Ahsan Hussain Jul 27 '15 at 21:40

0 Answers0