For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Interactive Brokers Multiple reqMktData

  • 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 is called for each datas (N).
    def _runnext(self, runstrats):
        for d in datas:
                    qlapse = datetime.datetime.utcnow() - qstart
                    d.do_qcheck(newqcheck, qlapse.total_seconds())
 ends up calling startdatas from get called. In startdatas we have :
    def startdatas(self):
        for data in self.datas:
             t = threading.Thread(target=data.reqdata)

    Which calls '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 ?


Log in to reply