ib_async icon indicating copy to clipboard operation
ib_async copied to clipboard

how to get option openinterest?

Open gracekk opened this issue 1 year ago • 3 comments

refer to https://github.com/ib-api-reloaded/ib_async/blob/main/notebooks/option_chain.ipynb There is no value associated with OpenInterest.

and I try ib.reqMktData option_contract = Option(stock_symbol, expiration, strike, right, exchange) ticker = ib.reqMktData(option_contract, '', False, False) ticker.putOpenInterest or ticker.callOpenInterest always get NaN

any demo code or suggestion? thanks

gracekk avatar May 14 '24 04:05 gracekk

You have to tell ib.reqMktData() that you want additional tickers via so called generic ticks.

There is a list available here: https://interactivebrokers.github.io/tws-api/tick_types.html

Call and put open interest is generic tick 101, so your market data call should look likes this: ticker = ib.reqMktData(option_contract, genericTickList='101')

It can take a short while till these extra ticks get filled after the first call, but it works for me.

August1328 avatar May 15 '24 09:05 August1328

You have to tell ib.reqMktData() that you want additional tickers via so called generic ticks.

There is a list available here: https://interactivebrokers.github.io/tws-api/tick_types.html

Call and put open interest is generic tick 101, so your market data call should look likes this: ticker = ib.reqMktData(option_contract, genericTickList='101')

It can take a short while till these extra ticks get filled after the first call, but it works for me.

Thanks man,I found that open interest doesn't even have anything to do with real time data, it looks like it will only be updated on a regular daily basis. generic tick 100 indicates the volume, but it doesn't seem to be the overall daily volume, just the volume of the previous tick, is it possible to get the total volume of the daily option?

gracekk avatar May 16 '24 14:05 gracekk

For overall daily volume of an option I use tick 100 and then ticker.callVolume or ticker.putVolume.

August1328 avatar May 17 '24 10:05 August1328

Apologies for reopening this request again, but I am having trouble with getting options open interest. The code I run in terminal is

from ib_async import *

ib = IB()
ib.connect('127.0.0.1', 4001, clientId=138)

ib.reqMarketDataType(1)

option1 = [Option('GOOGL', '20250117', 195, 'C', 'SMART')]

ib.qualifyContracts(option1[0])

a=ib.reqMktData(option1[0],genericTickList='100',snapshot=False, regulatorySnapshot=False)
print(a)
print("-")

b=ib.reqTickers(Option('GOOGL', '20250117', 195, 'C', 'SMART'))
print("Volume ", b[0].volume)
print("callOpenInterest ", b[0].callOpenInterest)
print("putOpenInterest", b[0].putOpenInterest)
print("impliedVolatility ", b[0].impliedVolatility)

ib.disconnect()

and the output I get is

Ticker(contract=Option(conId=584786601, symbol='GOOGL', lastTradeDateOrContractMonth='20250117', strike=195.0, right='C', multiplier='100', exchange='SMART', currency='USD', localSymbol='GOOGL 250117C00195000', tradingClass='GOOGL'))
-
Volume  1385.0
callOpenInterest  nan
putOpenInterest nan
impliedVolatility  nan

Would it be possible please to update the docs with option volume and open interest examples?

Djangu-algo avatar Dec 26 '24 22:12 Djangu-algo