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
parent
05959eaf70
commit
14f124164a
|
@ -416,20 +416,26 @@ class Client:
|
||||||
|
|
||||||
futs: list[asyncio.Future] = []
|
futs: list[asyncio.Future] = []
|
||||||
for con in contracts:
|
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))
|
futs.append(self.ib.reqContractDetailsAsync(con))
|
||||||
|
|
||||||
# batch request all details
|
# batch request all details
|
||||||
try:
|
try:
|
||||||
results: list[ContractDetails] = await asyncio.gather(*futs)
|
results: list[ContractDetails] = await asyncio.gather(*futs)
|
||||||
except RequestError as err:
|
except RequestError as err:
|
||||||
msg = err.message
|
msg: str = err.message
|
||||||
if (
|
if (
|
||||||
'No security definition' in msg
|
'No security definition' in msg
|
||||||
):
|
):
|
||||||
log.warning(f'{msg}: {contracts}')
|
log.warning(f'{msg}: {contracts}')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
raise
|
||||||
|
|
||||||
# one set per future result
|
# one set per future result
|
||||||
details: dict[str, ContractDetails] = {}
|
details: dict[str, ContractDetails] = {}
|
||||||
for details_set in results:
|
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
|
# relay all method requests to ``asyncio``-side client and deliver
|
||||||
# back results
|
# back results
|
||||||
while not to_trio._closed:
|
while not to_trio._closed:
|
||||||
msg = await from_trio.get()
|
msg: tuple[str, dict] | dict | None = await from_trio.get()
|
||||||
|
|
||||||
match msg:
|
match msg:
|
||||||
case None: # termination sentinel
|
case None: # termination sentinel
|
||||||
print('asyncio PROXY-RELAY SHUTDOWN')
|
print('asyncio PROXY-RELAY SHUTDOWN')
|
||||||
|
|
|
@ -846,6 +846,18 @@ async def emit_pp_update(
|
||||||
|
|
||||||
# con: Contract = fill.contract
|
# 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(
|
acnt.update_from_ledger(
|
||||||
trans,
|
trans,
|
||||||
|
|
||||||
|
@ -855,7 +867,7 @@ async def emit_pp_update(
|
||||||
|
|
||||||
# TODO: remove this hack by attempting to symcache an
|
# TODO: remove this hack by attempting to symcache an
|
||||||
# incrementally updated table?
|
# incrementally updated table?
|
||||||
_mktmap_table=client._contracts
|
_mktmap_table=backup_table,
|
||||||
)
|
)
|
||||||
|
|
||||||
# re-compute all positions that have changed state.
|
# re-compute all positions that have changed state.
|
||||||
|
|
|
@ -165,6 +165,7 @@ _exch_skip_list = {
|
||||||
'MEXI', # mexican stocks
|
'MEXI', # mexican stocks
|
||||||
|
|
||||||
# no idea
|
# no idea
|
||||||
|
'NSE',
|
||||||
'VALUE',
|
'VALUE',
|
||||||
'FUNDSERV',
|
'FUNDSERV',
|
||||||
'SWB2',
|
'SWB2',
|
||||||
|
@ -269,7 +270,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
|
||||||
|
|
||||||
stock_results.extend(results)
|
stock_results.extend(results)
|
||||||
|
|
||||||
for i in range(10):
|
for _ in range(10):
|
||||||
with trio.move_on_after(3) as cs:
|
with trio.move_on_after(3) as cs:
|
||||||
async with trio.open_nursery() as sn:
|
async with trio.open_nursery() as sn:
|
||||||
sn.start_soon(
|
sn.start_soon(
|
||||||
|
@ -292,7 +293,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
|
||||||
break
|
break
|
||||||
|
|
||||||
# # match against our ad-hoc set immediately
|
# # match against our ad-hoc set immediately
|
||||||
# adhoc_matches = fuzzy.extractBests(
|
# adhoc_matches = fuzzy.extract(
|
||||||
# pattern,
|
# pattern,
|
||||||
# list(_adhoc_futes_set),
|
# list(_adhoc_futes_set),
|
||||||
# score_cutoff=90,
|
# score_cutoff=90,
|
||||||
|
@ -305,7 +306,7 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
|
||||||
# adhoc_matches}
|
# adhoc_matches}
|
||||||
|
|
||||||
log.debug(f'fuzzy matching stocks {stock_results}')
|
log.debug(f'fuzzy matching stocks {stock_results}')
|
||||||
stock_matches = fuzzy.extractBests(
|
stock_matches = fuzzy.extract(
|
||||||
pattern,
|
pattern,
|
||||||
stock_results,
|
stock_results,
|
||||||
score_cutoff=50,
|
score_cutoff=50,
|
||||||
|
@ -423,9 +424,9 @@ def con2fqme(
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
suffix = con.primaryExchange or con.exchange
|
suffix: str = con.primaryExchange or con.exchange
|
||||||
symbol = con.symbol
|
symbol: str = con.symbol
|
||||||
expiry = con.lastTradeDateOrContractMonth or ''
|
expiry: str = con.lastTradeDateOrContractMonth or ''
|
||||||
|
|
||||||
match con:
|
match con:
|
||||||
case ibis.Option():
|
case ibis.Option():
|
||||||
|
|
Loading…
Reference in New Issue