Search code examples
pythonattributeerrorinteractive-brokers

IBKR contractdetails.contract variables not accessible


I am currently using the IBKR api to request details about a contract, I am specifically interested in the conid, which is an attribute of the object Contract according to the documentation (IBKR Api Class Contract)

As a test, I implemented a simple request contract details to print out the whole detail of the contract

def contractDetails(self, reqId, ctx):
    super().contractDetails(reqId, ctx)
    print(ctx.contract)

The above segment of code printout the following:

432280833,SOS,STK,,0.0,,,SMART,NYSE,USD,SOS,SOS,False,,combo:

def contractDetails(self, reqId, ctx):
    super().contractDetails(reqId, ctx)
    print(ctx.contract.symbol)

The above code printout the symbol of the contract searched, as expected.

SOS

def contractDetails(self, reqId, ctx):
    super().contractDetails(reqId, ctx)
    print(ctx.contract.conid)

But the above code return an attributeError:

AttributeError: 'Contract' object has no attribute 'conid'

From my understanding of the documentation, the attribute should exist, and based on the initial printout it has a value of 432280833.

My question is, as anyone tried to fetch this information and succeeded?


Solution

  • You can check the source code to see what fields and methods there are.

    class Contract(Object):
        def __init__(self):
            self.conId = 0
            self.symbol = ""
    .....
    

    Note the spelling.