Getting data¶
Interactive Brokers historic data¶
Interactive Brokers provides free historic data (only for clients) up to 6 month in the past, with a maximum resolution of 1 second bars. This is great of course, but to prevent abuse, IB imposed all kinds of download limitations. You are not allowed to make more than 60 data requests per 10 minutes for example and the number of bars per request is limited.
The script tools/getData.py
is designed to download large datasets while respecting the rules.
This script downloads historic data for single or multiple securities through the Interactive brokers API.
- the tool is run from the command line (see parameters below)
- configuration is done in
settings.yml
. Here a list of security definitions is kept - together with data destination folder
- configuration is done in
- the data is saved as
.csv
files in a directory structure.
Interactive Brokers tick data¶
tickLogger.py
is a script to log tick events to a file.
- symbols to log and data location are stored in a yml config file
- default configuration is read from
settings.yml
, you can provide different file through command line parameter. - ticks are logged to a rotating csv file, new file will start on midnight
Note
If you need to run this program for longer time periods, it is advisable to use IB Gateway instead of IB TWS. The latter will automatically log off at the end of each day.
Yahoo Finance data¶
Yahoo Finance¶
This module enables easy access to data provided by Yahoo Finance.
Note
This service may stop without notice, Yahoo does not seem to like people accessing their data automatically. Breaking the service already happened in early 2017. This module includes a workaround that works … for now.
Getting historic data¶
The module is usually imported as follows:
In [1]: from tradingWithPython import yahooFinance as yf
Singe symbol¶
Then, to get raw yahoo finance data for a symbol use getSymbolData()
In [2]: df = yf.getSymbolData("SPY")
Got 4510 days of data
In [3]: df.head()