Specify TickerID with ib_insync (Interactive Brokers API wrapper)

68 Views Asked by At

Does anyone know how to specify a TickerID using the ib_insync Interactive Broker's API wrapper? It is breaking my ability to pull historical pricing and snapshots multithreaded as ib_insync keeps sending the same TickerID with every call and IB is expecting a unique one.

Thx in advance. Hopefully a simple one.

ib_insync API doc:

reqHistoricalData(contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate=1, keepUpToDate=False, chartOptions=[], timeout=60)

Native IB API doc for the same function (4102 is the ticker ID):

self.reqHistoricalData(4102, ContractSamples.EurGbpFx(), queryTime, "1 M", "1 day", "MIDPOINT", 1, 1, False, [])

IB API Doc Page:

https://interactivebrokers.github.io/tws-api/historical_bars.html

IB telling me I am reusing a ticker ID.

Error processing request.-'bX' : cause - Duplicate ticker ID for API historical data query, contract: Stock(symbol='AAPL', exchange='SMART', currency='USD')

1

There are 1 best solutions below

0
Sumobull On

Figured it out. Can set the request ID to whatever you want via the following:

ib.client._reqIdSeq = <unique number>

However I identified that I didn't actually need to do that. Creating a new instance of the API object per thread with a unique client ID eliminates the problem.

ib.connect(host, port, clientId=<unique number>)