Handle no matching symbols case

symbol_search
Tyler Goodlet 2021-04-10 12:20:21 -04:00
parent 36530d9cf6
commit 27aed85404
1 changed files with 23 additions and 19 deletions

View File

@ -245,27 +245,31 @@ class Client:
""" """
descriptions = await self.ib.reqMatchingSymbolsAsync(pattern) descriptions = await self.ib.reqMatchingSymbolsAsync(pattern)
futs = [] if descriptions is not None:
for d in descriptions: futs = []
con = d.contract for d in descriptions:
futs.append(self.ib.reqContractDetailsAsync(con))
# batch request all details
results = await asyncio.gather(*futs)
# XXX: if there is more then one entry in the details list
details = {}
for details_set in results:
# then the contract is so called "ambiguous".
for d in details_set:
con = d.contract con = d.contract
unique_sym = f'{con.symbol}.{con.primaryExchange}' futs.append(self.ib.reqContractDetailsAsync(con))
details[unique_sym] = asdict(d) if asdicts else d
if len(details) == upto: # batch request all details
return details results = await asyncio.gather(*futs)
return details # XXX: if there is more then one entry in the details list
details = {}
for details_set in results:
# then the contract is so called "ambiguous".
for d in details_set:
con = d.contract
unique_sym = f'{con.symbol}.{con.primaryExchange}'
details[unique_sym] = asdict(d) if asdicts else d
if len(details) == upto:
return details
return details
else:
return {}
async def search_futes( async def search_futes(
self, self,
@ -562,7 +566,7 @@ class Client:
# default config ports # default config ports
_tws_port: int = 7497 _tws_port: int = 7497
_gw_port: int = 4002 _gw_port: int = 4002
_try_ports = [_tws_port, _gw_port] _try_ports = [_gw_port, _tws_port]
_client_ids = itertools.count() _client_ids = itertools.count()
_client_cache = {} _client_cache = {}