YahooFinance.get returns stock which is null

788 views Asked by At

I try to get some stock prices.

I tried to use the YahooFinance API, but it doesn't work like in the tutorial. My Source is like this :

Stock stock = YahooFinance.get("GOOG");
        if(stock == null)
            System.out.println("stock is null");
        BigDecimal price = stock.getQuote().getPrice();
        BigDecimal change = stock.getQuote().getChangeInPercent();
        BigDecimal peg = stock.getStats().getPeg();
        BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();
        stock.print();

Some ideas why YahooFinance.get returns null and not a valid stock object? If somebody knows a better API or solution, i'm interested in it.

1

There are 1 answers

0
akhil_mittal On

The code is correct but in some cases it ends up throwing null value for result.

I faced the similar problem. IMO, there is some issue with the API itself. And for some reason directly accessing the stock name won't work, so we need to put the name of stock in a string and use that string. Let me know if it works for you.

I believe there is similar API by google as well though I have not tried it myself.