IEX: Obtaining Real-Time Equities Data

Until recently, high-frequency equities traders that wished to obtain cost-free equities data relied on both the Google Finance and Yahoo Finance APIs. As of 1/2018, both Yahoo and Google’s services have shut down.

Not to worry though, as The Investor’s Exchange (IEX) provides a similar service to obtain equities data. Their Developer API’s Stocks endpoints provide real-time data from a list of tickers that is a superset of the NYSE, Nasdaq, and AMEX exchanges (meaning it includes all tickers which were available in the depreciated Yahoo and Google services).

Performance-wise, the service is comparable with its predecessors. It’s possible to obtain both intra-day and historical data (through the chart endpoint). For traders which use Python-based trading platforms, we’ve created iexfinance, a Python 2.7+/3.5+ wrapper for the stocks endpoints, which can be found on Pypi.

The source is available here, and the docs here. A short tutorial is below.


Ideally, before installing or using iexfinance, we’ll create a new virtual environment using virtualenv. This will ensure that our packages are isolated from other projects and configured correctly.

Getting started

Once our environment is created, we can now install iexfinance. We do so by the following from iexfinance’s pypl repository.

This will install the latest stable release of iexfinance that is ready for use. Once installed, we can import the library and begin downloading data!

Retrieving Data

iexfinance uses two internal objects, Share and Batch to retrieve equities data. Share is used for single symbols and uses the /stock/<symbolname> endpoint from IEX. Batch, however, uses the market endpoint from Batch Requests to conduct the retrieval for multiple symbols.

Single Symbol

We’ll first work with the following instantiation:

So, we’ve called the IexFinance function and passed it the symbol "aapl", for Apple Inc. We've receieved a Share object in return whose symbol is "aapl." Notice that we have not passed any parameters at instantiation, so our object has used its defaults (see Share for more information). Should we attempt to pass a symbol not contained in the available symbol list (see Utilities), an IEXSymbolError will be raised:

At this point, the wrapper has downloaded all avaiable data for Apple Inc., and we can quickly access certain endpoints and datapoints without the overhead of making multiple API calls for the information. We’ll first work with the Quote endpoint. The IEX Docs for quote:

We see on the right an exact representation of the Quote endpoint’s response, in this case a JSON of various datapoints including “symbol” and “companyName”, among others. To retrieve the endpoint as represented, we use the provided endpoint method get_quote:

We see that get_quote returns the same as the IEX docs! But what if we don't want the entire endpoint? iexfinance provides a number of datapoint methods which allow access to specific items within certain endpoints. For instance, we could use get_open or get_company_name to obtain the relevant information:

A full list of the avaiable datapoint methods is provided in the Share documentation. In addition to these methods, it is possible to obtain one or more datapoints from a specific endpoint, using the get_select_datapoints method, passing the desired endpoint and a string or list of desired datapoint(s) as below:

We see that get_select_datapoints returns a dict of these datapoints, indexed by the keys provided. Note: the datapoint names must be entered in the exact formatting as the IEX documentation. If we attempt to select an invalid datapoint, an IEXDatapointError will be raised:

Multiple Symbols

For batch requests, IexFinance returns a Batch object, which contains many of the same methods as Share, but returns data in a dict indexed by each symbol provided.

We can see that the entire dataset, indexed by “AAPL” and “TSLA”, contains each endpoint. To obtain an individual endpoint, we use an endpoint method as we would with single symbols:

We see that the response of an endpoint method is also symbol-indexed. This remains true for all methods in Batch, including datapoint methods:

Obtaining multiple endpoints or multiple datapoints from a certain endpoint is easy for multiple symbols:

Updating Data

When we call the IexFinance function, the resulting object calls the refresh method at instantiation. This method downloads and obtains the latest market data from IEX. Realtime data is updated to the latest 15 minutes, per the IEX documentation.

Originally published at