Skip to main content

Python module to get stock data from IEX API 1.0

Project description

https://travis-ci.org/addisonlynch/iexfinance.svg?branch=master https://codecov.io/gh/addisonlynch/iexfinance/branch/master/graphs/badge.svg?branch=master https://badge.fury.io/py/iexfinance.svg https://img.shields.io/badge/License-Apache%202.0-blue.svg

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


Download files

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

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page