ib-api-reloaded / ib_async

Python sync/async framework for Interactive Brokers API (replaces ib_insync)
BSD 2-Clause "Simplified" License
479 stars 73 forks source link

how to use the `ticker.updateEvent` method #94

Open junyuanz1 opened 3 days ago

junyuanz1 commented 3 days ago

i have a code like this:

    async def wait_for_midpoint_price(self, ticker: Ticker, wait_time: int) -> bool:
        event = asyncio.Event()
        def onTicker(ticker: Ticker) -> None:
            if not util.isNan(ticker.midpoint()):
                event.set()
        ticker.updateEvent += onTicker
        try:
            await asyncio.wait_for(event.wait(), timeout=wait_time)
            return True
        except asyncio.TimeoutError:
            return False
        finally:
            ticker.updateEvent -= onTicker

however, I got some Python type error:

Cannot assign to attribute "updateEvent" for class "Ticker"
  Expression of type "Event" cannot be assigned to attribute "updateEvent" of class "Ticker"
    "Event" is not assignable to "TickerUpdateEvent"

just wondering is this the right way to use the updateEvent handler?

gnzsnz commented 2 days ago

here you have an example https://nbviewer.org/github/ib-api-reloaded/ib_async/blob/main/notebooks/tick_data.ipynb