This Python script connects to the Interactive Brokers Trader Workstation (TWS) API to fetch option contract details for a specific ticker symbol and expiration date, and then saves the data to a CSV file.
- Retrieve option contract details (call and put) for a specified ticker symbol and expiration date
- Save the fetched data to a CSV file
- Python 3.6 or higher
- Interactive Brokers account and TWS software installed
- TWS API enabled with proper IP and port settings
ibapi
package installed (usepip install ibapi
to install)
- Update the script with the desired ticker symbol and expiration date in the
main()
function:
contract.symbol = "AMZN" contract.lastTradeDateOrContractMonth = "20240119"
-
Ensure that the TWS software is running and the API is enabled with the correct IP and port settings.
-
Run the script:
python fetch_option_data.py
- The option contract details will be saved in a CSV file named
options_data.csv
.
This project is licensed under the GNU Lesser General Public License (LGPL) v2.1. See the LICENSE file for details.