Work in progress Iron Condor automation script
This commit is contained in:
commit
c166a5560c
18
iron_condor.py
Normal file
18
iron_condor.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user