From c166a5560c071f69822e4f393eebcba01ff1f436 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Fri, 15 Sep 2023 07:17:44 -0700 Subject: [PATCH] Work in progress Iron Condor automation script --- iron_condor.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 iron_condor.py 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