Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBKR API Gateway - Option Data #91

Open
joker1319 opened this issue Nov 17, 2024 · 2 comments
Open

IBKR API Gateway - Option Data #91

joker1319 opened this issue Nov 17, 2024 · 2 comments

Comments

@joker1319
Copy link

joker1319 commented Nov 17, 2024

Hi,
I don’t know why, but I can never get real-time data and always get "NaN" as the value. I also get the error message: "Requested market data is not subscribed. Delayed market data is available." However, I’ve subscribed to "OPRA (US-Optionsbörsen) (NP, L1)".

I just want a script that retrieves the option chain for all expiration dates so I can save it in my database (right now, I’m only using Yahoo Finance).

from ib_insync import *

def get_multiple_expirations_strikes(exp_list,strike_list):
    ib = IB()
    ib.connect('192.168.178.42', 8888, clientId=4, readonly=True)
    for i in exp_list:
        print('Expiration: ', i)
        for x in strike_list:
            for k in ['C','P']:
                contract = Option('SPY', i, x, k, 'SMART')
                details = ib.reqTickers(contract)                

                ib.sleep(5)

                print ('strike: ',x,' C/P: ',k," ",details[0].close)

get_multiple_expirations_strikes(["20241122"], [590])

Output:

Expiration: 20241122

Error 354, reqId 3: Requested market data is not subscribed.Delayed market data is available.SPY NOV 22 '24 590 Call (SPY   241122C00590000) /TOP/ALL, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20241122', strike=590, right='C', exchange='SMART')
Error 354, reqId 3: Requested market data is not subscribed.Delayed market data is available.Error&BEST/OPT/Top&BEST/OPT/Top
strike:  590  C/P:  C   nan
Error 354, reqId 4: Requested market data is not subscribed.Delayed market data is available.SPY NOV 22 '24 590 Put (SPY   241122P00590000) /TOP/ALL, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20241122', strike=590, right='P', exchange='SMART')
Error 354, reqId 4: Requested market data is not subscribed.Delayed market data is available.Error&BEST/OPT/Top&BEST/OPT/Top
strike:  590  C/P:  P   nan
@mattsta
Copy link
Contributor

mattsta commented Nov 17, 2024

Probably a mix of:

  • If the error message is complaining about "not subscribed" market data, then the correct market data just isn't available on the account for the request. Check the market data IBKR settings page for more bundles or data packages to use.
  • All contracts for requests should be run through qualify() first so the exact contract id values are populated.

If the goal is to find the full option chain, then reqContractDetails() with a partial date would return more matching values for the full date range.

I just want a script that retrieves the option chain for all expiration dates

Then reqTickers() doesn't help because reqTickers() provides live market data (and reqTickers() is mostly just a wrapper around reqMktData()).

What you would want is reqContractDetails() to fetch a list of option contracts for a partial contract specification (just provide a date of 202412 and it'll return for every date in the month, but since SPY has daily expirations, you may want to request dates sequentially).

@vishalg
Copy link

vishalg commented Jan 10, 2025

I believe you need to subscribe to the streaming data for the underlying not just the option data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants