From 2ad3b6f080b322698b1a79059d62ac7b2ba5b9f8 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 10 Jun 2020 13:56:09 -0400 Subject: [PATCH] Add piker chart command --- piker/ui/cli.py | 32 ++++++++++++++++++++++++++++++++ piker/ui/qt/__init__.py | 3 +++ piker/ui/qt/_exec.py | 22 ---------------------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/piker/ui/cli.py b/piker/ui/cli.py index a869e307..d5f6a9ed 100644 --- a/piker/ui/cli.py +++ b/piker/ui/cli.py @@ -1,9 +1,11 @@ """ Console interface to UI components. """ +from datetime import datetime from functools import partial import os import click +import trio import tractor from ..cli import cli @@ -103,3 +105,33 @@ def optschain(config, symbol, date, tl, rate, test): loglevel=loglevel if tl else None, 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 chart(config, symbol, date, tl, rate, test): + """Start an option chain UI + """ + from .qt._exec import run_qtrio + from .qt._chart import QuotesTabWidget + from .qt.quantdom.base import Symbol + from .qt.quantdom.loaders import get_quotes + + async def plot_symbol(widgets): + qtw = widgets['main'] + s = Symbol(ticker=symbol, mode=Symbol.SHARES) + get_quotes( + symbol=s.ticker, + date_from=datetime(1900, 1, 1), + date_to=datetime(2030, 12, 31), + ) + # spawn chart + qtw.update_chart(s) + await trio.sleep_forever() + + run_qtrio(plot_symbol, (), QuotesTabWidget) diff --git a/piker/ui/qt/__init__.py b/piker/ui/qt/__init__.py index e69de29b..8513b317 100644 --- a/piker/ui/qt/__init__.py +++ b/piker/ui/qt/__init__.py @@ -0,0 +1,3 @@ +""" +Super hawt Qt UI components +""" diff --git a/piker/ui/qt/_exec.py b/piker/ui/qt/_exec.py index 90286681..41b216d3 100644 --- a/piker/ui/qt/_exec.py +++ b/piker/ui/qt/_exec.py @@ -5,7 +5,6 @@ Run ``trio`` in guest mode on top of the Qt event loop. All global Qt runtime settings are mostly defined here. """ import traceback -from datetime import datetime import PyQt5 # noqa from pyqtgraph import QtGui @@ -15,10 +14,6 @@ import qdarkstyle import trio from outcome import Error -from _chart import QuotesTabWidget -from quantdom.base import Symbol -from quantdom.loaders import get_quotes - # Taken from Quantdom class MainWindow(QtGui.QMainWindow): @@ -98,20 +93,3 @@ def run_qtrio( window.setCentralWidget(instance) window.show() app.exec_() - - -async def plot_aapl(widgets): - qtw = widgets['main'] - s = Symbol(ticker='AAPL', mode=Symbol.SHARES) - get_quotes( - symbol=s.ticker, - date_from=datetime(1900, 1, 1), - date_to=datetime(2030, 12, 31), - ) - # spawn chart - qtw.update_chart(s) - await trio.sleep_forever() - - -if __name__ == '__main__': - run_qtrio(plot_aapl, (), QuotesTabWidget)