public class YahooFinance extends 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 String |
HISTQUOTES_BASE_URL |
static String |
HISTQUOTES_QUERY2V8_BASE_URL |
static String |
HISTQUOTES2_BASE_URL |
static String |
HISTQUOTES2_COOKIE |
static String |
HISTQUOTES2_COOKIE_AGREE |
static String |
HISTQUOTES2_COOKIE_NAMESPACE |
static String |
HISTQUOTES2_COOKIE_OATH_DONEURL |
static String |
HISTQUOTES2_COOKIE_OATH_HOST |
static String |
HISTQUOTES2_COOKIE_OATH_ORIGIN |
static String |
HISTQUOTES2_COOKIE_OATH_URL |
static String |
HISTQUOTES2_CRUMB |
static String |
HISTQUOTES2_CRUMB_URL |
static String |
HISTQUOTES2_ENABLED |
static String |
HISTQUOTES2_SCRAPE_URL |
static String |
QUOTES_BASE_URL |
static String |
QUOTES_CSV_DELIMITER |
static String |
QUOTES_QUERY1V7_BASE_URL |
static String |
QUOTES_QUERY1V7_ENABLED |
static String |
TIMEZONE |
Constructor and Description |
---|
YahooFinance() |
Modifier and Type | Method and Description |
---|---|
static Stock |
get(String symbol)
Sends a basic quotes request to Yahoo Finance.
|
static Map<String,Stock> |
get(String[] symbols)
Sends a basic quotes request to Yahoo Finance.
|
static Map<String,Stock> |
get(String[] symbols,
boolean includeHistorical)
Same as the
get(String[]) method, but with the option to include
historical stock quote data. |
static Map<String,Stock> |
get(String[] symbols,
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 Map<String,Stock> |
get(String[] symbols,
Calendar from,
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 Map<String,Stock> |
get(String[] symbols,
Calendar from,
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 Map<String,Stock> |
get(String[] symbols,
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 Map<String,Stock> |
get(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(String symbol,
boolean includeHistorical)
Same as the
get(String) method, but with the option to include
historical stock quote data. |
static Stock |
get(String symbol,
Calendar from)
Sends a request with the historical quotes included
starting from the specified
Calendar date
at the default interval (monthly). |
static Stock |
get(String symbol,
Calendar from,
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(String symbol,
Calendar from,
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(String symbol,
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(String symbol,
Interval interval)
Sends a request with the historical quotes included
at the specified interval (DAILY, WEEKLY, MONTHLY).
|
static FxQuote |
getFx(String symbol)
Sends a request for a single FX rate.
|
static Map<String,FxQuote> |
getFx(String[] symbols)
Sends a single request to Yahoo Finance to retrieve a quote
for all the requested FX symbols.
|
public static final String QUOTES_BASE_URL
public static final String QUOTES_QUERY1V7_BASE_URL
public static final String QUOTES_QUERY1V7_ENABLED
public static final String HISTQUOTES_BASE_URL
public static final String HISTQUOTES2_ENABLED
public static final String HISTQUOTES2_BASE_URL
public static final String HISTQUOTES_QUERY2V8_BASE_URL
public static final String HISTQUOTES2_SCRAPE_URL
public static final String HISTQUOTES2_CRUMB_URL
public static final String HISTQUOTES2_CRUMB
public static final String HISTQUOTES2_COOKIE
public static final String HISTQUOTES2_COOKIE_NAMESPACE
public static final String HISTQUOTES2_COOKIE_AGREE
public static final String HISTQUOTES2_COOKIE_OATH_URL
public static final String HISTQUOTES2_COOKIE_OATH_HOST
public static final String HISTQUOTES2_COOKIE_OATH_ORIGIN
public static final String HISTQUOTES2_COOKIE_OATH_DONEURL
public static final String QUOTES_CSV_DELIMITER
public static final String TIMEZONE
public static final int CONNECTION_TIMEOUT
public static Stock get(String symbol) throws 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 informationIOException
- when there's a connection problempublic static Stock get(String symbol, boolean includeHistorical) throws 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 informationIOException
- when there's a connection problempublic static Stock get(String symbol, Interval interval) throws 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 informationIOException
- when there's a connection problempublic static Stock get(String symbol, Calendar from) throws 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 informationIOException
- when there's a connection problempublic static Stock get(String symbol, Calendar from, Interval interval) throws 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 informationIOException
- when there's a connection problempublic static Stock get(String symbol, Calendar from, Calendar to) throws 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 informationIOException
- when there's a connection problempublic static Stock get(String symbol, Calendar from, Calendar to, Interval interval) throws 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 informationIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols) throws 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 informationIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols, boolean includeHistorical) throws 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 includedIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols, Interval interval) throws 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 dataIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols, Calendar from) throws 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 dataIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols, Calendar from, Interval interval) throws 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 dataIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols, Calendar from, Calendar to) throws 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 dataIOException
- when there's a connection problempublic static Map<String,Stock> get(String[] symbols, Calendar from, Calendar to, Interval interval) throws 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 dataIOException
- when there's a connection problempublic static FxQuote getFx(String symbol) throws IOException
FxSymbols
Some examples of accepted symbols:
symbol
- symbol for the FX rate you want to requestIOException
- when there's a connection problempublic static Map<String,FxQuote> getFx(String[] symbols) throws IOException
getFx(String)
for more information on the
accepted FX symbols.symbols
- an array of FX symbolsIOException
- when there's a connection problem or the request is incorrectgetFx(java.lang.String)
Copyright © 2022. All rights reserved.