Luis Carcamo
Luis Carcamo

Reputation: 31

No security definition has been found for the request, Future Option Python

I'm using Python and ib_insync to use the Interactive brokers API, I'm trying to get market data as Bid, Ask,AskSize etc of a future Options contract, but when convert this contract on a ticker I got "No security definition has been found for the request", even when I assign this attribute before.

# using Future from ib_insync has the same problem
# contract = Future('ES',"20190315",'GLOBEX')

contract = Contract()
contract.symbol = "ES"
contract.secType = "FOP"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20190315"
contract.strike = 2900
contract.right = "C"
contract.multiplier = "50"

result =[]
result.append(contract)


ib.reqMarketDataType(3)
ib.qualifyContracts(*result)
ticker = ib.reqMktData(contract,"",False,False)
ib.sleep(3)
ticker

Output:

Error 200, reqId 26: No security definition has been found for the request, contract: Contract(secType='FOP', symbol='ES', lastTradeDateOrContractMonth='20190315', strike=2900, right='C', multiplier='50', exchange='GLOBEX', currency='USD')
Unknown contract: Contract(secType='FOP', symbol='ES', lastTradeDateOrContractMonth='20190315', strike=2900, right='C', multiplier='50', exchange='GLOBEX', currency='USD')

Upvotes: 1

Views: 4038

Answers (2)

Josh
Josh

Reputation: 816

Once a future option (or stock option) expires, its historical data is removed from the Interactive Brokers' database and is no longer available. So you would have to request data for a futures option which has not yet expired. TWS API Historical Data Limitations (This is also true for TWS charts, and not just the TWS API).

The boolean 'IncludeExpired' is only for futures contracts, and not for futures options.

Upvotes: 1

brian
brian

Reputation: 10989

Without testing your code I'm guessing this quote from the docs applies.

bool IncludeExpired [get, set] If set to true, contract details requests and historical data queries can be performed pertaining to expired futures contracts. Expired options or other instrument types are not available.

link to docs

So if it was just a futures contract you could do contract.includeExpired = True If you want historical data.

For reqMarketData, obviously you need to use a current contract, for ES that would be 201909 as the front month. Note that you don't have to put the date (15th) unless it is ambiguous or for options.

There is a program to test listing contracts available at github. https://github.com/tradewright/ibapi-tools/blob/master/ContractInspector/readme.md

Upvotes: 0

Related Questions