From f202699c25345b81cc7c784b46c2381d68351eef Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 18 Aug 2022 11:31:18 -0400 Subject: [PATCH] Fix scan loop: only stash clients that actually connect.. --- piker/brokers/ib/api.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/piker/brokers/ib/api.py b/piker/brokers/ib/api.py index 4616fe52..c18125f4 100644 --- a/piker/brokers/ib/api.py +++ b/piker/brokers/ib/api.py @@ -1127,6 +1127,12 @@ async def load_aio_clients( # careful. timeout=connect_timeout, ) + # create and cache client + client = Client(ib) + + # update all actor-global caches + log.info(f"Caching client for {sockaddr}") + _client_cache[sockaddr] = client break except ( @@ -1150,21 +1156,9 @@ async def load_aio_clients( log.warning( f'Failed to connect on {port} for {i} time, retrying...') - # create and cache client - client = Client(ib) - # Pre-collect all accounts available for this # connection and map account names to this client # instance. - pps = ib.positions() - if pps: - for pp in pps: - accounts_found[ - accounts_def.inverse[pp.account] - ] = client - - # if there are accounts without positions we should still - # register them for this client for value in ib.accountValues(): acct_number = value.account @@ -1185,10 +1179,6 @@ async def load_aio_clients( f'{pformat(accounts_found)}' ) - # update all actor-global caches - log.info(f"Caching client for {sockaddr}") - _client_cache[sockaddr] = client - # XXX: why aren't we just updating this directy above # instead of using the intermediary `accounts_found`? _accounts2clients.update(accounts_found)