Adjust checker to not require client methods, add `trades_dialogue()` endpoint
parent
d5ffad01b7
commit
d641f77a80
|
@ -21,11 +21,15 @@ import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from typing import (
|
||||||
|
Any,
|
||||||
|
)
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
|
|
||||||
|
# from .._daemon import maybe_open_runtime
|
||||||
from ..cli import cli
|
from ..cli import cli
|
||||||
from .. import watchlists as wl
|
from .. import watchlists as wl
|
||||||
from ..log import get_console_log, colorize_json, get_logger
|
from ..log import get_console_log, colorize_json, get_logger
|
||||||
|
@ -58,44 +62,65 @@ 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):
|
async def run_method(
|
||||||
|
client,
|
||||||
|
meth_name: str,
|
||||||
|
**kwargs,
|
||||||
|
|
||||||
|
) -> Any:
|
||||||
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, f'.{meth_name} does not exist for {client}!'
|
||||||
print_ok('found!, running...', end='', flush=True)
|
print_ok('found!, running...', end='', flush=True)
|
||||||
result = await method(**kwargs)
|
result = await method(**kwargs)
|
||||||
print_ok(f'done! result: {type(result)}')
|
print_ok(f'done! result: {type(result)}')
|
||||||
return 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)
|
||||||
total = 0
|
total = 0
|
||||||
passed = 0
|
passed = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
|
|
||||||
print(f'getting client...', end='', flush=True)
|
print('getting client...', end='', flush=True)
|
||||||
if not hasattr(brokermod, 'get_client'):
|
if not hasattr(brokermod, 'get_client'):
|
||||||
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:
|
# extra_tractor_kwargs = getattr(
|
||||||
print_ok(f'done! inside client context.')
|
# brokermod,
|
||||||
|
# '_spawn_kwargs',
|
||||||
|
# {},
|
||||||
|
# )
|
||||||
|
async with (
|
||||||
|
# TODO: in theory we can actually spawn a local `brokerd`
|
||||||
|
# and then try to make some basic feed queries?
|
||||||
|
# maybe_open_runtime(**extra_tractor_kwargs),
|
||||||
|
brokermod.get_client(is_brokercheck=True) as client,
|
||||||
|
):
|
||||||
|
print_ok('done! inside client context.')
|
||||||
|
|
||||||
# check for methods present on brokermod
|
# check for methods present on brokermod
|
||||||
method_list = [
|
method_list = [
|
||||||
'stream_messages',
|
# not required eps i'm pretty sure?
|
||||||
|
# 'backfill_bars',
|
||||||
|
# 'stream_messages',
|
||||||
|
|
||||||
'open_history_client',
|
'open_history_client',
|
||||||
'backfill_bars',
|
|
||||||
'stream_quotes',
|
'stream_quotes',
|
||||||
'open_symbol_search'
|
'open_symbol_search',
|
||||||
|
'trades_dialogue',
|
||||||
]
|
]
|
||||||
|
|
||||||
for method in method_list:
|
for method in method_list:
|
||||||
print(
|
print(
|
||||||
f'checking brokermod for method \'{method}\'...',
|
f"checking brokermod for method '{method}'...",
|
||||||
end='', flush=True)
|
end='',
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
if not hasattr(brokermod, method):
|
if not hasattr(brokermod, method):
|
||||||
print_error(f'fail! method \'{method}\' not found.')
|
print_error(f"fail! method '{method}' not found.")
|
||||||
failed += 1
|
failed += 1
|
||||||
else:
|
else:
|
||||||
print_ok('done!')
|
print_ok('done!')
|
||||||
|
@ -103,36 +128,42 @@ def brokercheck(config, broker):
|
||||||
|
|
||||||
total += 1
|
total += 1
|
||||||
|
|
||||||
# check for methods present con brokermod.Client and their
|
# check for methods present con brokermod.Client and attempt
|
||||||
# results
|
# to use them and gather output results.
|
||||||
|
|
||||||
syms = await run_method(client, 'symbol_info')
|
symbol_info = getattr(client, 'symbol_info', None)
|
||||||
total += 1
|
if symbol_info:
|
||||||
|
syms = await run_method(
|
||||||
if len(syms) == 0:
|
client,
|
||||||
raise BaseException('Empty Symbol list?')
|
'symbol_info',
|
||||||
|
)
|
||||||
passed += 1
|
|
||||||
|
|
||||||
first_sym = tuple(syms.keys())[0]
|
|
||||||
|
|
||||||
method_list = [
|
|
||||||
('cache_symbols', {}),
|
|
||||||
('search_symbols', {'pattern': first_sym[:-1]}),
|
|
||||||
('bars', {'symbol': first_sym})
|
|
||||||
]
|
|
||||||
|
|
||||||
for method_name, method_kwargs in method_list:
|
|
||||||
try:
|
|
||||||
await run_method(client, method_name, **method_kwargs)
|
|
||||||
passed += 1
|
|
||||||
|
|
||||||
except AssertionError:
|
|
||||||
print_error(f'fail! method \'{method_name}\' not found.')
|
|
||||||
failed += 1
|
|
||||||
|
|
||||||
total += 1
|
total += 1
|
||||||
|
|
||||||
|
if len(syms) == 0:
|
||||||
|
raise BaseException('Empty Symbol list?')
|
||||||
|
|
||||||
|
passed += 1
|
||||||
|
|
||||||
|
first_sym = tuple(syms.keys())[0]
|
||||||
|
|
||||||
|
method_list = [
|
||||||
|
('cache_symbols', {}),
|
||||||
|
('search_symbols', {'pattern': first_sym[:-1]}),
|
||||||
|
('bars', {'symbol': first_sym})
|
||||||
|
]
|
||||||
|
|
||||||
|
for method_name, method_kwargs in method_list:
|
||||||
|
try:
|
||||||
|
await run_method(client, method_name, **method_kwargs)
|
||||||
|
passed += 1
|
||||||
|
|
||||||
|
except AssertionError:
|
||||||
|
print_error(f'fail! method \'{method_name}\' not found.')
|
||||||
|
failed += 1
|
||||||
|
|
||||||
|
total += 1
|
||||||
|
|
||||||
print(f'total: {total}, passed: {passed}, failed: {failed}')
|
print(f'total: {total}, passed: {passed}, failed: {failed}')
|
||||||
|
|
||||||
trio.run(run_test, broker)
|
trio.run(run_test, broker)
|
||||||
|
|
Loading…
Reference in New Issue