Matthew Cassar Matthew Cassar - 7 months ago 15
Java Question

financequotes API returning null values

I have downloaded an API called "financequotes" for Java (Link: http://financequotes-api.com/) and have attempted to use it for a project. It has been imported into my class path and all the methods run, however when I ask for a stocks details

Stock s = new Stock("INTC");
s.print();


I am given back all the details which should have been obtained online as null including name, currency, quote, etc.

Why is this?

ALTERNATIVELY - Could you suggest another finance API which is relatively simple to use to gather basic financial data?

Thanks

Answer

The creator of the API has answered - Here was the problem

The code doesn't have a request to Yahoo Finance yet. There's 2 alternative ways to fix this.

  1. Request it through the YahooFinance static methods

    Stock stock = YahooFinance.get("INTC");
    stock.print();
    
  2. Force a refresh of the stock's quote by using the getQuote(boolean refresh) method

    Stock stock = new Stock("INTC");
    stock.getQuote(true);
    stock.print();
    

This will automatically also load/refresh the statistics and dividend data.