Possible to get historical options data using IB/Python API?

Discussion in 'Automated Trading' started by ffs1001, Jun 7, 2022.

  1. ffs1001


    Does anyone know if it's possible to get historical options data where the expiry date is in the past? Eg, if say, today is 07-Jun-22, and I want to get options data for 02-Mar-22 for APPL call options at the strike price of 130, with an expiry date of 04-Mar-2022. Is this possible?

    I'm a newbie to Python, and have a simple script which gets the historical options data for expiries that are for the current week/future (eg 10-Jun-2022), but when I try to get the historical options data I get the "No security definition has been found."

    This video by IB themselves (at 14:30) states that once the option has expired, then it's data is removed from the database and it's data is thus no longer available. I was thinking maybe there is a way, or there may be a 3rd party service available (happy to pay) which has this options data.

  2. ZBZB


  3. ffs1001


    Thanks ZBZB, sorry I should have stated that I'm not looking for EOD data - I need a bit more granularity, like every hour, or preferably options data at 10 minute intervals.
    ivolatility.com and www.historicaloptionsdata.com are EOD data.

    I'll check out the other two - do you know if they can provide the detail I'm looking for?
  4. ffs1001


    Thanks @angrytrader , you are right - it's only possible to get historical data for currently live expiries.

    Meanwhile, I have another question. I've got a basic Python API script which gets historical prices for stocks like AAPL say, and the main code looks like this :

    #Create contract object
    contract = Contract()
    contract.symbol = 'AAPL'
    contract.secType = 'STK'
    contract.exchange = 'SMART'
    contract.currency = 'USD'

    #Request Market Data
    app.reqMktData(1, contract, '', False, False, [])

    ...and this works fine.

    However, when I try the same code for SPX, I change the 'contract' details to be as follows :

    #Create contract object
    contract = Contract()
    contract.symbol = 'SPX'
    contract.secType = 'IND'
    contract.exchange = 'CBOE'
    contract.currency = 'USD'

    and this gives me the error :

    "ERROR 1 162 Historical Market Data Service error message:No historical market data for SPX/IND@CBOE MidPoint 600"

    I have full SPX data permissions, so it is not that. The Description of this security on TWS is :

    and my code matches this.

    Anyone know why this is not working?

  5. ffs1001


    Last edited: Jun 21, 2022 at 11:47 AM