Python module to get stock data from IEX API 1.0
Project description
Python wrapper around the Investors Exchange (IEX) Developer API.
An easy-to-use interface to obtain:
Real-time quotes
Historical data
Fundamentals,
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:
Documentation
Stable documentation is hosted on github.io.
Development documentation is also available for the latest changes in master.
Install
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.
Real-time Quotes
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()
Historical Data
It’s possible to obtain historical data the get_historical_data and get_historical_intraday.
Daily
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()
Minutely (Intraday)
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')
Endpoints
Stock Endpoints
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()
IEX Stats
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).
Contact
Email: ahlshop@gmail.com
Twitter: alynchfc
License
Copyright © 2018 Addison Lynch
See LICENSE for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for iexfinance-0.3.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0523d02fbdd042060c9c816972cdbaaa4fde1cf3451b3caaeda9c6b1253cb4b |
|
MD5 | bb6b5dbd40a8c2de85796860e8c23ee8 |
|
BLAKE2b-256 | f38c1b63aaeca15a69b7821e9a0394950465bc546fe282fd4bc7a0ddde3c4343 |