ib_async icon indicating copy to clipboard operation
ib_async copied to clipboard

how to use the `ticker.updateEvent` method

Open junyuanz1 opened this issue 1 year ago • 1 comments

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?

junyuanz1 avatar Dec 01 '24 05:12 junyuanz1

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

gnzsnz avatar Dec 02 '24 12:12 gnzsnz