By default silence `Client.get_quote()` timeout errors unless caller specifies to raise
parent
2e6b1330f3
commit
2b8cd031e8
|
@ -663,7 +663,7 @@ class Client:
|
||||||
|
|
||||||
# commodities
|
# commodities
|
||||||
elif exch == 'CMDTY': # eg. XAUUSD.CMDTY
|
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 = Commodity(**con_kwargs)
|
||||||
con.bars_kwargs = bars_kwargs
|
con.bars_kwargs = bars_kwargs
|
||||||
|
|
||||||
|
@ -780,6 +780,7 @@ class Client:
|
||||||
self,
|
self,
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
timeout: float = 1,
|
timeout: float = 1,
|
||||||
|
raise_on_timeout: bool = False,
|
||||||
|
|
||||||
) -> Ticker:
|
) -> Ticker:
|
||||||
'''
|
'''
|
||||||
|
@ -798,10 +799,16 @@ class Client:
|
||||||
if isnan(ticker.last):
|
if isnan(ticker.last):
|
||||||
|
|
||||||
# wait for a first update(Event)
|
# wait for a first update(Event)
|
||||||
|
try:
|
||||||
tkr = await asyncio.wait_for(
|
tkr = await asyncio.wait_for(
|
||||||
ready,
|
ready,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
except TimeoutError:
|
||||||
|
if raise_on_timeout:
|
||||||
|
raise
|
||||||
|
return tkr
|
||||||
|
|
||||||
if tkr:
|
if tkr:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -843,7 +843,10 @@ async def stream_quotes(
|
||||||
# TODO: we should instead spawn a task that waits on a feed to start
|
# 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.
|
# and let it wait indefinitely..instead of this hard coded stuff.
|
||||||
with trio.move_on_after(1):
|
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
|
# it might be outside regular trading hours so see if we can at
|
||||||
# least grab history.
|
# least grab history.
|
||||||
|
|
Loading…
Reference in New Issue