After working with data from eodhistoricaldata.com for a while I made this to simplify fetching and aggregating from their different endpoints and returning it in a consistent format.
- Have python and pandas installed (I'm using Python 3.8.10 and pandas 1.3.1)
- Download the
EOD_api.py
file to your working directory
You can download data for different stocks across different exchanges by just providing a list of tickers
import EOD_api as eod
import os
token = os.environ['EOD_TOKEN'] # Place your token here, i.e. token = '12ab3cd5efgh45.12345678'
eod.ohlcv( ['AAPL.US','BP.LSE'], token, '2020-10-13', '2020-10-15').retrieve_data()
eod.ohlcv_intraday( ['AAPL.US'], token, '2020-10-13', '2020-10-14',intraday_frec='5m').retrieve_data()
The Income Statement, Balance Sheet, and Cash Flow data all in one pandas dataframe
eod.fundamental( ['AAPL.US','MSFT.US'], token, '2020-04-01', '2020-08-01').retrieve_data()
Some extra functions and methods to make data exploration easier from the start
Show
Get the list of available exchanges:
eod.get_exchange_list( token )
Get info on all the available tickers from a exchange:
eod.get_all_tickers_exchange('US',token)
Find tickers by marketcap:
eod.stock_screener( 7, token, 'US', initial_offset = 0, mincap = None, maxcap = None)['code']
Some methods to make it easier to add or remove data incrementally instead of downloading all the data from the data provider at every step during data exploration:
data = eod.ohlcv( ['AAPL.US','BP.LSE'], token, '2020-10-13', '2020-10-15')
data.retrieve_data()
data.add_tickers(['MSFT.US']).retrieve_data()
data.truncate_dates('2020-10-13','2020-10-14').retrieve_data()
data.remove_tickers(['MSFT.US','BP.LSE']).retrieve_data()
Show
Downloads ohlcv data to a pandas dataframe
tickers
: List of tickers to downloadtoken
: String with your key from the data providerstart
: String with the initial date from which to download dataend
: String with the final date from which to download data
retrieve_data()
: Return the dataframe with the dataadd_tickers( tickers)
: Download more tickers to the dataframetickers
: List of tickers to download
remove_tickers( tickers)
: Remove tickerstickers
: List of tickers to remove
truncate_dates( start, end)
: Remove datesstart
: String with the new initial dateend
: String with the new final date
Downloads intraday data to a pandas dataframe
intraday_frec
: Frecuency of intraday data. '5m' and '1m'. Check the data provider for availability of data.
Downloads fundamental data to a pandas dataframe. The Income Statement, Balance Sheet, and Cash Flow data is aggregated into one dataframe. If any columns have duplicated names only one is kept.
Returns a list of the available exchanges and some more info
Returns a list of the available tickers for a exchange and some more info
Function stock_screener( n_stocks, token, exchange, initial_offset = 0, mincap = None, maxcap = None):
Finds first n stocks in exchange by marketcap
n_stocks
: Int. Number of stocks to findexchange
: String. Chosen exchangeinitial_offset
: Number of stocks to skipmincap
:Minimum market capitalizationmaxcap
:Maximum market capitalization
I don't plan to maintain this.
However, I created a EODdata
class inside the EOD_api.py
that you can subclass to add more types of data. This way you might download all of your data from eodhistoricaldata.com in a streamlined way.
You can check all of the data types they offer in their website. For example you could include options, bonds, live data, financial news, insider trading, etc.
If you found any of this useful I would appreciate feedback.