Python module to get stock data from IEX API 1.0
An easy-to-use interface to obtain:
- Real-time quotes
- Historical data
- Actions (dividends, splits), Sector Performance
- Trading analyses (gainers, losers, etc.)
- IEX Market Data & Stats
iexfinance provides real-time financial data from the various IEX endpoints, including:
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
Common Usage Examples
The iex-examples repository provides a number of detailed examples of iexfinance usage. Basic examples are also provided below.
Using iexfinance to access data from IEX is quite easy. 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.
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 the 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)
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:
The Stock function creates a StockReader instance which has a method to retrieve each of the Stocks endpoints (get_quote, get_book, get_volume_by_venue, etc.):
from iexfinance.stocks import Stock tsla = Stock('TSLA') tsla.get_open() tsla.get_price()
Pandas DataFrame and JSON (dict) output formatting are selected with the output_format parameter when calling Stock.
tsla = Stock("TSLA", output_format='pandas') tsla.get_quote()
IEX Reference Data
Support for the IEX Reference Data endpoints is available through the top level functions get_available_symbols, get_corporate_actions, get_dividends, get_next_day_ex_date, and get_listed_symbol_dir. As with all endpoints, request parameters such as retry_count and output format selection (through output_format) can be passed to the call.
from iexfinance import get_available_symbols get_available_symbols(output_format='pandas')[:2]
IEX Market Data
The IEX Market Data endpoints are supported through various top-level functions, including get_market_tops and get_market_deep.
from iexfinance import get_market_tops get_market_tops()
The IEX Stats endpoints are supported through various top-level functions, including get_stats_intraday and get_stats_recent. These endpoints provide IEX’s trading statistics for a given ticker.
from iexfinance import get_stats_intraday get_stats_intraday()
Debugging & Caching
All functions (including Stock and get_historical_data) allow for Request Parameters, which include retry_count, pause, and session. These parameters are entirely optional. The first two deal with how unsuccessful requests are handled, and the third allows for the passing of a cached requests-cache session (see caching).
Copyright © 2018 Addison Lynch
See LICENSE for details
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|iexfinance-0.3.5-py3-none-any.whl (21.7 kB) Copy SHA256 hash SHA256||Wheel||py3|
|iexfinance-0.3.5.tar.gz (22.5 kB) Copy SHA256 hash SHA256||Source||None|