Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No definition found for Table yahoo.finance.xchange

Tags:

finance

yahoo

yql

I have a service which uses a Yahoo! Finance table yahoo.finance.xchange. This morning I noticed it has stopped working because suddenly Yahoo! started to return an error saying:

{
    "error": {
    "lang": "en-US",
        "description": "No definition found for Table yahoo.finance.xchange"
    }
}

This is the request URL. Interesting fact: if I try to refresh the query multiple times, sometimes I get back a correct response but this happen very rarely (like 10% of the time). Days before, everything was fine.

Does this mean Yahoo API is down or am I missing something because the API was changed? I would appreciate any help.

like image 473
DolceVita Avatar asked Aug 24 '17 08:08

DolceVita


Video Answer


2 Answers

Since I have the same problem and that it started today too, that others came to post exactly in the same time as well, and that it still works most of the time, the only explanation I can find is that they have some random database errors on their end and we can hope that this will be solved soon. I also have a 20% rate of failures when refreshing the page of the query.

My guess is that they use many servers to handle the requests (let's say 8) and that one of them is empty or doesn't have that table for some reasons so whenever it directs the query to that server, the error is returned.

Temporary solution: Just modify your script to retry 3-4 times. That did it for me because among 5 attempts at least one succeeds.

like image 187
FlorianB Avatar answered Oct 09 '22 18:10

FlorianB


I solve this issue by using quote.yahoo.com instead of the query.yahooapis.com service. Here's my code:

function devise($currency_from,$currency_to,$amount_from){
  $url = "http://quote.yahoo.com/d/quotes.csv?s=" . $currency_from . $currency_to . "=X" . "&f=l1&e=.csv";
  $handle  = fopen($url, "r");
  $exchange_rate = fread($handle, 2000);
  fclose($handle );
  $amount_to = $amount_from  * $exchange_rate;
  return round($amount_to,2);
}

EDIT the above no longer works. At this point, lets just forget about yahoo lol Use this instead

function convertCurrency($from, $to, $amount)    
{
    $url = file_get_contents('https://free.currencyconverterapi.com/api/v5/convert?q=' . $from . '_' . $to . '&compact=ultra');
    $json = json_decode($url, true);
    $rate = implode(" ",$json);
    $total = $rate * $amount;
    $rounded = round($total);
    return $total;
}
like image 32
Patrick Simard Avatar answered Oct 09 '22 18:10

Patrick Simard