Add brokercheck guard on deribit.get_client && drop method running in brokercheck

size_in_shm_token
Guillermo Rodriguez 2022-08-24 19:32:54 -03:00
parent e97dd1cbdb
commit accb0eee6c
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
2 changed files with 31 additions and 27 deletions

View File

@ -58,14 +58,12 @@ def brokercheck(config, broker):
def print_error(s: str, **kwargs): def print_error(s: str, **kwargs):
print(FAIL + s + ENDC, **kwargs) print(FAIL + s + ENDC, **kwargs)
async def run_method(client, meth_name: str, **kwargs): def get_method(client, meth_name: str):
print(f'checking client for method \'{meth_name}\'...', end='', flush=True) print(f'checking client for method \'{meth_name}\'...', end='', flush=True)
method = getattr(client, meth_name, None) method = getattr(client, meth_name, None)
assert method assert method
print_ok('found!, running...', end='', flush=True) print_ok('found!.')
result = await method(**kwargs) return method
print_ok(f'done! result: {type(result)}')
return result
async def run_test(broker_name: str): async def run_test(broker_name: str):
brokermod = get_brokermod(broker_name) brokermod = get_brokermod(broker_name)
@ -78,16 +76,18 @@ def brokercheck(config, broker):
print_error('fail! no \'get_client\' context manager found.') print_error('fail! no \'get_client\' context manager found.')
return return
async with brokermod.get_client() as client: async with brokermod.get_client(is_brokercheck=True) as client:
print_ok(f'done! inside client context.') print_ok(f'done! inside client context.')
# check for methods present on brokermod # check for methods present on brokermod
method_list = [ method_list = [
'stream_messages',
'open_history_client',
'backfill_bars', 'backfill_bars',
'get_client',
'trades_dialogue',
'open_history_client',
'open_symbol_search',
'stream_quotes', 'stream_quotes',
'open_symbol_search'
] ]
for method in method_list: for method in method_list:
@ -106,25 +106,22 @@ def brokercheck(config, broker):
# check for methods present con brokermod.Client and their # check for methods present con brokermod.Client and their
# results # results
syms = await run_method(client, 'symbol_info') # for private methods only check is present
total += 1
if len(syms) == 0:
raise BaseException('Empty Symbol list?')
passed += 1
first_sym = tuple(syms.keys())[0]
method_list = [ method_list = [
('cache_symbols', {}), 'get_balances',
('search_symbols', {'pattern': first_sym[:-1]}), 'get_assets',
('bars', {'symbol': first_sym}) 'get_trades',
'get_xfers',
'submit_limit',
'submit_cancel',
'cache_symbols',
'search_symbols',
'bars'
] ]
for method_name, method_kwargs in method_list: for method_name in method_list:
try: try:
await run_method(client, method_name, **method_kwargs) get_method(client, method_name)
passed += 1 passed += 1
except AssertionError: except AssertionError:

View File

@ -410,7 +410,14 @@ class Client:
@acm @acm
async def get_client() -> Client: async def get_client(
is_brokercheck: bool = False
) -> Client:
if is_brokercheck:
yield Client
return
async with ( async with (
trio.open_nursery() as n, trio.open_nursery() as n,
open_autorecon_ws(_testnet_ws_url) as ws open_autorecon_ws(_testnet_ws_url) as ws