From d2d3286fb8248b19082ede76fad480d87d809086 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 22 Feb 2022 15:20:13 -0500 Subject: [PATCH] Use `asyncio` in `Client.get_quote()` --- piker/brokers/ib.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index 3431dfd6..f8ad5826 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -516,12 +516,24 @@ class Client: ''' contract, ticker, details = await self.get_sym_details(symbol) + ready = ticker.updateEvent + # ensure a last price gets filled in before we deliver quote for _ in range(100): if isnan(ticker.last): - await asyncio.sleep(0.01) - log.warning(f'Quote for {symbol} timed out: market is closed?') - ticker = await ticker.updateEvent + + done, pending = await asyncio.wait( + [ready], + timeout=0.1, + ) + if ready in done: + break + else: + log.warning( + f'Quote for {symbol} timed out: market is closed?' + ) + + # ticker = await ticker.updateEvent else: log.info(f'Got first quote for {symbol}') break