public class YahooFinance
extends java.lang.Object
When trying to get information on multiple stocks at once, please use the provided
methods that accept a String[] of symbols to get the best performance.
To retrieve the basic quote, statistics and dividend data, a single request can be sent to
Yahoo Finance for multiple stocks at once.
For the historical data however, a separate request has to be sent to Yahoo Finance
for each of the requested stocks. The provided methods will retrieve
all of the required information in the least amount of
requests possible towards Yahoo Finance.
You can change the default timeout of 10s for requests to Yahoo Finance by setting the yahoofinance.connection.timeout system property.
Please be aware that the data received from Yahoo Finance is not always complete for every single stock. Stocks on the American stock exchanges usually have a lot more data available than stocks on other exchanges.
This API can also be used to send requests for retrieving FX rates.
Since the data is provided by Yahoo, please check their Terms of Service at https://info.yahoo.com/legal/us/yahoo/
| Modifier and Type | Field and Description |
|---|---|
static int |
CONNECTION_TIMEOUT |
static java.lang.String |
HISTQUOTES_BASE_URL |
static java.util.logging.Logger |
logger |
static java.lang.String |
QUOTES_BASE_URL |
static java.lang.String |
QUOTES_CSV_DELIMITER |
static java.lang.String |
TIMEZONE |
| Constructor and Description |
|---|
YahooFinance() |
| Modifier and Type | Method and Description |
|---|---|
static Stock |
get(java.lang.String symbol)
Sends a basic quotes request to Yahoo Finance.
|
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols)
Sends a basic quotes request to Yahoo Finance.
|
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols,
boolean includeHistorical)
Same as the
get(String[]) method, but with the option to include
historical stock quote data. |
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols,
java.util.Calendar from)
Sends a request for multiple stocks with the historical quotes included
starting from the specified
Calendar date until today,
at the default interval (monthly). |
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols,
java.util.Calendar from,
java.util.Calendar to)
Sends a request for multiple stocks with the historical quotes included
starting from the specified
Calendar date
until the specified Calendar date (to)
at the default interval (monthly). |
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols,
java.util.Calendar from,
java.util.Calendar to,
Interval interval)
Sends a request for multiple stocks with the historical quotes included
starting from the specified
Calendar date
until the specified Calendar date (to)
at the specified interval. |
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols,
java.util.Calendar from,
Interval interval)
Sends a request for multiple stocks with the historical quotes included
starting from the specified
Calendar date until today,
at the specified interval. |
static java.util.Map<java.lang.String,Stock> |
get(java.lang.String[] symbols,
Interval interval)
Sends a request for multiple stocks with the historical quotes included
from the past year,
at the specified interval.
|
static Stock |
get(java.lang.String symbol,
boolean includeHistorical)
Same as the
get(String) method, but with the option to include
historical stock quote data. |
static Stock |
get(java.lang.String symbol,
java.util.Calendar from)
Sends a request with the historical quotes included
starting from the specified
Calendar date
at the default interval (monthly). |
static Stock |
get(java.lang.String symbol,
java.util.Calendar from,
java.util.Calendar to)
Sends a request with the historical quotes included
starting from the specified
Calendar date
until the specified Calendar date (to)
at the default interval (monthly). |
static Stock |
get(java.lang.String symbol,
java.util.Calendar from,
java.util.Calendar to,
Interval interval)
Sends a request with the historical quotes included
starting from the specified
Calendar date
until the specified Calendar date (to)
at the specified interval. |
static Stock |
get(java.lang.String symbol,
java.util.Calendar from,
Interval interval)
Sends a request with the historical quotes included
starting from the specified
Calendar date
at the specified interval. |
static Stock |
get(java.lang.String symbol,
Interval interval)
Sends a request with the historical quotes included
at the specified interval (DAILY, WEEKLY, MONTHLY).
|
static FxQuote |
getFx(java.lang.String symbol)
Sends a request for a single FX rate.
|
static java.util.Map<java.lang.String,FxQuote> |
getFx(java.lang.String[] symbols)
Sends a single request to Yahoo Finance to retrieve a quote
for all the requested FX symbols.
|
public static final java.lang.String QUOTES_BASE_URL
public static final java.lang.String HISTQUOTES_BASE_URL
public static final java.lang.String QUOTES_CSV_DELIMITER
public static final java.lang.String TIMEZONE
public static final int CONNECTION_TIMEOUT
public static final java.util.logging.Logger logger
public static Stock get(java.lang.String symbol) throws java.io.IOException
Stock object
with its StockQuote, StockStats
and StockDividend member fields
filled in with the available data.
Returns null if the data can't be retrieved from Yahoo Finance.symbol - the symbol of the stock for which you want to retrieve informationStock object containing the requested informationjava.io.IOException - when there's a connection problempublic static Stock get(java.lang.String symbol, boolean includeHistorical) throws java.io.IOException
get(String) method, but with the option to include
historical stock quote data. Including historical data will cause the Stock
object's member field HistoricalQuote to be filled in
with the default past year term at monthly intervals.
Returns null if the data can't be retrieved from Yahoo Finance.symbol - the symbol of the stock for which you want to retrieve informationincludeHistorical - indicates if the historical quotes should be included.Stock object containing the requested informationjava.io.IOException - when there's a connection problempublic static Stock get(java.lang.String symbol, Interval interval) throws java.io.IOException
symbol - the symbol of the stock for which you want to retrieve informationinterval - the interval of the included historical dataStock object containing the requested informationjava.io.IOException - when there's a connection problempublic static Stock get(java.lang.String symbol, java.util.Calendar from) throws java.io.IOException
Calendar date
at the default interval (monthly).
Returns null if the data can't be retrieved from Yahoo Finance.symbol - the symbol of the stock for which you want to retrieve informationfrom - start date of the historical dataStock object containing the requested informationjava.io.IOException - when there's a connection problempublic static Stock get(java.lang.String symbol, java.util.Calendar from, Interval interval) throws java.io.IOException
Calendar date
at the specified interval.
Returns null if the data can't be retrieved from Yahoo Finance.symbol - the symbol of the stock for which you want to retrieve informationfrom - start date of the historical datainterval - the interval of the included historical dataStock object containing the requested informationjava.io.IOException - when there's a connection problempublic static Stock get(java.lang.String symbol, java.util.Calendar from, java.util.Calendar to) throws java.io.IOException
Calendar date
until the specified Calendar date (to)
at the default interval (monthly).
Returns null if the data can't be retrieved from Yahoo Finance.symbol - the symbol of the stock for which you want to retrieve informationfrom - start date of the historical datato - end date of the historical dataStock object containing the requested informationjava.io.IOException - when there's a connection problempublic static Stock get(java.lang.String symbol, java.util.Calendar from, java.util.Calendar to, Interval interval) throws java.io.IOException
Calendar date
until the specified Calendar date (to)
at the specified interval.
Returns null if the data can't be retrieved from Yahoo Finance.symbol - the symbol of the stock for which you want to retrieve informationfrom - start date of the historical datato - end date of the historical datainterval - the interval of the included historical dataStock object containing the requested informationjava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols) throws java.io.IOException
Map object
that links the symbols to their respective Stock objects.
The Stock objects have their StockQuote, StockStats
and StockDividend member fields
filled in with the available data.
All the information is retrieved in a single request to Yahoo Finance. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationjava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols, boolean includeHistorical) throws java.io.IOException
get(String[]) method, but with the option to include
historical stock quote data. Including historical data will cause the Stock
objects their member field HistoricalQuote to be filled in
with the default past year term at monthly intervals.
The latest quotes will be retrieved in a single request to Yahoo Finance. For the historical quotes (if includeHistorical), a separate request will be sent for each requested stock. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationincludeHistorical - indicates if the historical quotes should be includedjava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols, Interval interval) throws java.io.IOException
The latest quotes will be retrieved in a single request to Yahoo Finance. For the historical quotes, a separate request will be sent for each requested stock. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationinterval - the interval of the included historical datajava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols, java.util.Calendar from) throws java.io.IOException
Calendar date until today,
at the default interval (monthly).
The latest quotes will be retrieved in a single request to Yahoo Finance. For the historical quotes, a separate request will be sent for each requested stock. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationfrom - start date of the historical datajava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols, java.util.Calendar from, Interval interval) throws java.io.IOException
Calendar date until today,
at the specified interval.
The latest quotes will be retrieved in a single request to Yahoo Finance. For the historical quotes, a separate request will be sent for each requested stock. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationfrom - start date of the historical datainterval - the interval of the included historical datajava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols, java.util.Calendar from, java.util.Calendar to) throws java.io.IOException
Calendar date
until the specified Calendar date (to)
at the default interval (monthly).
The latest quotes will be retrieved in a single request to Yahoo Finance. For the historical quotes, a separate request will be sent for each requested stock. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationfrom - start date of the historical datato - end date of the historical datajava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,Stock> get(java.lang.String[] symbols, java.util.Calendar from, java.util.Calendar to, Interval interval) throws java.io.IOException
Calendar date
until the specified Calendar date (to)
at the specified interval.
The latest quotes will be retrieved in a single request to Yahoo Finance. For the historical quotes, a separate request will be sent for each requested stock. The returned Map only includes the Stocks that could successfully be retrieved from Yahoo Finance.
symbols - the symbols of the stocks for which you want to retrieve informationfrom - start date of the historical datato - end date of the historical datainterval - the interval of the included historical datajava.io.IOException - when there's a connection problempublic static FxQuote getFx(java.lang.String symbol) throws java.io.IOException
FxSymbols
Some examples of accepted symbols:
symbol - symbol for the FX rate you want to requestjava.io.IOException - when there's a connection problempublic static java.util.Map<java.lang.String,FxQuote> getFx(java.lang.String[] symbols) throws java.io.IOException
getFx(String) for more information on the
accepted FX symbols.symbols - an array of FX symbolsjava.io.IOException - when there's a connection problem or the request is incorrectgetFx(java.lang.String)