commit c166a5560c071f69822e4f393eebcba01ff1f436 Author: moshferatu Date: Fri Sep 15 07:17:44 2023 -0700 Work in progress Iron Condor automation script diff --git a/iron_condor.py b/iron_condor.py new file mode 100644 index 0000000..a3af87b --- /dev/null +++ b/iron_condor.py @@ -0,0 +1,18 @@ +from datetime import datetime +from ibkr import Client + +ibkr_client = Client(host = '127.0.0.1', port = 7497) + +underlying_ticker = ibkr_client.get_ticker('SPX', 'CBOE') +current_price = underlying_ticker.last + +# Filtering strikes based on distance from current price speeds up the request. +max_strike_distance = 100 +def contract_filter(contract): + if contract.right == 'C': + return contract.strike <= (current_price + max_strike_distance) and contract.strike >= current_price + return contract.strike <= current_price and contract.strike >= (current_price - max_strike_distance) + +# The weekly symbol for SPX (SPXW) is required in order to distinguish from monthly options. +option_chain = ibkr_client.get_option_chain('SPX', datetime.now(), sub_symbol = 'SPXW', contract_filter = contract_filter) +print(option_chain) \ No newline at end of file