Has yahoo stopped their history data api service?

Discussion in 'Automated Trading' started by kiev, Apr 18, 2017.

  1. kiev

    kiev

    I used to download yahoo history data everyday with my program until this week. My code is as follows,

    URL queryStockUrl = new URL(stockQueryURL);
    HttpURLConnection connection = (HttpURLConnection) queryStockUrl
    .openConnection();
    connection.connect();
    BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));

    Now the reader can get nothing, no error, no exception thrown. If I enter the same stockQueryURL as above into chrome, I can download the history data file in chrome, but my program can't.

    I guess yahoo has stopped the api service, if server finds your history data request is not from a web browser, it will offer you nothing.

    Any ideas?
     
  2. nemo4242

    nemo4242

    You could try it with other programs that use the Yahoo history db. E.g. there are R and Pandas package that do that.
    If you're suspicious that they block non-browser access, try changing the user agent.
    You seem to use Java, so e.g.:
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");

    or something like that. You can use e.g. http://www.whoishostingthis.com/tools/user-agent/ to find the User-Agent chrome uses on your computer.
    Hope that helps.
     
  3. hal1954

    hal1954

    Hi,
    Yahoo has changed the protocol to https.
    connection.getResponseCode(); will return 301.
    Change http to https in your URL and it works.
    You should always check the HTTP Response Code.
     
    ET180 and Simples like this.
  4. kiev

    kiev

    I post the same question on yahoo community today, and someone there told me he met the same problem, I will try to change the http request according to your code.

    Thanks
     
  5. kiev

    kiev

    It does work, very helpful, thanks a lot
     
  6. ET180

    ET180

  7. Yes. I believe Yahoo finance API is not available anymore. I have moved to MarketXLS after this change, much more reliable data.