Python SDK for IEX Cloud. Architecture mirrors that of the IEX Cloud API (and its documentation).
An easy-to-use toolkit to obtain data for Stocks, ETFs, Mutual Funds, Forex/Currencies, Options, Commodities, Bonds, and Cryptocurrencies:
- Real-time and delayed quotes
- Historical data (daily and minutely)
- Financial statements (Balance Sheet, Income Statement, Cash Flow)
- End of Day Options Prices
- Institutional and Fund ownership
- Analyst estimates, Price targets
- Corporate actions (Dividends, Splits)
- Sector performance
- Market analysis (gainers, losers, volume, etc.)
- IEX market data & statistics (IEX supported/listed symbols, volume, etc)
- Social Sentiment and CEO Compensation
Stable documentation is hosted on github.io.
Development documentation is also available for the latest changes in master.
From PyPI with pip (latest stable release):
$ pip3 install iexfinance
From development repository (dev version):
$ git clone https://github.com/addisonlynch/iexfinance.git
$ cd iexfinance
$ python3 setup.py install
An IEX Cloud account is required to acecss the IEX Cloud API. Various plans are availalbe, free, paid, and pay-as-you-go.
Your IEX Cloud (secret) authentication token can be passed to any function or at the instantiation of a Stock
object.
The easiest way to store a token is in the IEX_TOKEN
environment variable.
The authentication token can also be passed to any function call:
from iexfinance.refdata import get_symbols
get_symbols(output_format='pandas', token="<YOUR AUTH TOKEN>")
or at the instantiation of a Stock
object:
from iexfinance.stocks import Stock
a = Stock("AAPL", token="<YOUR AUTH TOKEN>")
a.get_quote()
iexfinance
is designed to mirror the structure of the IEX Cloud API. The
following IEX Cloud endpoint groups are mapped to their respective
iexfinance
modules:
- Account -
account
(iexfinance docs | IEX Docs) - Stocks -
stocks
(iexfinance docs | IEX Docs) - Alternative Data -
altdata
(iexfinance docs | IEX Cloud Docs) - Reference Data -
refdata
(iexfinance docs | IEX Cloud Docs) - Investors Exchange Data -
iexdata
(iexfinance docs | IEX Cloud Docs) - API System Metadata -
apidata
(iexfinance docs | IEX Cloud Docs)
The most commonly-used endpoints are the Stocks endpoints, which allow access to various information regarding equities, including quotes, historical prices, dividends, and much more.
The Stock
object
provides access to most endpoints, and can be instantiated with a symbol or
list of symbols:
from iexfinance.stocks import Stock
aapl = Stock("AAPL")
aapl.get_balance_sheet()
The rest of the package is designed as a 1:1 mirror. For example, using the
Alternative Data endpoint
group, obtain the Social Sentiment endpoint with
iexfinance.altdata.get_social_sentiment
:
from iexfinance.altdata import get_social_sentiment
get_social_sentiment("AAPL")
iexfinance
now defaults to IEX Cloud for all calls. The use of
v1
as IEX_API_VERSION
now calls IEX Cloud version 1 (v1).
The desired IEX API version can be specified using the IEX_API_VERSION
environment variable. The following versions are currently supported:
v1
- default (now same asiexcloud-v1
)iexcloud-beta
iexcloud-v1
iexcloud-sandbox
- for use with the sandbox environment (test token must be used)
By default, iexfinance
returns data formatted exactly as received from
the IEX Endpoint. pandas DataFrame
output
formatting is available for most endpoints.
pandas DataFrame
output formatting can be selected by setting the
IEX_OUTPUT_FORMAT
environment variable to pandas
or by passing
output_format
as an argument to any function call (or at the instantiation
of a Stock
object).
The iex-examples repository provides a number of detailed examples of iexfinance usage. Basic examples are also provided below.
To obtain real-time quotes for one or more symbols, use the get_price
method of the Stock
object:
from iexfinance.stocks import Stock
tsla = Stock('TSLA')
tsla.get_price()
or for multiple symbols, use a list or list-like object (Tuple, Pandas Series, etc.):
batch = Stock(["TSLA", "AAPL"])
batch.get_price()
It's possible to obtain historical data using get_historical_data
and
get_historical_intraday
.
To obtain daily historical price data for one or more symbols, use the
get_historical_data
function. This will return a daily time-series of the ticker
requested over the desired date range (start
and end
passed as
datetime.datetime
objects):
from datetime import datetime
from iexfinance.stocks import get_historical_data
start = datetime(2017, 1, 1)
end = datetime(2018, 1, 1)
df = get_historical_data("TSLA", start, end)
To obtain daily closing prices only (reduces message count), set
close_only=True
:
df = get_historical_data("TSLA", "20190617", close_only=True)
For Pandas DataFrame output formatting, pass output_format
:
df = get_historical_data("TSLA", start, end, output_format='pandas')
It's really simple to plot this data, using matplotlib:
import matplotlib.pyplot as plt
df.plot()
plt.show()
To obtain historical intraday data, use get_historical_intraday
as follows.
Pass an optional date
to specify a date within three months prior to the
current day (default is current date):
from datetime import datetime
from iexfinance.stocks import get_historical_intraday
date = datetime(2018, 11, 27)
get_historical_intraday("AAPL", date)
or for a Pandas Dataframe indexed by each minute:
get_historical_intraday("AAPL", output_format='pandas')
from iexfinance.stocks import Stock
aapl = Stock("AAPL")
aapl.get_balance_sheet()
aapl.get_income_statement()
aapl.get_cash_flow()
from iexfinance.stocks import Stock
aapl = Stock("AAPL")
aapl.get_estimates()
aapl.get_price_target()
from iexfinance.altdata import get_social_sentiment
get_social_sentiment("AAPL")
from iexfinance.altdata import get_ceo_compensation
get_ceo_compensation("AAPL")
from iexfinance.stocks import Stock
aapl = Stock("AAPL")
# Fund ownership
aapl.get_fund_ownership()
# Institutional ownership
aapl.get_institutional_ownership()
List of Symbols IEX supports for API calls
from iexfinance.refdata import get_symbols
get_symbols()
List of Symbols IEX supports for trading
from iexfinance.refdata import get_iex_symbols
get_iex_symbols()
from iexfinance.account import get_usage
get_usage(quota_type='messages')
from iexfinance.account import get_api_status
get_api_status()
Email: [email protected]
Twitter: alynchfc
Copyright © 2019 Addison Lynch
See LICENSE for details