ib: only raise first quote timeout err after tries

Previously we were actually failing silently too fast instead of
actually trying multiple times (now we do for 100) before finally
raising any timeout in the final loop `else:` block.
distribute_dis
Tyler Goodlet 2023-12-18 11:45:19 -05:00
parent 1f9a497637
commit d5d68f75ea
2 changed files with 26 additions and 13 deletions

View File

@ -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 raise_on_timeout:
raise
return None
if tkr:
break
except TimeoutError as err:
timeouterr = err
await asyncio.sleep(0.01)
continue
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.

View File

@ -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 (