Question:
How to get a StockQuote using yahoofinance API?
Answer:
Here is a simple example on how to get a single quote using the Java Finance Quotes API for Yahoo.Finance
Code:
import java.io.IOException; import yahoofinance.Stock; import yahoofinance.YahooFinance; import yahoofinance.quotes.stock.StockQuote; public class YahooStockQuoteAPI { public static void main(String[] args) throws IOException { YahooFinance yahoo = new YahooFinance(); Stock stock = yahoo.get("GOOG"); StockQuote sq = stock.getQuote(); System.out.println("Symbol: " + sq.getSymbol()); System.out.println("Price: " + sq.getPrice()); System.out.println("Date: " + sq.getLastTradeTime().getTime()); } }
Output:
$ java YahooStockQuoteAPI Symbol: GOOG Price: 662.20 Date: Fri Oct 16 16:00:00 EDT 2015