Move UI spawning cmds to new module
parent
42aa2bce5b
commit
489e8c226f
|
@ -130,49 +130,6 @@ def bars(config, symbol, count, df_output):
|
||||||
click.echo(colorize_json(bars))
|
click.echo(colorize_json(bars))
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
|
||||||
@click.option('--rate', '-r', default=3, help='Quote rate limit')
|
|
||||||
@click.option('--test', '-t', help='Test quote stream file')
|
|
||||||
@click.option('--dhost', '-dh', default='127.0.0.1',
|
|
||||||
help='Daemon host address to connect to')
|
|
||||||
@click.argument('name', nargs=1, required=True)
|
|
||||||
@click.pass_obj
|
|
||||||
def monitor(config, rate, name, dhost, test, tl):
|
|
||||||
"""Start a real-time watchlist UI
|
|
||||||
"""
|
|
||||||
# global opts
|
|
||||||
brokermod = config['brokermod']
|
|
||||||
loglevel = config['loglevel']
|
|
||||||
log = config['log']
|
|
||||||
|
|
||||||
watchlist_from_file = wl.ensure_watchlists(_watchlists_data_path)
|
|
||||||
watchlists = wl.merge_watchlist(watchlist_from_file, wl._builtins)
|
|
||||||
tickers = watchlists[name]
|
|
||||||
if not tickers:
|
|
||||||
log.error(f"No symbols found for watchlist `{name}`?")
|
|
||||||
return
|
|
||||||
|
|
||||||
from ..ui.monitor import _async_main
|
|
||||||
|
|
||||||
async def main(tries):
|
|
||||||
async with maybe_spawn_brokerd_as_subactor(
|
|
||||||
tries=tries, loglevel=loglevel
|
|
||||||
) as portal:
|
|
||||||
# run app "main"
|
|
||||||
await _async_main(
|
|
||||||
name, portal, tickers,
|
|
||||||
brokermod, rate, test=test,
|
|
||||||
)
|
|
||||||
|
|
||||||
tractor.run(
|
|
||||||
partial(main, tries=1),
|
|
||||||
name='monitor',
|
|
||||||
loglevel=loglevel if tl else None,
|
|
||||||
rpc_module_paths=['piker.ui.monitor'],
|
|
||||||
start_method='forkserver',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option('--rate', '-r', default=5, help='Logging level')
|
@click.option('--rate', '-r', default=5, help='Logging level')
|
||||||
|
@ -268,40 +225,3 @@ def optsquote(config, symbol, df_output, date):
|
||||||
click.echo(df)
|
click.echo(df)
|
||||||
else:
|
else:
|
||||||
click.echo(colorize_json(quotes))
|
click.echo(colorize_json(quotes))
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
|
||||||
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
|
||||||
@click.option('--date', '-d', help='Contracts expiry date')
|
|
||||||
@click.option('--test', '-t', help='Test quote stream file')
|
|
||||||
@click.option('--rate', '-r', default=1, help='Logging level')
|
|
||||||
@click.argument('symbol', required=True)
|
|
||||||
@click.pass_obj
|
|
||||||
def optschain(config, symbol, date, tl, rate, test):
|
|
||||||
"""Start an option chain UI
|
|
||||||
"""
|
|
||||||
# global opts
|
|
||||||
loglevel = config['loglevel']
|
|
||||||
brokername = config['broker']
|
|
||||||
|
|
||||||
from ..ui.option_chain import _async_main
|
|
||||||
|
|
||||||
async def main(tries):
|
|
||||||
async with maybe_spawn_brokerd_as_subactor(
|
|
||||||
tries=tries, loglevel=loglevel
|
|
||||||
):
|
|
||||||
# run app "main"
|
|
||||||
await _async_main(
|
|
||||||
symbol,
|
|
||||||
brokername,
|
|
||||||
rate=rate,
|
|
||||||
loglevel=loglevel,
|
|
||||||
test=test,
|
|
||||||
)
|
|
||||||
|
|
||||||
tractor.run(
|
|
||||||
partial(main, tries=1),
|
|
||||||
name='kivy-options-chain',
|
|
||||||
loglevel=loglevel if tl else None,
|
|
||||||
start_method='forkserver',
|
|
||||||
)
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ _config_dir = click.get_app_dir('piker')
|
||||||
_watchlists_data_path = os.path.join(_config_dir, 'watchlists.json')
|
_watchlists_data_path = os.path.join(_config_dir, 'watchlists.json')
|
||||||
_context_defaults = dict(
|
_context_defaults = dict(
|
||||||
default_map={
|
default_map={
|
||||||
|
# Questrade specific quote poll rates
|
||||||
'monitor': {
|
'monitor': {
|
||||||
'rate': 3,
|
'rate': 3,
|
||||||
},
|
},
|
||||||
|
@ -66,5 +67,6 @@ def cli(ctx, broker, loglevel, configdir):
|
||||||
|
|
||||||
# load downstream cli modules
|
# load downstream cli modules
|
||||||
from ..brokers import cli as _
|
from ..brokers import cli as _
|
||||||
|
from ..ui import cli as _
|
||||||
from ..watchlists import cli as _
|
from ..watchlists import cli as _
|
||||||
from ..data import marketstore as _
|
from ..data import marketstore as _
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
"""
|
|
||||||
Stuff for your eyes.
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# XXX clear all flags at import to avoid upsetting
|
|
||||||
# ol' kivy see: https://github.com/kivy/kivy/issues/4225
|
|
||||||
# though this is likely a ``click`` problem
|
|
||||||
sys.argv[1:] = []
|
|
||||||
|
|
||||||
# use the trio async loop
|
|
||||||
os.environ['KIVY_EVENTLOOP'] = 'trio'
|
|
||||||
import kivy
|
|
||||||
kivy.require('1.10.0')
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
"""
|
||||||
|
Console interface to UI components.
|
||||||
|
"""
|
||||||
|
from functools import partial
|
||||||
|
import os
|
||||||
|
import click
|
||||||
|
import tractor
|
||||||
|
|
||||||
|
from ..cli import cli
|
||||||
|
from .. import watchlists as wl
|
||||||
|
from ..brokers.core import maybe_spawn_brokerd_as_subactor
|
||||||
|
|
||||||
|
|
||||||
|
_config_dir = click.get_app_dir('piker')
|
||||||
|
_watchlists_data_path = os.path.join(_config_dir, 'watchlists.json')
|
||||||
|
|
||||||
|
|
||||||
|
def _kivy_import_hack():
|
||||||
|
# Command line hacks to make it work.
|
||||||
|
# See the pkg mod.
|
||||||
|
from .kivy import kivy # noqa
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
||||||
|
@click.option('--rate', '-r', default=3, help='Quote rate limit')
|
||||||
|
@click.option('--test', '-t', help='Test quote stream file')
|
||||||
|
@click.option('--dhost', '-dh', default='127.0.0.1',
|
||||||
|
help='Daemon host address to connect to')
|
||||||
|
@click.argument('name', nargs=1, required=True)
|
||||||
|
@click.pass_obj
|
||||||
|
def monitor(config, rate, name, dhost, test, tl):
|
||||||
|
"""Start a real-time watchlist UI
|
||||||
|
"""
|
||||||
|
# global opts
|
||||||
|
brokermod = config['brokermod']
|
||||||
|
loglevel = config['loglevel']
|
||||||
|
log = config['log']
|
||||||
|
|
||||||
|
watchlist_from_file = wl.ensure_watchlists(_watchlists_data_path)
|
||||||
|
watchlists = wl.merge_watchlist(watchlist_from_file, wl._builtins)
|
||||||
|
tickers = watchlists[name]
|
||||||
|
if not tickers:
|
||||||
|
log.error(f"No symbols found for watchlist `{name}`?")
|
||||||
|
return
|
||||||
|
|
||||||
|
_kivy_import_hack()
|
||||||
|
from .monitor import _async_main
|
||||||
|
|
||||||
|
async def main(tries):
|
||||||
|
async with maybe_spawn_brokerd_as_subactor(
|
||||||
|
tries=tries, loglevel=loglevel
|
||||||
|
) as portal:
|
||||||
|
# run app "main"
|
||||||
|
await _async_main(
|
||||||
|
name, portal, tickers,
|
||||||
|
brokermod, rate, test=test,
|
||||||
|
)
|
||||||
|
|
||||||
|
tractor.run(
|
||||||
|
partial(main, tries=1),
|
||||||
|
name='monitor',
|
||||||
|
loglevel=loglevel if tl else None,
|
||||||
|
rpc_module_paths=['piker.ui.monitor'],
|
||||||
|
start_method='forkserver',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.option('--tl', is_flag=True, help='Enable tractor logging')
|
||||||
|
@click.option('--date', '-d', help='Contracts expiry date')
|
||||||
|
@click.option('--test', '-t', help='Test quote stream file')
|
||||||
|
@click.option('--rate', '-r', default=1, help='Logging level')
|
||||||
|
@click.argument('symbol', required=True)
|
||||||
|
@click.pass_obj
|
||||||
|
def optschain(config, symbol, date, tl, rate, test):
|
||||||
|
"""Start an option chain UI
|
||||||
|
"""
|
||||||
|
# global opts
|
||||||
|
loglevel = config['loglevel']
|
||||||
|
brokername = config['broker']
|
||||||
|
|
||||||
|
_kivy_import_hack()
|
||||||
|
from .option_chain import _async_main
|
||||||
|
|
||||||
|
async def main(tries):
|
||||||
|
async with maybe_spawn_brokerd_as_subactor(
|
||||||
|
tries=tries, loglevel=loglevel
|
||||||
|
):
|
||||||
|
# run app "main"
|
||||||
|
await _async_main(
|
||||||
|
symbol,
|
||||||
|
brokername,
|
||||||
|
rate=rate,
|
||||||
|
loglevel=loglevel,
|
||||||
|
test=test,
|
||||||
|
)
|
||||||
|
|
||||||
|
tractor.run(
|
||||||
|
partial(main, tries=1),
|
||||||
|
name='kivy-options-chain',
|
||||||
|
loglevel=loglevel if tl else None,
|
||||||
|
start_method='forkserver',
|
||||||
|
)
|
|
@ -0,0 +1,15 @@
|
||||||
|
"""
|
||||||
|
Legacy kivy components.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# XXX clear all flags at import to avoid upsetting
|
||||||
|
# ol' kivy see: https://github.com/kivy/kivy/issues/4225
|
||||||
|
# though this is likely a ``click`` problem
|
||||||
|
sys.argv[1:] = []
|
||||||
|
|
||||||
|
# use the trio async loop
|
||||||
|
os.environ['KIVY_EVENTLOOP'] = 'trio'
|
||||||
|
import kivy
|
||||||
|
kivy.require('1.10.0')
|
Loading…
Reference in New Issue