erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.75k stars 723 forks source link

updateEvent Handler Issue with streaming Historical data #666

Closed MilindRCodes closed 5 months ago

MilindRCodes commented 7 months ago

Hi,

I am trying to extract streaming Historical bars using event handler. However, I am not getting any response in form of bars updated every 'x' time interval.

I am running this .py script in pycharm with python 3.9

Earlier, this same logic was working perfectly fine. Now, it is not giving any response. Do I have to change: 1) the event handler? 2) is there any new method to extract streaming bars?

`

    ib = IB()
    ib.connect('127.0.0.1', 7497, clientId=1)

    contract = Stock(self.stock_name, self.exchange, self.currency)
    self.ib_conn.qualifyContracts(contract)
    self.qualified_stock_contract = self.ib_conn.qualifyContracts(contract)
    self.ib_conn.reqMarketDataType(1)  # used 1 for live streaming data.

    bars = ib.reqHistoricalData(
        contract, endDateTime='', durationStr='1 D',
        barSizeSetting='1 min', whatToShow='MIDPOINT', useRTH=True)

   bars.updateEvent += self.on_bar_update   
   self.ib_conn.run()  # Run infinitely

   def on_bar_update(self, bars, has_new_bar):
        if has_new_bar:
            self.logger.info('%s: Received new bar.' % str(self.stock_name))
            df = util.df(bars)

`

cgntiger commented 6 months ago
bars = ib.reqHistoricalData(
    contract, endDateTime='', durationStr='1 D',
    barSizeSetting='1 min', whatToShow='MIDPOINT', useRTH=True, keepUpToDate=True)

    订阅缺少了参数 keepUpToDate=True;没有这个参数的话,设置回调事件也没用
erdewit commented 5 months ago

Not sure what the problem can be, but nothing has changed really.