ib: pull vnc sockaddrs from brokers.toml config if defined

basic_buy_bot
Tyler Goodlet 2023-06-19 09:54:59 -04:00
parent b28b38afab
commit a149e71fb1
3 changed files with 37 additions and 11 deletions

View File

@ -81,9 +81,20 @@ async def data_reset_hack(
that need to be wrangle. that need to be wrangle.
''' '''
ib_client: IB = client.ib
# look up any user defined vnc socket address mapped from
# a particular API socket port.
api_port: str = str(ib_client.client.port)
vnc_host: str
vnc_port: int
vnc_host, vnc_port = client.conf['vnc_addrs'].get(
api_port,
('localhost', 3003)
)
no_setup_msg:str = ( no_setup_msg:str = (
'No data reset hack test setup for {vnc_host}!\n' f'No data reset hack test setup for {vnc_host}!\n'
'See setup @\n' 'See setup @\n'
'https://github.com/pikers/piker/tree/master/piker/brokers/ib' 'https://github.com/pikers/piker/tree/master/piker/brokers/ib'
) )
@ -96,6 +107,7 @@ async def data_reset_hack(
partial( partial(
vnc_click_hack, vnc_click_hack,
host=vnc_host, host=vnc_host,
port=vnc_port,
) )
) )
except OSError: except OSError:
@ -104,7 +116,7 @@ async def data_reset_hack(
return False return False
try: try:
import i3ipc import i3ipc # noqa (since a deps dynamic check)
except ModuleNotFoundError: except ModuleNotFoundError:
log.warning(no_setup_msg) log.warning(no_setup_msg)
return False return False
@ -128,7 +140,8 @@ async def data_reset_hack(
async def vnc_click_hack( async def vnc_click_hack(
host: str = 'localhost', host: str,
port: int,
reset_type: str = 'data' reset_type: str = 'data'
) -> None: ) -> None:
''' '''
@ -154,8 +167,12 @@ async def vnc_click_hack(
async with asyncvnc.connect( async with asyncvnc.connect(
host, host,
port=3003, port=port,
# TODO: doesn't work see:
# https://github.com/barneygale/asyncvnc/issues/7
# password='ibcansmbz', # password='ibcansmbz',
) as client: ) as client:
# move to middle of screen # move to middle of screen
@ -169,6 +186,11 @@ async def vnc_click_hack(
def i3ipc_xdotool_manual_click_hack() -> None: def i3ipc_xdotool_manual_click_hack() -> None:
'''
Do the data reset hack but expecting a local X-window using `xdotool`.
'''
import i3ipc
i3 = i3ipc.Connection() i3 = i3ipc.Connection()
# TODO: might be worth offering some kinda api for grabbing # TODO: might be worth offering some kinda api for grabbing

View File

@ -385,8 +385,14 @@ class Client:
self, self,
ib: IB, ib: IB,
config: dict[str, Any],
) -> None: ) -> None:
# stash `brokers.toml` config on client for user settings
# as needed throughout this backend (eg. vnc sockaddr).
self.conf = config
self.ib = ib self.ib = ib
self.ib.RaiseRequestErrors = True self.ib.RaiseRequestErrors = True
@ -1267,7 +1273,7 @@ async def load_aio_clients(
''' '''
global _accounts2clients, _client_cache, _scan_ignore global _accounts2clients, _client_cache, _scan_ignore
conf = get_config() conf: dict[str, Any] = get_config()
ib = None ib = None
client = None client = None
@ -1333,7 +1339,7 @@ async def load_aio_clients(
timeout=connect_timeout, timeout=connect_timeout,
) )
# create and cache client # create and cache client
client = Client(ib) client = Client(ib=ib, config=conf)
# update all actor-global caches # update all actor-global caches
log.info(f"Caching client for {sockaddr}") log.info(f"Caching client for {sockaddr}")
@ -1466,7 +1472,7 @@ def get_preferred_data_client(
''' '''
conf = get_config() conf = get_config()
data_accounts = conf['prefer_data_account'] data_accounts: list[str] = conf['prefer_data_account']
for name in data_accounts: for name in data_accounts:
client = clients.get(f'ib.{name}') client = clients.get(f'ib.{name}')

View File

@ -278,7 +278,6 @@ async def wait_on_data_reset(
# try to wait on the reset event(s) to arrive, a timeout # try to wait on the reset event(s) to arrive, a timeout
# will trigger a retry up to 6 times (for now). # will trigger a retry up to 6 times (for now).
client: Client = proxy._aio_ns client: Client = proxy._aio_ns
ib_client: ibis.IB = client.ib
done = trio.Event() done = trio.Event()
with trio.move_on_after(timeout) as cs: with trio.move_on_after(timeout) as cs:
@ -287,11 +286,10 @@ async def wait_on_data_reset(
log.warning( log.warning(
'Sending DATA RESET request:\n' 'Sending DATA RESET request:\n'
f'{ib_client.client}' f'{client.ib.client}'
) )
res = await data_reset_hack( res = await data_reset_hack(
# vnc_host=client.host, client=client,
ib_client=ib_client,
reset_type=reset_type, reset_type=reset_type,
) )