ib: prep for passing `Client` to data reset hacker

Since we want to be able to support user-configurable vnc socketaddrs,
this preps for passing the piker client direct into the vnc hacker
routine so that we can (eventually load) and read the ib brokers config
settings into the client and then read those in the `asyncvnc` task
spawner.
basic_buy_bot
Tyler Goodlet 2023-06-17 14:41:41 -04:00
parent bc58e42a74
commit 909f880211
3 changed files with 19 additions and 8 deletions

View File

@ -21,13 +21,20 @@ runnable script-programs.
''' '''
from __future__ import annotations from __future__ import annotations
from functools import partial from functools import partial
from typing import Literal from typing import (
Literal,
TYPE_CHECKING,
)
import subprocess import subprocess
import tractor import tractor
from .._util import get_logger from .._util import get_logger
if TYPE_CHECKING:
from .api import Client
from ib_insync import IB
log = get_logger('piker.brokers.ib') log = get_logger('piker.brokers.ib')
_reset_tech: Literal[ _reset_tech: Literal[
@ -42,7 +49,8 @@ _reset_tech: Literal[
async def data_reset_hack( async def data_reset_hack(
vnc_host: str, # vnc_host: str,
client: Client,
reset_type: Literal['data', 'connection'], reset_type: Literal['data', 'connection'],
) -> None: ) -> None:

View File

@ -512,9 +512,9 @@ async def open_trade_event_stream(
async with tractor.to_asyncio.open_channel_from( async with tractor.to_asyncio.open_channel_from(
recv_trade_updates, recv_trade_updates,
client=client, client=client,
) as (ibclient, trade_event_stream): ) as (_, trade_event_stream):
assert ibclient is client.ib # assert ibclient is client.ib
task_status.started(trade_event_stream) task_status.started(trade_event_stream)
await trio.sleep_forever() await trio.sleep_forever()

View File

@ -37,6 +37,7 @@ from typing import (
from async_generator import aclosing from async_generator import aclosing
from fuzzywuzzy import process as fuzzy from fuzzywuzzy import process as fuzzy
import ib_insync as ibis
import numpy as np import numpy as np
import pendulum import pendulum
import tractor import tractor
@ -50,10 +51,10 @@ from .._util import (
) )
from .api import ( from .api import (
# _adhoc_futes_set, # _adhoc_futes_set,
Client,
con2fqme, con2fqme,
log, log,
load_aio_clients, load_aio_clients,
ibis,
MethodProxy, MethodProxy,
open_client_proxies, open_client_proxies,
get_preferred_data_client, get_preferred_data_client,
@ -276,7 +277,8 @@ 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 = proxy._aio_ns.ib.client 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:
@ -285,10 +287,11 @@ async def wait_on_data_reset(
log.warning( log.warning(
'Sending DATA RESET request:\n' 'Sending DATA RESET request:\n'
f'{client}' f'{ib_client.client}'
) )
res = await data_reset_hack( res = await data_reset_hack(
vnc_host=client.host, # vnc_host=client.host,
ib_client=ib_client,
reset_type=reset_type, reset_type=reset_type,
) )