简体   繁体   中英

Using Yahoo finance

I have a list of 1000 stocks of wich i am trying to get the price from yahoo finance. How ever the program seems to skip some stocks and does not fill it in. The code i am using is

     void display(String symbol) throws IOException
       {

                    URL yahoofin = new URL("http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=l1kjm3m4r"); 
                    URLConnection yc = yahoofin.openConnection(); 

        BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); 
        String inputLine; 

        while ((inputLine = in.readLine()) != null) 
        { 

            System.out.println("ing= "+ing+" "+inputLine);
            info[ing]=inputLine;


        } 
        System.out.println("ing = "+ing);

        in.close(); 
    /* 
    catch (Exception ex) 
    { 
       // log.error("Unable to get stockinfo for: " + symbol + ex); 
    } 
     */
 } 

I keep passing new symbols from another function ten at a time. BUt ing prints 7 sometimes.(that means stocks are skipped). Where am i going wrong.

You might want to add a delay between your calls. Sometime Yahoo does not accept very high frequency requests and turns down some of them.

You can pass more than one symbol per request (I think up to 50) seperated by "+". This should imensely decrease the number of your requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM