Interactive Brokers Multiple reqMktData
esteve last edited by
I have a stategy that attaches to multiple IB symbols (10 aprox). However after backfilling from a file and connecting to IB I get the following error:
Max rate of messages per second has been exceeded
Is it possible that backtrader is launching too many requests to TWS ?
I have been looking into backtrader code and I believe self.ib.reqMktData is being called too many times. N^2 times where N is the number of symbols/datas.
At _runnext in cerebro.py d.next is called for each datas (N).
cerebro.py def _runnext(self, runstrats): ... for d in datas: qlapse = datetime.datetime.utcnow() - qstart d.do_qcheck(newqcheck, qlapse.total_seconds()) drets.append(d.next(ticks=False))
d.next ends up calling startdatas from ibsotre.py get called. In startdatas we have :
ibstore.py def startdatas(self): for data in self.datas: t = threading.Thread(target=data.reqdata)
Which calls ibdata.py 's reqdata, which finally does:
self.qlive = self.ib.reqMktData(self.contract)
Therefore we have two for loops on self.datas.
I have been able to avoid the max request problem by adding a timer.sleep at startdatas after waiting for the threads. But I believe there should be a better way.
This is my first post and I am not familiar with the platform. I hope I am not too off and this has not been covered in some other post... My guess is that self.ib.reqMktData should only be done once per symbol. Am I missing something ?