IEX API¶
IEX - Account Set Up¶
Install the Stock Analysis Engine
- If you want to use python pip:
pip install stock-analysis-engine
- If you want to use a Kubernetes cloud service (EKS, AKS, or GCP) use the Helm guide to get started
- If you want to run on your own bare-metal servers you can use Metalnetes to run multiple Analysis Engines at the same time
- If you want to develop your own algorithms or integrate your applications using python, you can set up a Development Environment
- If you want to use python pip:
Set
IEX_TOKEN
the Environment Variableexport IEX_TOKEN=PUBLISHABLE_TOKEN
IEX - Fetch API Reference¶
Fetch API calls for pulling IEX Cloud Data from a valid IEX account
Warning
Running these API calls will impact your account’s monthly quota. Please be aware of your usage when calling these.
Please set the environment variable IEX_TOKEN
to
your account token before running these calls.
More steps can be found on the docs in the IEX API
Command Line Tool Fetching Examples
With the Analysis Engine stack running you can use
the pip’s included fetch
command line tool with the
following arguments to pull data (and automate it).
Fetch Minute Data
fetch -t AAPL -g min
Fetch Daily Data
fetch -t AAPL -g day
Fetch Quote Data
fetch -t AAPL -g quote
Fetch Stats Data
fetch -t AAPL -g stats
Fetch Peers Data
fetch -t AAPL -g peers
Fetch News Data
fetch -t AAPL -g news
Fetch Financials Data
fetch -t AAPL -g fin
Fetch Earnings Data
fetch -t AAPL -g earn
Fetch Dividends Data
fetch -t AAPL -g div
Fetch Company Data
fetch -t AAPL -g comp
Command Line Fetch Debugging
Add the -d
flag to the fetch
command to enable
verbose logging. Here is an example:
fetch -t AAPL -g news -d
-
analysis_engine.iex.fetch_api.
fetch_daily
(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX daily data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#historical-prices
import analysis_engine.iex.fetch_api as iex_fetch daily_df = iex_fetch.fetch_daily(ticker='SPY') print(daily_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_minute
(ticker=None, backfill_date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX minute intraday data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#historical-prices
import analysis_engine.iex.fetch_api as iex_fetch minute_df = iex_fetch.fetch_minute(ticker='SPY') print(minute_df)
Parameters: - ticker – string ticker to fetch
- backfill_date – optional - date string formatted
YYYY-MM-DD
for filling in missing minute data - work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_quote
(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX quote data for a ticker and return as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#quote
import analysis_engine.iex.fetch_api as iex_fetch quote_df = iex_fetch.fetch_quote(ticker='SPY') print(quote_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_stats
(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX statistics data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#key-stats
import analysis_engine.iex.fetch_api as iex_fetch stats_df = iex_fetch.fetch_stats(ticker='SPY') print(stats_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_stats
(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source] Fetch the IEX statistics data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#key-stats
import analysis_engine.iex.fetch_api as iex_fetch stats_df = iex_fetch.fetch_stats(ticker='SPY') print(stats_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_news
(ticker=None, num_news=5, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX news data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#news
import analysis_engine.iex.fetch_api as iex_fetch news_df = iex_fetch.fetch_news(ticker='SPY') print(news_df)
Parameters: - ticker – string ticker to fetch
- num_news – optional - int number of news
articles to fetch
(default is
5
articles) - work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_financials
(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX financial data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#financials
import analysis_engine.iex.fetch_api as iex_fetch fin_df = iex_fetch.fetch_financials(ticker='SPY') print(fin_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_earnings
(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX earnings data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#earnings
import analysis_engine.iex.fetch_api as iex_fetch earn_df = iex_fetch.fetch_earnings(ticker='SPY') print(earn_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_dividends
(ticker=None, timeframe='3m', work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Fetch the IEX dividends data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#dividends
import analysis_engine.iex.fetch_api as iex_fetch div_df = iex_fetch.fetch_dividends(ticker='SPY') print(div_df)
Parameters: - ticker – string ticker to fetch
- timeframe – optional - string for setting
dividend lookback period used for
(default is
3m
for three months) - work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
-
analysis_engine.iex.fetch_api.
fetch_company
(ticker=None, work_dict=None, scrub_mode='NO_SORT', verbose=False)[source]¶ Fetch the IEX company data for a ticker and return it as a
pandas.DataFrame
.https://iexcloud.io/docs/api/#company
import analysis_engine.iex.fetch_api as iex_fetch comp_df = iex_fetch.fetch_company(ticker='SPY') print(comp_df)
Parameters: - ticker – string ticker to fetch
- work_dict – dictionary of args used by the automation
- scrub_mode – optional - string type of scrubbing handler to run
- verbose – optional - bool to log for debugging
IEX - HTTP Fetch Functions¶
Functions for getting data from IEX using HTTP
Debugging
Please set the verbose
argument to True
to enable debug logging with these calls
-
analysis_engine.iex.helpers_for_iex_api.
get_from_iex
(url, token=None, version=None, verbose=False)[source]¶ Helper for getting data from an IEX publishable API endpoint using a token as a query param on the http url.
Parameters: - url – IEX resource url
- token – optional - string token for your user’s account
- version – optional - version string
- verbose – optional - bool turn on logging
-
analysis_engine.iex.helpers_for_iex_api.
handle_get_from_iex
(url, token=None, version=None, verbose=False)[source]¶ Implementation for getting data from the IEX v2 or v1 api depending on if the
token
argument is set:Parameters: - url – IEX resource url
- token – optional - string token for your user’s account
- verbose – optional - bool turn on logging
Version: optional - string version for the IEX Cloud (default is
beta
)
-
analysis_engine.iex.helpers_for_iex_api.
get_from_iex_cloud
(url, token=None, verbose=False)[source]¶ Get data from IEX Cloud API (v2) https://iexcloud.io
Parameters: - url – IEX resource url
- token – optional - string token for your user’s account
- verbose – optional - bool turn on logging
-
analysis_engine.iex.helpers_for_iex_api.
get_from_iex_v1
(url, verbose=False)[source]¶ Get data from the IEX Trading API (v1) https//api.iextrading.com/1.0/
Parameters: - url – IEX V1 Resource URL
- verbose – optional - bool turn on logging
-
analysis_engine.iex.helpers_for_iex_api.
convert_datetime_columns
(df, date_cols=None, second_cols=None, tcols=None, ecols=None)[source]¶ Convert the IEX date columns in the
df
todatetime
objectsParameters: - df –
pandas.DataFrame
to set columns to datetime objects - date_cols – list of columns to convert with a date string format
formatted:
YYYY-MM-DD
- second_cols – list of columns to convert with a date string format
formatted:
YYYY-MM-DD HH:MM:SS
- tcols – list of columns to convert with a time format (this is for millisecond epoch integers)
- ecols – list of columns to convert with a time format (this is for nanosecond epoch integers)
- df –
IEX - Build Auth URL Using Publishable Token¶
Build an authenticated url for IEX Cloud
-
analysis_engine.iex.build_auth_url.
build_auth_url
(url, token=None)[source]¶ Helper for constructing authenticated IEX urls using an
IEX Publishable Token
with a valid IEX Cloud Beta AccountThis will return a string with the token as a query parameter on the HTTP url
Parameters: - url – initial url to make authenticated
- token – optional - string
IEX Publishable Token
(defaults toIEX_TOKEN
environment variable orNone
)
IEX - Extraction API Reference¶
Here is the extraction API for returning a pandas.DataFrame
from cached or archived IEX datasets.
Extract an IEX dataset from Redis and
return it as a pandas.DataFrame
or None
Please refer to the Extraction API reference for additional support
-
analysis_engine.iex.extract_df_from_redis.
extract_daily_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX daily data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' daily_status, daily_df = iex_extract.extract_daily_dataset( ticker='SPY') print(daily_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_minute_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX minute intraday data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' minute_status, minute_df = iex_extract.extract_minute_dataset( ticker='SPY') print(minute_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- scrub_mode – type of scrubbing handler to run
- work_dict – dictionary of args
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_quote_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX quote data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' quote_status, quote_df = iex_extract.extract_quote_dataset( ticker='SPY') print(quote_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_stats_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX statistics data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' stats_status, stats_df = iex_extract.extract_stats_dataset( ticker='SPY') print(stats_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_peers_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX peers data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' peers_status, peers_df = iex_extract.extract_peers_dataset( ticker='SPY') print(peers_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_news_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX news data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' news_status, news_df = iex_extract.extract_news_dataset( ticker='SPY') print(news_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_financials_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX financial data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' fin_status, fin_df = iex_extract.extract_financials_dataset( ticker='SPY') print(fin_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_earnings_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX earnings data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' earn_status, earn_df = iex_extract.extract_earnings_dataset( ticker='SPY') print(earn_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_dividends_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]¶ Extract the IEX dividends data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' div_status, div_df = iex_extract.extract_dividends_dataset( ticker='SPY') print(div_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
-
analysis_engine.iex.extract_df_from_redis.
extract_company_dataset
(ticker=None, date=None, work_dict=None, scrub_mode='NO_SORT', verbose=False)[source]¶ Extract the IEX company data for a ticker from Redis and return it as a tuple (status,
pandas.Dataframe
)import analysis_engine.iex.extract_df_from_redis as iex_extract # extract by historical date is also supported as an arg # date='2019-02-15' comp_status, comp_df = iex_extract.extract_company_dataset( ticker='SPY') print(comp_df)
Parameters: - ticker – string ticker to extract
- date – optional - string date to extract
formatted
YYYY-MM-DD
- work_dict – dictionary of args
- scrub_mode – type of scrubbing handler to run
- verbose – optional - boolean for turning on logging
IEX API Example - Fetch Minute Intraday Data using HTTP¶
Warning
This will fetch minute
data using your IEX Cloud account and can cost money depending on your request usage.
import analysis_engine.iex.fetch_api as fetch
df = fetch.fetch_minute(ticker='SPY')
print(df)
IEX API Example - Extract Minute Intraday Data from Cache¶
import datetime
import analysis_engine.iex.extract_df_from_redis as extract
ticker = 'SPY'
today = datetime.datetime.now().strftime('%Y-%m-%d')
status, df = extract.extract_minute_dataset({
'ticker': f'{ticker}',
'redis_key': f'{ticker}_{today}_minute'})
print(df)
IEX API Example - Get Minute Data from IEX (calls fetch and cache)¶
Warning
This will fetch and cache minute
data using your IEX Cloud account and can cost money depending on your request usage.
import analysis_engine.iex.get_data as get_data
df = get_data.get_data_from_iex({
'ticker': 'SPY',
'ft_type': 'minute'})
print(df)
IEX - Get Data¶
Use this function to pull data from IEX with a shared API for supported fetch routines over the IEX HTTP Rest API.
Common Fetch for any supported Get from IEX using HTTP
Supported environment variables:
# debug the fetch routines with:
export DEBUG_IEX_DATA=1
-
analysis_engine.iex.get_data.
get_data_from_iex
(work_dict)[source]¶ Get data from IEX - this requires an account
Parameters: work_dict – request dictionary
Distributed Automation API¶
This is a helper for the parent method:
analysis_engine.iex.get_data.py
Fetch data from
IEX
with the factory method fetch_data
-
analysis_engine.iex.fetch_data.
fetch_data
(work_dict, fetch_type=None, verbose=False)[source]¶ Factory method for fetching data from IEX using an enum or string alias. Returns a pandas
DataFrame
and only supports one ticker at a time.Supported enums from:
analysis_engine.iex.consts
fetch_type = iex_consts.FETCH_DAILY fetch_type = iex_consts.FETCH_MINUTE fetch_type = iex_consts.FETCH_QUOTE fetch_type = iex_consts.FETCH_STATS fetch_type = iex_consts.FETCH_PEERS fetch_type = iex_consts.FETCH_NEWS fetch_type = iex_consts.FETCH_FINANCIALS fetch_type = iex_consts.FETCH_EARNINGS fetch_type = iex_consts.FETCH_DIVIDENDS fetch_type = iex_consts.FETCH_COMPANY
Supported
work_dict['ft_type']
string values:work_dict['ft_type'] = 'daily' work_dict['ft_type'] = 'minute' work_dict['ft_type'] = 'quote' work_dict['ft_type'] = 'stats' work_dict['ft_type'] = 'peers' work_dict['ft_type'] = 'news' work_dict['ft_type'] = 'financials' work_dict['ft_type'] = 'earnings' work_dict['ft_type'] = 'dividends' work_dict['ft_type'] = 'company'
Parameters: - work_dict – dictionary of args for the pEX call
- fetch_type – optional - name or enum of the fetcher to create can also be a lower case string in work_dict[‘ft_type’]
- verbose – optional - boolean enable debug logging