From 2b8cd031e802fc9945d816b634c6d4630e2abb4f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 18 Aug 2023 17:28:28 -0400 Subject: [PATCH] By default silence `Client.get_quote()` timeout errors unless caller specifies to raise --- piker/brokers/ib/api.py | 17 ++++++++++++----- piker/brokers/ib/feed.py | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/piker/brokers/ib/api.py b/piker/brokers/ib/api.py index 75a79dbe..7647d03e 100644 --- a/piker/brokers/ib/api.py +++ b/piker/brokers/ib/api.py @@ -663,7 +663,7 @@ class Client: # commodities elif exch == 'CMDTY': # eg. XAUUSD.CMDTY - con_kwargs, bars_kwargs = _adhoc_symbol_map[symbol] + con_kwargs, bars_kwargs = _adhoc_symbol_map[symbol.upper()] con = Commodity(**con_kwargs) con.bars_kwargs = bars_kwargs @@ -780,6 +780,7 @@ class Client: self, contract: Contract, timeout: float = 1, + raise_on_timeout: bool = False, ) -> Ticker: ''' @@ -798,10 +799,16 @@ class Client: if isnan(ticker.last): # wait for a first update(Event) - tkr = await asyncio.wait_for( - ready, - timeout=timeout, - ) + try: + tkr = await asyncio.wait_for( + ready, + timeout=timeout, + ) + except TimeoutError: + if raise_on_timeout: + raise + return tkr + if tkr: break else: diff --git a/piker/brokers/ib/feed.py b/piker/brokers/ib/feed.py index 72f51964..44e3af2a 100644 --- a/piker/brokers/ib/feed.py +++ b/piker/brokers/ib/feed.py @@ -843,7 +843,10 @@ async def stream_quotes( # TODO: we should instead spawn a task that waits on a feed to start # and let it wait indefinitely..instead of this hard coded stuff. with trio.move_on_after(1): - first_ticker = await proxy.get_quote(contract=con) + first_ticker = await proxy.get_quote( + contract=con, + raise_on_timeout=True, + ) # it might be outside regular trading hours so see if we can at # least grab history.