brokers.core: open cached client before hitting `.get_mkt_info()`

account_tests
Tyler Goodlet 2023-07-10 12:07:15 -04:00
parent a2c6749112
commit 55c3d617fa
1 changed files with 26 additions and 24 deletions

View File

@ -95,15 +95,15 @@ async def option_chain(
return await client.option_chains(contracts) return await client.option_chains(contracts)
async def contracts( # async def contracts(
brokermod: ModuleType, # brokermod: ModuleType,
symbol: str, # symbol: str,
) -> Dict[str, Dict[str, Dict[str, Any]]]: # ) -> Dict[str, Dict[str, Dict[str, Any]]]:
"""Return option contracts (all expiries) for ``symbol``. # """Return option contracts (all expiries) for ``symbol``.
""" # """
async with brokermod.get_client() as client: # async with brokermod.get_client() as client:
# # return await client.get_all_contracts([symbol])
# return await client.get_all_contracts([symbol]) # return await client.get_all_contracts([symbol])
return await client.get_all_contracts([symbol])
async def bars( async def bars(
@ -117,21 +117,6 @@ async def bars(
return await client.bars(symbol, **kwargs) return await client.bars(symbol, **kwargs)
async def mkt_info(
brokermod: ModuleType,
fqme: str,
**kwargs,
) -> MktPair:
'''
Return MktPair info from broker including src and dst assets.
'''
return await brokermod.get_mkt_info(
fqme.replace(brokermod.name, '')
)
async def search_w_brokerd(name: str, pattern: str) -> dict: async def search_w_brokerd(name: str, pattern: str) -> dict:
async with open_cached_client(name) as client: async with open_cached_client(name) as client:
@ -178,3 +163,20 @@ async def symbol_search(
n.start_soon(search_backend, mod.name) n.start_soon(search_backend, mod.name)
return results return results
async def mkt_info(
brokermod: ModuleType,
fqme: str,
**kwargs,
) -> MktPair:
'''
Return MktPair info from broker including src and dst assets.
'''
async with open_cached_client(brokermod.name) as client:
assert client
return await brokermod.get_mkt_info(
fqme.replace(brokermod.name, '')
)