|
| 1 | +[](https://travis-ci.org/femtotrader/python-eodhistoricaldata) |
| 2 | + |
| 3 | +# Python EOD Historical Data |
| 4 | + |
| 5 | +A library to download data from EOD historical data https://eodhistoricaldata.com/ using: |
| 6 | +- [Python](https://www.python.org/) |
| 7 | +- [Requests](http://docs.python-requests.org/) / [Requests-cache](http://requests-cache.readthedocs.io/) |
| 8 | +- [Pandas](http://pandas.pydata.org/) |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +### Install latest development version |
| 13 | + |
| 14 | +```bash |
| 15 | +$ pip install git+https://github.com/femtotrader/python-eodhistoricaldata.git |
| 16 | +``` |
| 17 | + |
| 18 | +or |
| 19 | + |
| 20 | +```bash |
| 21 | +$ git clone https://github.com/femtotrader/python-eodhistoricaldata.git |
| 22 | +$ python setup.py install |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +Environment variable `EOD_HISTORICAL_API_KEY` should be defined using: |
| 28 | + |
| 29 | +```bash |
| 30 | +export EOD_HISTORICAL_API_KEY="YOUR_API" |
| 31 | +``` |
| 32 | + |
| 33 | +You can download data simply using |
| 34 | + |
| 35 | +```python |
| 36 | +In [1]: import pandas as pd |
| 37 | +In [2]: pd.set_option("max_rows", 10) |
| 38 | +In [3]: from eod_historical_data import get_eod_data |
| 39 | +In [4]: df = get_eod_data("AAPL", "US") |
| 40 | +In [5]: df |
| 41 | +Out[1]: |
| 42 | + Open High Low Close Adjusted_close \ |
| 43 | +Date |
| 44 | +2000-01-03 3.7455 4.0179 3.6317 3.9978 3.9978 |
| 45 | +2000-01-04 3.8661 3.9509 3.6138 3.6607 3.6607 |
| 46 | +2000-01-05 3.7054 3.9487 3.6786 3.7143 3.7143 |
| 47 | +2000-01-06 3.7902 3.8214 3.3929 3.3929 3.3929 |
| 48 | +2000-01-07 3.4464 3.6071 3.4107 3.5536 3.5536 |
| 49 | +... ... ... ... ... ... |
| 50 | +2017-05-26 154.0000 154.2400 153.3100 153.6100 153.6100 |
| 51 | +2017-05-30 153.4200 154.4300 153.3300 153.6700 153.6700 |
| 52 | +2017-05-31 153.9700 154.1700 152.3800 152.7600 152.7600 |
| 53 | +2017-06-01 153.1700 153.3300 152.2200 153.1800 153.1800 |
| 54 | +2017-06-02 153.6000 155.4500 152.8900 155.4500 155.4500 |
| 55 | + |
| 56 | + Volume |
| 57 | +Date |
| 58 | +2000-01-03 133949200.0 |
| 59 | +2000-01-04 128094400.0 |
| 60 | +2000-01-05 194580400.0 |
| 61 | +2000-01-06 191993200.0 |
| 62 | +2000-01-07 115183600.0 |
| 63 | +... ... |
| 64 | +2017-05-26 21927600.0 |
| 65 | +2017-05-30 20126900.0 |
| 66 | +2017-05-31 24451200.0 |
| 67 | +2017-06-01 16274200.0 |
| 68 | +2017-06-02 25163841.0 |
| 69 | + |
| 70 | +[4382 rows x 6 columns] |
| 71 | +``` |
| 72 | + |
| 73 | +but if you want to avoid too much data consumption, you can use a cache mechanism. |
| 74 | + |
| 75 | + |
| 76 | +```python |
| 77 | +In [1]: import datetime |
| 78 | +In [2]: import requests_cache |
| 79 | +In [3]: expire_after = datetime.timedelta(days=1) |
| 80 | +In [4]: session = requests_cache.CachedSession(cache_name='cache', backend='sqlite', expire_after=expire_after) |
| 81 | +In [5]: df = get_eod_data("AAPL", "US", session=session) |
| 82 | +``` |
| 83 | + |
| 84 | +See [tests directory](https://github.com/femtotrader/python-eodhistoricaldata/tree/master/tests) for example of other API endpoints. |
| 85 | + |
| 86 | +## Credits |
| 87 | + |
| 88 | +- Idea to create this project [came from this issue](https://github.com/pydata/pandas-datareader/issues/315) (Thanks [@deios0](https://github.com/deios0) ) |
| 89 | +- Code was inspired by [pandas-datareader](http://pandas-datareader.readthedocs.io/) |
0 commit comments