0

I have a JAVA program that i have been using for the last year to downlaod data from yahoo finance. A few days ago it stopped working and yahoo started to refuse the connection.

java.net.ConnectException: Connection refused: connect

Has anyone else experienced this?

import java.net.URL;
import java.net.URLConnection;
import java.util.Calendar;
import java.util.Scanner;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;

public class C_GetStocksFromYahoo {
    public Scanner input;

    public void GetStocks(String symbol, GregorianCalendar start, GregorianCalendar end) {  
        String url = "http://real-chart.finance.yahoo.com/table.csv?s="
            + symbol
            + "&a=" + start.get(Calendar.MONTH)
            + "&b=" + start.get(Calendar.DAY_OF_MONTH)
            + "&c=" + start.get(Calendar.YEAR)
            + "&d=" + end.get(Calendar.MONTH)
            + "&e=" +end.get(Calendar.DAY_OF_MONTH)
            + "&f=" + end.get(Calendar.YEAR)
            + "&g=d&ignore=.csv"; //g=d means daily stock quotes

        try {
            URL yhoofin=new URL(url);//Create New URL data
            URLConnection data=yhoofin.openConnection();//Open a connection
            input = new Scanner(data.getInputStream());//get data from input stream 
            //System.out.println("This is the scanner " + input);
            //System.out.println("This is the first line " + this.nextline());
            //System.out.println("This is the first line " + this.nextline());
        } catch (Exception e) {
            System.out.println("This is the symbol i failed on " + symbol);
            System.err.println(e);
        }
    }

    //scanner value
    public Scanner getScan() {
        return input;
    }

    //determine if file has next entry
    public boolean hasnext() {
        return input.hasNext();
    }

    //contains next line
    public String nextline() {
        return input.nextLine();
    }

    public void closeConnection() {
        input.close();
    }
}
Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
stormer1120
  • 97
  • 1
  • 5
  • 1
    Does it work inside a browser ? – Arnaud May 18 '17 at 13:10
  • Sorry not a very experienced programmer. I have been running this as a JAVA application. How do you run it inside a browser? – stormer1120 May 18 '17 at 13:14
  • Just copy-paste the content of your `url` `String` to the adress bar of your browser, and see if you get the result page (I just tried to paste "http://real-chart.finance.yahoo.com/table.csv", it gave error 404 / host unreachable) . – Arnaud May 18 '17 at 13:16
  • I tried and it does not work. it appears they changed the address to something very difficult to read. Thank you for the help. – stormer1120 May 23 '17 at 11:06

1 Answers1

0

Unfortunately Yahoo discontinued their API for historical data, therefor your URL http://real-chart.finance.yahoo.com/table.csv? won't get you any data back anymore.

On https://forums.yahoo.net/t5/Yahoo-Finance-help/Is-Yahoo-Finance-API-broken/td-p/250503/page/3 Nixon (Official 'Hoo Staff) said:

Hi All - This feature was discontinued by the Finance team and they will not be reintroducing that functionality.

Taken from: Yahoo Finance URL not working

Community
  • 1
  • 1
jrn
  • 2,640
  • 4
  • 29
  • 51