Merge pull request #417 from pikers/daemon_sockaddr_config
Daemon sockaddr configpre_multifeed_hotfix
commit
a44b8e3e22
|
@ -18,3 +18,10 @@
|
||||||
piker: trading gear for hackers.
|
piker: trading gear for hackers.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from ._daemon import open_piker_runtime
|
||||||
|
from .data.feed import open_feed
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'open_piker_runtime',
|
||||||
|
'open_feed',
|
||||||
|
]
|
||||||
|
|
|
@ -35,7 +35,12 @@ log = get_logger(__name__)
|
||||||
|
|
||||||
_root_dname = 'pikerd'
|
_root_dname = 'pikerd'
|
||||||
|
|
||||||
_registry_addr = ('127.0.0.1', 6116)
|
_registry_host: str = '127.0.0.1'
|
||||||
|
_registry_port: int = 6116
|
||||||
|
_registry_addr = (
|
||||||
|
_registry_host,
|
||||||
|
_registry_port,
|
||||||
|
)
|
||||||
_tractor_kwargs: dict[str, Any] = {
|
_tractor_kwargs: dict[str, Any] = {
|
||||||
# use a different registry addr then tractor's default
|
# use a different registry addr then tractor's default
|
||||||
'arbiter_addr': _registry_addr
|
'arbiter_addr': _registry_addr
|
||||||
|
@ -135,6 +140,7 @@ async def open_pikerd(
|
||||||
# XXX: you should pretty much never want debug mode
|
# XXX: you should pretty much never want debug mode
|
||||||
# for data daemons when running in production.
|
# for data daemons when running in production.
|
||||||
debug_mode: bool = False,
|
debug_mode: bool = False,
|
||||||
|
registry_addr: None | tuple[str, int] = None,
|
||||||
|
|
||||||
) -> Optional[tractor._portal.Portal]:
|
) -> Optional[tractor._portal.Portal]:
|
||||||
'''
|
'''
|
||||||
|
@ -146,14 +152,13 @@ async def open_pikerd(
|
||||||
|
|
||||||
'''
|
'''
|
||||||
global _services
|
global _services
|
||||||
assert _services is None
|
|
||||||
|
|
||||||
# XXX: this may open a root actor as well
|
# XXX: this may open a root actor as well
|
||||||
async with (
|
async with (
|
||||||
tractor.open_root_actor(
|
tractor.open_root_actor(
|
||||||
|
|
||||||
# passed through to ``open_root_actor``
|
# passed through to ``open_root_actor``
|
||||||
arbiter_addr=_registry_addr,
|
arbiter_addr=registry_addr or _registry_addr,
|
||||||
name=_root_dname,
|
name=_root_dname,
|
||||||
loglevel=loglevel,
|
loglevel=loglevel,
|
||||||
debug_mode=debug_mode,
|
debug_mode=debug_mode,
|
||||||
|
@ -192,22 +197,22 @@ async def open_piker_runtime(
|
||||||
# XXX: you should pretty much never want debug mode
|
# XXX: you should pretty much never want debug mode
|
||||||
# for data daemons when running in production.
|
# for data daemons when running in production.
|
||||||
debug_mode: bool = False,
|
debug_mode: bool = False,
|
||||||
|
registry_addr: None | tuple[str, int] = _registry_addr,
|
||||||
|
|
||||||
) -> Optional[tractor._portal.Portal]:
|
) -> tractor.Actor:
|
||||||
'''
|
'''
|
||||||
Start a piker actor who's runtime will automatically sync with
|
Start a piker actor who's runtime will automatically sync with
|
||||||
existing piker actors on the local link based on configuration.
|
existing piker actors on the local link based on configuration.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
global _services
|
global _services
|
||||||
assert _services is None
|
|
||||||
|
|
||||||
# XXX: this may open a root actor as well
|
# XXX: this may open a root actor as well
|
||||||
async with (
|
async with (
|
||||||
tractor.open_root_actor(
|
tractor.open_root_actor(
|
||||||
|
|
||||||
# passed through to ``open_root_actor``
|
# passed through to ``open_root_actor``
|
||||||
arbiter_addr=_registry_addr,
|
arbiter_addr=registry_addr,
|
||||||
name=name,
|
name=name,
|
||||||
loglevel=loglevel,
|
loglevel=loglevel,
|
||||||
debug_mode=debug_mode,
|
debug_mode=debug_mode,
|
||||||
|
@ -248,6 +253,7 @@ async def maybe_open_runtime(
|
||||||
@acm
|
@acm
|
||||||
async def maybe_open_pikerd(
|
async def maybe_open_pikerd(
|
||||||
loglevel: Optional[str] = None,
|
loglevel: Optional[str] = None,
|
||||||
|
registry_addr: None | tuple = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
|
||||||
) -> Union[tractor._portal.Portal, Services]:
|
) -> Union[tractor._portal.Portal, Services]:
|
||||||
|
@ -260,11 +266,19 @@ async def maybe_open_pikerd(
|
||||||
get_console_log(loglevel)
|
get_console_log(loglevel)
|
||||||
|
|
||||||
# subtle, we must have the runtime up here or portal lookup will fail
|
# subtle, we must have the runtime up here or portal lookup will fail
|
||||||
async with maybe_open_runtime(loglevel, **kwargs):
|
async with (
|
||||||
|
maybe_open_runtime(loglevel, **kwargs),
|
||||||
async with tractor.find_actor(_root_dname) as portal:
|
tractor.find_actor(_root_dname) as portal
|
||||||
# assert portal is not None
|
):
|
||||||
if portal is not None:
|
# connect to any existing daemon presuming
|
||||||
|
# its registry socket was selected.
|
||||||
|
if (
|
||||||
|
portal is not None
|
||||||
|
and (
|
||||||
|
registry_addr is None
|
||||||
|
or portal.channel.raddr == registry_addr
|
||||||
|
)
|
||||||
|
):
|
||||||
yield portal
|
yield portal
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -274,6 +288,7 @@ async def maybe_open_pikerd(
|
||||||
|
|
||||||
loglevel=loglevel,
|
loglevel=loglevel,
|
||||||
debug_mode=kwargs.get('debug_mode', False),
|
debug_mode=kwargs.get('debug_mode', False),
|
||||||
|
registry_addr=registry_addr,
|
||||||
|
|
||||||
) as _:
|
) as _:
|
||||||
# in the case where we're starting up the
|
# in the case where we're starting up the
|
||||||
|
|
|
@ -27,7 +27,11 @@ import tractor
|
||||||
|
|
||||||
from ..log import get_console_log, get_logger, colorize_json
|
from ..log import get_console_log, get_logger, colorize_json
|
||||||
from ..brokers import get_brokermod
|
from ..brokers import get_brokermod
|
||||||
from .._daemon import _tractor_kwargs
|
from .._daemon import (
|
||||||
|
_tractor_kwargs,
|
||||||
|
_registry_host,
|
||||||
|
_registry_port,
|
||||||
|
)
|
||||||
from .. import config
|
from .. import config
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,13 +43,21 @@ DEFAULT_BROKER = 'questrade'
|
||||||
@click.option('--loglevel', '-l', default='warning', help='Logging level')
|
@click.option('--loglevel', '-l', default='warning', help='Logging level')
|
||||||
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
||||||
@click.option('--pdb', is_flag=True, help='Enable tractor debug mode')
|
@click.option('--pdb', is_flag=True, help='Enable tractor debug mode')
|
||||||
@click.option('--host', '-h', default='127.0.0.1', help='Host address to bind')
|
@click.option('--host', '-h', default=None, help='Host addr to bind')
|
||||||
|
@click.option('--port', '-p', default=None, help='Port number to bind')
|
||||||
@click.option(
|
@click.option(
|
||||||
'--tsdb',
|
'--tsdb',
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
help='Enable local ``marketstore`` instance'
|
help='Enable local ``marketstore`` instance'
|
||||||
)
|
)
|
||||||
def pikerd(loglevel, host, tl, pdb, tsdb):
|
def pikerd(
|
||||||
|
loglevel: str,
|
||||||
|
host: str,
|
||||||
|
port: int,
|
||||||
|
tl: bool,
|
||||||
|
pdb: bool,
|
||||||
|
tsdb: bool,
|
||||||
|
):
|
||||||
'''
|
'''
|
||||||
Spawn the piker broker-daemon.
|
Spawn the piker broker-daemon.
|
||||||
|
|
||||||
|
@ -62,12 +74,21 @@ def pikerd(loglevel, host, tl, pdb, tsdb):
|
||||||
"\n"
|
"\n"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
reg_addr: None | tuple[str, int] = None
|
||||||
|
if host or port:
|
||||||
|
reg_addr = (
|
||||||
|
host or _registry_host,
|
||||||
|
int(port) or _registry_port,
|
||||||
|
)
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
open_pikerd(
|
open_pikerd(
|
||||||
loglevel=loglevel,
|
loglevel=loglevel,
|
||||||
debug_mode=pdb,
|
debug_mode=pdb,
|
||||||
|
registry_addr=reg_addr,
|
||||||
|
|
||||||
), # normally delivers a ``Services`` handle
|
), # normally delivers a ``Services`` handle
|
||||||
trio.open_nursery() as n,
|
trio.open_nursery() as n,
|
||||||
):
|
):
|
||||||
|
@ -104,8 +125,19 @@ def pikerd(loglevel, host, tl, pdb, tsdb):
|
||||||
@click.option('--loglevel', '-l', default='warning', help='Logging level')
|
@click.option('--loglevel', '-l', default='warning', help='Logging level')
|
||||||
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
||||||
@click.option('--configdir', '-c', help='Configuration directory')
|
@click.option('--configdir', '-c', help='Configuration directory')
|
||||||
|
@click.option('--host', '-h', default=None, help='Host addr to bind')
|
||||||
|
@click.option('--port', '-p', default=None, help='Port number to bind')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx, brokers, loglevel, tl, configdir):
|
def cli(
|
||||||
|
ctx: click.Context,
|
||||||
|
brokers: list[str],
|
||||||
|
loglevel: str,
|
||||||
|
tl: bool,
|
||||||
|
configdir: str,
|
||||||
|
host: str,
|
||||||
|
port: int,
|
||||||
|
|
||||||
|
) -> None:
|
||||||
if configdir is not None:
|
if configdir is not None:
|
||||||
assert os.path.isdir(configdir), f"`{configdir}` is not a valid path"
|
assert os.path.isdir(configdir), f"`{configdir}` is not a valid path"
|
||||||
config._override_config_dir(configdir)
|
config._override_config_dir(configdir)
|
||||||
|
@ -117,6 +149,13 @@ def cli(ctx, brokers, loglevel, tl, configdir):
|
||||||
else:
|
else:
|
||||||
brokermods = [get_brokermod(broker) for broker in brokers]
|
brokermods = [get_brokermod(broker) for broker in brokers]
|
||||||
|
|
||||||
|
reg_addr: None | tuple[str, int] = None
|
||||||
|
if host or port:
|
||||||
|
reg_addr = (
|
||||||
|
host or _registry_host,
|
||||||
|
int(port) or _registry_port,
|
||||||
|
)
|
||||||
|
|
||||||
ctx.obj.update({
|
ctx.obj.update({
|
||||||
'brokers': brokers,
|
'brokers': brokers,
|
||||||
'brokermods': brokermods,
|
'brokermods': brokermods,
|
||||||
|
@ -125,6 +164,7 @@ def cli(ctx, brokers, loglevel, tl, configdir):
|
||||||
'log': get_console_log(loglevel),
|
'log': get_console_log(loglevel),
|
||||||
'confdir': config._config_dir,
|
'confdir': config._config_dir,
|
||||||
'wl_path': config._watchlists_data_path,
|
'wl_path': config._watchlists_data_path,
|
||||||
|
'registry_addr': reg_addr,
|
||||||
})
|
})
|
||||||
|
|
||||||
# allow enabling same loglevel in ``tractor`` machinery
|
# allow enabling same loglevel in ``tractor`` machinery
|
||||||
|
|
|
@ -46,8 +46,10 @@ def _kivy_import_hack():
|
||||||
@click.argument('name', nargs=1, required=True)
|
@click.argument('name', nargs=1, required=True)
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def monitor(config, rate, name, dhost, test, tl):
|
def monitor(config, rate, name, dhost, test, tl):
|
||||||
"""Start a real-time watchlist UI
|
'''
|
||||||
"""
|
Start a real-time watchlist UI
|
||||||
|
|
||||||
|
'''
|
||||||
# global opts
|
# global opts
|
||||||
brokermod = config['brokermods'][0]
|
brokermod = config['brokermods'][0]
|
||||||
loglevel = config['loglevel']
|
loglevel = config['loglevel']
|
||||||
|
@ -70,8 +72,12 @@ def monitor(config, rate, name, dhost, test, tl):
|
||||||
) as portal:
|
) as portal:
|
||||||
# run app "main"
|
# run app "main"
|
||||||
await _async_main(
|
await _async_main(
|
||||||
name, portal, tickers,
|
name,
|
||||||
brokermod, rate, test=test,
|
portal,
|
||||||
|
tickers,
|
||||||
|
brokermod,
|
||||||
|
rate,
|
||||||
|
test=test,
|
||||||
)
|
)
|
||||||
|
|
||||||
tractor.run(
|
tractor.run(
|
||||||
|
@ -122,7 +128,7 @@ def optschain(config, symbol, date, rate, test):
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option(
|
@click.option(
|
||||||
'--profile',
|
'--profile',
|
||||||
'-p',
|
# '-p',
|
||||||
default=None,
|
default=None,
|
||||||
help='Enable pyqtgraph profiling'
|
help='Enable pyqtgraph profiling'
|
||||||
)
|
)
|
||||||
|
@ -131,9 +137,14 @@ def optschain(config, symbol, date, rate, test):
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
help='Enable tractor debug mode'
|
help='Enable tractor debug mode'
|
||||||
)
|
)
|
||||||
@click.argument('symbol', required=True)
|
@click.argument('symbols', nargs=-1, required=True)
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def chart(config, symbol, profile, pdb):
|
def chart(
|
||||||
|
config,
|
||||||
|
symbols: list[str],
|
||||||
|
profile,
|
||||||
|
pdb: bool,
|
||||||
|
):
|
||||||
'''
|
'''
|
||||||
Start a real-time chartng UI
|
Start a real-time chartng UI
|
||||||
|
|
||||||
|
@ -144,8 +155,10 @@ def chart(config, symbol, profile, pdb):
|
||||||
_profile._pg_profile = True
|
_profile._pg_profile = True
|
||||||
_profile.ms_slower_then = float(profile)
|
_profile.ms_slower_then = float(profile)
|
||||||
|
|
||||||
|
# Qt UI entrypoint
|
||||||
from ._app import _main
|
from ._app import _main
|
||||||
|
|
||||||
|
for symbol in symbols:
|
||||||
if '.' not in symbol:
|
if '.' not in symbol:
|
||||||
click.echo(click.style(
|
click.echo(click.style(
|
||||||
f'symbol: {symbol} must have a {symbol}.<provider> suffix',
|
f'symbol: {symbol} must have a {symbol}.<provider> suffix',
|
||||||
|
@ -159,8 +172,9 @@ def chart(config, symbol, profile, pdb):
|
||||||
tractorloglevel = config['tractorloglevel']
|
tractorloglevel = config['tractorloglevel']
|
||||||
pikerloglevel = config['loglevel']
|
pikerloglevel = config['loglevel']
|
||||||
|
|
||||||
|
|
||||||
_main(
|
_main(
|
||||||
sym=symbol,
|
syms=symbols,
|
||||||
brokernames=brokernames,
|
brokernames=brokernames,
|
||||||
piker_loglevel=pikerloglevel,
|
piker_loglevel=pikerloglevel,
|
||||||
tractor_kwargs={
|
tractor_kwargs={
|
||||||
|
@ -170,5 +184,6 @@ def chart(config, symbol, profile, pdb):
|
||||||
'enable_modules': [
|
'enable_modules': [
|
||||||
'piker.clearing._client'
|
'piker.clearing._client'
|
||||||
],
|
],
|
||||||
|
'registry_addr': config.get('registry_addr'),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue