ib: fix mktpair fallback table: use `Client._con2mkts` to translate..

Previously we were assuming that the `Client._contracts: dict[str,
Contract]` would suffice this directly, which obviously isn't true XD

Also,
- add the `NSE` venue to skip list.
- use new `rapidfuzz.process.extract()` lib API.
- only get con deats for non null exchange names..
ib_py311_fixes
Tyler Goodlet 2023-09-21 19:14:44 -04:00
parent 05959eaf70
commit 14f124164a
3 changed files with 29 additions and 11 deletions

View File

@ -416,20 +416,26 @@ class Client:
futs: list[asyncio.Future] = []
for con in contracts:
if con.primaryExchange not in _exch_skip_list:
exch: str = con.primaryExchange or con.exchange
if (
exch
and exch not in _exch_skip_list
):
futs.append(self.ib.reqContractDetailsAsync(con))
# batch request all details
try:
results: list[ContractDetails] = await asyncio.gather(*futs)
except RequestError as err:
msg = err.message
msg: str = err.message
if (
'No security definition' in msg
):
log.warning(f'{msg}: {contracts}')
return {}
raise
# one set per future result
details: dict[str, ContractDetails] = {}
for details_set in results:
@ -1356,8 +1362,7 @@ async def open_aio_client_method_relay(
# relay all method requests to ``asyncio``-side client and deliver
# back results
while not to_trio._closed:
msg = await from_trio.get()
msg: tuple[str, dict] | dict | None = await from_trio.get()
match msg:
case None: # termination sentinel
print('asyncio PROXY-RELAY SHUTDOWN')

View File

@ -846,6 +846,18 @@ async def emit_pp_update(
# con: Contract = fill.contract
# provide a backup fqme -> MktPair table in case the
# symcache does not (yet) have an entry for the current mkt
# txn.
backup_table: dict[str, MktPair] = {}
for tid, txn in trans.items():
fqme: str = txn.fqme
if fqme not in ledger.symcache.mktmaps:
# bs_mktid: str = txn.bs_mktid
backup_table[fqme] = client._cons2mkts[
client._contracts[fqme]
]
acnt.update_from_ledger(
trans,
@ -855,7 +867,7 @@ async def emit_pp_update(
# TODO: remove this hack by attempting to symcache an
# incrementally updated table?
_mktmap_table=client._contracts
_mktmap_table=backup_table,
)
# re-compute all positions that have changed state.

View File

@ -165,6 +165,7 @@ _exch_skip_list = {
'MEXI', # mexican stocks
# no idea
'NSE',
'VALUE',
'FUNDSERV',
'SWB2',
@ -269,7 +270,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
stock_results.extend(results)
for i in range(10):
for _ in range(10):
with trio.move_on_after(3) as cs:
async with trio.open_nursery() as sn:
sn.start_soon(
@ -292,7 +293,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
break
# # match against our ad-hoc set immediately
# adhoc_matches = fuzzy.extractBests(
# adhoc_matches = fuzzy.extract(
# pattern,
# list(_adhoc_futes_set),
# score_cutoff=90,
@ -305,7 +306,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
# adhoc_matches}
log.debug(f'fuzzy matching stocks {stock_results}')
stock_matches = fuzzy.extractBests(
stock_matches = fuzzy.extract(
pattern,
stock_results,
score_cutoff=50,
@ -423,9 +424,9 @@ def con2fqme(
except KeyError:
pass
suffix = con.primaryExchange or con.exchange
symbol = con.symbol
expiry = con.lastTradeDateOrContractMonth or ''
suffix: str = con.primaryExchange or con.exchange
symbol: str = con.symbol
expiry: str = con.lastTradeDateOrContractMonth or ''
match con:
case ibis.Option():