diff --git a/piker/brokers/ib/api.py b/piker/brokers/ib/api.py index 67e63f70..431c889f 100644 --- a/piker/brokers/ib/api.py +++ b/piker/brokers/ib/api.py @@ -843,6 +843,7 @@ class Client: self, contract: Contract, timeout: float = 1, + tries: int = 100, raise_on_timeout: bool = False, ) -> Ticker | None: @@ -857,30 +858,30 @@ class Client: ready: ticker.TickerUpdateEvent = ticker.updateEvent # ensure a last price gets filled in before we deliver quote + timeouterr: Exception | None = None warnset: bool = False - for _ in range(100): - if isnan(ticker.last): + for _ in range(tries): - # wait for a first update(Event) + # wait for a first update(Event) indicatingn a + # live quote feed. + if isnan(ticker.last): try: tkr = await asyncio.wait_for( ready, timeout=timeout, ) - except TimeoutError: - import pdbp - pdbp.set_trace() + if tkr: + break + except TimeoutError as err: + timeouterr = err + await asyncio.sleep(0.01) + continue - if raise_on_timeout: - raise - return None - - if tkr: - break else: if not warnset: log.warning( - f'Quote for {contract} timed out: market is closed?' + f'Quote req timed out..maybe venue is closed?\n' + f'{asdict(contract)}' ) warnset = True @@ -888,6 +889,11 @@ class Client: log.info(f'Got first quote for {contract}') break else: + if timeouterr and raise_on_timeout: + import pdbp + pdbp.set_trace() + raise timeouterr + if not warnset: log.warning( f'Contract {contract} is not returning a quote ' @@ -895,6 +901,8 @@ class Client: ) warnset = True + return None + return ticker # async to be consistent for the client proxy, and cuz why not. diff --git a/piker/brokers/ib/feed.py b/piker/brokers/ib/feed.py index a175209d..c6ed6350 100644 --- a/piker/brokers/ib/feed.py +++ b/piker/brokers/ib/feed.py @@ -943,6 +943,11 @@ async def stream_quotes( contract=con, raise_on_timeout=True, ) + first_quote: dict = normalize(first_ticker) + log.info( + 'Rxed init quote:\n' + f'{pformat(first_quote)}' + ) cs: trio.CancelScope | None = None startup: bool = True while (