This gives me historical data for a single JPY future option. I want to get the same data, but for all available expiries/strikes.
from ib_insync import *
util.startLoop()
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)
contract = Contract(
secType='FOP',
symbol='JPY',
lastTradeDateOrContractMonth='20240906',
strike=0.0064,
right='P',
exchange='CME',
)
bars = ib.reqHistoricalData(
contract,
endDateTime='20240621-22:00:00',
durationStr='2 D',
barSizeSetting='1 hour',
whatToShow='MIDPOINT',
useRTH=True
)
df = util.df(bars)
print(df)
If I omit the expiry and use reqContractDetails, I can get a list of contracts details that contains the expiries
contracts = Contract(
secType='FOP',
symbol='JPY',
#lastTradeDateOrContractMonth='20240906',
strike=0.0064,
right='P',
exchange='CME',
)
contract_details = ib.reqContractDetails(contracts)
contract_details
But how do I extract the expiries from that?
The other thing I have tried is to follow the ib_insync documentation and do something like
chains = ib.reqSecDefOptParams(contract.symbol, '', contract.secType, contract.conId)
util.df(chains)
But couldn’t get this to work…
New contributor
NeroTulip is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.