0

I'm using Node.js for my project and I'm wondering is there any difference between what Yahoo finance sends to the server machine and "regular" machine.

 var http = require('http');
    var link = "http://download.finance.yahoo.com/d/quotes?s=" + fromCurrency + toCurrency + "%3DX&f=l1n";
    http.request(link,
        function (response)
        {
            var str = '';
            response.on('data', function (chunk) {
                str += chunk;});
            response.on('end', function () {
                var rate = parseRate(str);
                console.log(rate);
                callback(sender, convert(howMuch, rate, fromCurrency, toCurrency));
            });
        }).end();

This is my code. When I run this on my laptop, it returns right rates. But the interesting thing is that when I run this on the server, it sends wrong data for some currencies. For example if you try CAD to USD, it will say that 1 cad equals 95.88 USD. Aggrr!

I'm wondering - maybe I've missed something? Can you help?

Jan
  • 184
  • 2
  • 15

1 Answers1

0

I think you are calling the wrong webservice, try:

var link = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20%3D%20%22USDCAD%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="

Test it here: YQL console

bomblike
  • 168
  • 3
  • 12
  • Heh. The same result. Look what I receive in responce {"query":{"count":2,"created":"2016-04-25T13:32:27Z","lang":"en-US","results":{"rate":[{"id":"CAD","Name":"PIMCO Canada Bond Index Exchang","Rate":"95.879","Date":"9/25/2014","Time":"4:00pm","Ask":"N/A","Bid":"N/A"},{"id":"USD=X","Name":"USD/USD","Rate":"1.0000","Date":"1/29/2016","Time":"8:25am","Ask":"1.0000","Bid":"1.0000"}]}}} – Jan Apr 25 '16 at 13:37
  • I mean - when I request the result manually, I receive the right answer. The problem is somewhere else. – Jan Apr 25 '16 at 13:40