Compare commits
No commits in common. "9d01b5367b6a3580c64529ae2e3d5cca5e4e236e" and "feb25af8b86012f4e02f678092b2e94a892f8428" have entirely different histories.
9d01b5367b
...
feb25af8b8
|
|
@ -24,7 +24,6 @@ from functools import partial
|
|||
from typing import (
|
||||
AsyncIterator,
|
||||
Callable,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
|
|
@ -34,12 +33,12 @@ import tractor
|
|||
from tractor.msg import NamespacePath
|
||||
|
||||
from piker.types import Struct
|
||||
from ..log import (
|
||||
get_logger,
|
||||
get_console_log,
|
||||
)
|
||||
from ..log import get_logger, get_console_log
|
||||
from .. import data
|
||||
from ..data.flows import Flume
|
||||
from ..data.feed import (
|
||||
Flume,
|
||||
Feed,
|
||||
)
|
||||
from ..data._sharedmem import ShmArray
|
||||
from ..data._sampling import (
|
||||
_default_delay_s,
|
||||
|
|
@ -53,9 +52,6 @@ from ._api import (
|
|||
)
|
||||
from ..toolz import Profiler
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..data.feed import Feed
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
|
|
@ -173,10 +169,8 @@ class Cascade(Struct):
|
|||
if not synced:
|
||||
fsp: Fsp = self.fsp
|
||||
log.warning(
|
||||
f'***DESYNCED fsp***\n'
|
||||
f'------------------\n'
|
||||
f'ns-path: {fsp.ns_path!r}\n'
|
||||
f'shm-token: {src_shm.token}\n'
|
||||
'***DESYNCED FSP***\n'
|
||||
f'{fsp.ns_path}@{src_shm.token}\n'
|
||||
f'step_diff: {step_diff}\n'
|
||||
f'len_diff: {len_diff}\n'
|
||||
)
|
||||
|
|
@ -404,6 +398,7 @@ async def connect_streams(
|
|||
|
||||
@tractor.context
|
||||
async def cascade(
|
||||
|
||||
ctx: tractor.Context,
|
||||
|
||||
# data feed key
|
||||
|
|
@ -417,7 +412,7 @@ async def cascade(
|
|||
shm_registry: dict[str, _Token],
|
||||
|
||||
zero_on_step: bool = False,
|
||||
loglevel: str|None = None,
|
||||
loglevel: str | None = None,
|
||||
|
||||
) -> None:
|
||||
'''
|
||||
|
|
@ -431,17 +426,7 @@ async def cascade(
|
|||
)
|
||||
|
||||
if loglevel:
|
||||
log = get_console_log(
|
||||
loglevel,
|
||||
name=__name__,
|
||||
)
|
||||
# XXX TODO!
|
||||
# figure out why this writes a dict to,
|
||||
# `tractor._state._runtime_vars['_root_mailbox']`
|
||||
# XD .. wtf
|
||||
# TODO, solve this as reported in,
|
||||
# https://www.pikers.dev/pikers/piker/issues/70
|
||||
# await tractor.pause()
|
||||
get_console_log(loglevel)
|
||||
|
||||
src: Flume = Flume.from_msg(src_flume_addr)
|
||||
dst: Flume = Flume.from_msg(
|
||||
|
|
|
|||
228
piker/types.py
228
piker/types.py
|
|
@ -21,6 +21,230 @@ Extensions to built-in or (heavily used but 3rd party) friend-lib
|
|||
types.
|
||||
|
||||
'''
|
||||
from tractor.msg.pretty_struct import (
|
||||
Struct as Struct,
|
||||
from __future__ import annotations
|
||||
from collections import UserList
|
||||
from pprint import (
|
||||
saferepr,
|
||||
)
|
||||
from typing import Any
|
||||
|
||||
from msgspec import (
|
||||
msgpack,
|
||||
Struct as _Struct,
|
||||
structs,
|
||||
)
|
||||
|
||||
|
||||
class DiffDump(UserList):
|
||||
'''
|
||||
Very simple list delegator that repr() dumps (presumed) tuple
|
||||
elements of the form `tuple[str, Any, Any]` in a nice
|
||||
multi-line readable form for analyzing `Struct` diffs.
|
||||
|
||||
'''
|
||||
def __repr__(self) -> str:
|
||||
if not len(self):
|
||||
return super().__repr__()
|
||||
|
||||
# format by displaying item pair's ``repr()`` on multiple,
|
||||
# indented lines such that they are more easily visually
|
||||
# comparable when printed to console when printed to
|
||||
# console.
|
||||
repstr: str = '[\n'
|
||||
for k, left, right in self:
|
||||
repstr += (
|
||||
f'({k},\n'
|
||||
f'\t{repr(left)},\n'
|
||||
f'\t{repr(right)},\n'
|
||||
')\n'
|
||||
)
|
||||
repstr += ']\n'
|
||||
return repstr
|
||||
|
||||
|
||||
class Struct(
|
||||
_Struct,
|
||||
|
||||
# https://jcristharif.com/msgspec/structs.html#tagged-unions
|
||||
# tag='pikerstruct',
|
||||
# tag=True,
|
||||
):
|
||||
'''
|
||||
A "human friendlier" (aka repl buddy) struct subtype.
|
||||
|
||||
'''
|
||||
def _sin_props(self) -> Iterator[
|
||||
tuple[
|
||||
structs.FieldIinfo,
|
||||
str,
|
||||
Any,
|
||||
]
|
||||
]:
|
||||
'''
|
||||
Iterate over all non-@property fields of this struct.
|
||||
|
||||
'''
|
||||
fi: structs.FieldInfo
|
||||
for fi in structs.fields(self):
|
||||
key: str = fi.name
|
||||
val: Any = getattr(self, key)
|
||||
yield fi, key, val
|
||||
|
||||
def to_dict(
|
||||
self,
|
||||
include_non_members: bool = True,
|
||||
|
||||
) -> dict:
|
||||
'''
|
||||
Like it sounds.. direct delegation to:
|
||||
https://jcristharif.com/msgspec/api.html#msgspec.structs.asdict
|
||||
|
||||
BUT, by default we pop all non-member (aka not defined as
|
||||
struct fields) fields by default.
|
||||
|
||||
'''
|
||||
asdict: dict = structs.asdict(self)
|
||||
if include_non_members:
|
||||
return asdict
|
||||
|
||||
# only return a dict of the struct members
|
||||
# which were provided as input, NOT anything
|
||||
# added as type-defined `@property` methods!
|
||||
sin_props: dict = {}
|
||||
fi: structs.FieldInfo
|
||||
for fi, k, v in self._sin_props():
|
||||
sin_props[k] = asdict[k]
|
||||
|
||||
return sin_props
|
||||
|
||||
def pformat(
|
||||
self,
|
||||
field_indent: int = 2,
|
||||
indent: int = 0,
|
||||
|
||||
) -> str:
|
||||
'''
|
||||
Recursion-safe `pprint.pformat()` style formatting of
|
||||
a `msgspec.Struct` for sane reading by a human using a REPL.
|
||||
|
||||
'''
|
||||
# global whitespace indent
|
||||
ws: str = ' '*indent
|
||||
|
||||
# field whitespace indent
|
||||
field_ws: str = ' '*(field_indent + indent)
|
||||
|
||||
# qtn: str = ws + self.__class__.__qualname__
|
||||
qtn: str = self.__class__.__qualname__
|
||||
|
||||
obj_str: str = '' # accumulator
|
||||
fi: structs.FieldInfo
|
||||
k: str
|
||||
v: Any
|
||||
for fi, k, v in self._sin_props():
|
||||
|
||||
# TODO: how can we prefer `Literal['option1', 'option2,
|
||||
# ..]` over .__name__ == `Literal` but still get only the
|
||||
# latter for simple types like `str | int | None` etc..?
|
||||
ft: type = fi.type
|
||||
typ_name: str = getattr(ft, '__name__', str(ft))
|
||||
|
||||
# recurse to get sub-struct's `.pformat()` output Bo
|
||||
if isinstance(v, Struct):
|
||||
val_str: str = v.pformat(
|
||||
indent=field_indent + indent,
|
||||
field_indent=indent + field_indent,
|
||||
)
|
||||
|
||||
else: # the `pprint` recursion-safe format:
|
||||
# https://docs.python.org/3.11/library/pprint.html#pprint.saferepr
|
||||
val_str: str = saferepr(v)
|
||||
|
||||
obj_str += (field_ws + f'{k}: {typ_name} = {val_str},\n')
|
||||
|
||||
return (
|
||||
f'{qtn}(\n'
|
||||
f'{obj_str}'
|
||||
f'{ws})'
|
||||
)
|
||||
|
||||
# TODO: use a pprint.PrettyPrinter instance around ONLY rendering
|
||||
# inside a known tty?
|
||||
# def __repr__(self) -> str:
|
||||
# ...
|
||||
|
||||
# __str__ = __repr__ = pformat
|
||||
__repr__ = pformat
|
||||
|
||||
def copy(
|
||||
self,
|
||||
update: dict | None = None,
|
||||
|
||||
) -> Struct:
|
||||
'''
|
||||
Validate-typecast all self defined fields, return a copy of
|
||||
us with all such fields.
|
||||
|
||||
NOTE: This is kinda like the default behaviour in
|
||||
`pydantic.BaseModel` except a copy of the object is
|
||||
returned making it compat with `frozen=True`.
|
||||
|
||||
'''
|
||||
if update:
|
||||
for k, v in update.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
# NOTE: roundtrip serialize to validate
|
||||
# - enode to msgpack binary format,
|
||||
# - decode that back to a struct.
|
||||
return msgpack.Decoder(type=type(self)).decode(
|
||||
msgpack.Encoder().encode(self)
|
||||
)
|
||||
|
||||
def typecast(
|
||||
self,
|
||||
|
||||
# TODO: allow only casting a named subset?
|
||||
# fields: set[str] | None = None,
|
||||
|
||||
) -> None:
|
||||
'''
|
||||
Cast all fields using their declared type annotations
|
||||
(kinda like what `pydantic` does by default).
|
||||
|
||||
NOTE: this of course won't work on frozen types, use
|
||||
``.copy()`` above in such cases.
|
||||
|
||||
'''
|
||||
# https://jcristharif.com/msgspec/api.html#msgspec.structs.fields
|
||||
fi: structs.FieldInfo
|
||||
for fi in structs.fields(self):
|
||||
setattr(
|
||||
self,
|
||||
fi.name,
|
||||
fi.type(getattr(self, fi.name)),
|
||||
)
|
||||
|
||||
def __sub__(
|
||||
self,
|
||||
other: Struct,
|
||||
|
||||
) -> DiffDump[tuple[str, Any, Any]]:
|
||||
'''
|
||||
Compare fields/items key-wise and return a ``DiffDump``
|
||||
for easy visual REPL comparison B)
|
||||
|
||||
'''
|
||||
diffs: DiffDump[tuple[str, Any, Any]] = DiffDump()
|
||||
for fi in structs.fields(self):
|
||||
attr_name: str = fi.name
|
||||
ours: Any = getattr(self, attr_name)
|
||||
theirs: Any = getattr(other, attr_name)
|
||||
if ours != theirs:
|
||||
diffs.append((
|
||||
attr_name,
|
||||
ours,
|
||||
theirs,
|
||||
))
|
||||
|
||||
return diffs
|
||||
|
|
|
|||
|
|
@ -33,10 +33,7 @@ from . import _search
|
|||
from ..accounting import unpack_fqme
|
||||
from ..data._symcache import open_symcache
|
||||
from ..data.feed import install_brokerd_search
|
||||
from ..log import (
|
||||
get_logger,
|
||||
get_console_log,
|
||||
)
|
||||
from ..log import get_logger
|
||||
from ..service import maybe_spawn_brokerd
|
||||
from ._exec import run_qtractor
|
||||
|
||||
|
|
@ -90,13 +87,6 @@ async def _async_main(
|
|||
Provision the "main" widget with initial symbol data and root nursery.
|
||||
|
||||
"""
|
||||
# enable chart's console logging
|
||||
if loglevel:
|
||||
get_console_log(
|
||||
level=loglevel,
|
||||
name=__name__,
|
||||
)
|
||||
|
||||
# set as singleton
|
||||
_chart._godw = main_widget
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from typing import (
|
|||
)
|
||||
|
||||
import pyqtgraph as pg
|
||||
import trio
|
||||
|
||||
from piker.ui.qt import (
|
||||
QtCore,
|
||||
|
|
@ -40,7 +41,6 @@ from piker.ui.qt import (
|
|||
QVBoxLayout,
|
||||
QSplitter,
|
||||
)
|
||||
from ._widget import GodWidget
|
||||
from ._axes import (
|
||||
DynamicDateAxis,
|
||||
PriceAxis,
|
||||
|
|
@ -61,6 +61,10 @@ from ._style import (
|
|||
_xaxis_at,
|
||||
# _min_points_to_show,
|
||||
)
|
||||
from ..data.feed import (
|
||||
Feed,
|
||||
Flume,
|
||||
)
|
||||
from ..accounting import (
|
||||
MktPair,
|
||||
)
|
||||
|
|
@ -74,12 +78,305 @@ from . import _pg_overrides as pgo
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from ._display import DisplayState
|
||||
from ..data.flows import Flume
|
||||
from ..data.feed import Feed
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
_godw: GodWidget|None = None
|
||||
|
||||
def get_godw() -> GodWidget:
|
||||
'''
|
||||
Get the top level "god widget", the root/central-most Qt
|
||||
widget-object set as `QMainWindow.setCentralWidget(_godw)`.
|
||||
|
||||
See `piker.ui._exec` for the runtime init details and all the
|
||||
machinery for running `trio` on the Qt event loop in guest mode.
|
||||
|
||||
'''
|
||||
if _godw is None:
|
||||
raise RuntimeError(
|
||||
'No god-widget initialized ??\n'
|
||||
'Have you called `run_qtractor()` yet?\n'
|
||||
)
|
||||
return _godw
|
||||
|
||||
|
||||
class GodWidget(QWidget):
|
||||
'''
|
||||
"Our lord and savior, the holy child of window-shua, there is no
|
||||
widget above thee." - 6|6
|
||||
|
||||
The highest level composed widget which contains layouts for
|
||||
organizing charts as well as other sub-widgets used to control or
|
||||
modify them.
|
||||
|
||||
'''
|
||||
search: SearchWidget
|
||||
mode_name: str = 'god'
|
||||
|
||||
def __init__(
|
||||
|
||||
self,
|
||||
parent=None,
|
||||
|
||||
) -> None:
|
||||
|
||||
super().__init__(parent)
|
||||
|
||||
self.search: SearchWidget|None = None
|
||||
|
||||
self.hbox = QHBoxLayout(self)
|
||||
self.hbox.setContentsMargins(0, 0, 0, 0)
|
||||
self.hbox.setSpacing(6)
|
||||
self.hbox.setAlignment(Qt.AlignTop)
|
||||
|
||||
self.vbox = QVBoxLayout()
|
||||
self.vbox.setContentsMargins(0, 0, 0, 0)
|
||||
self.vbox.setSpacing(2)
|
||||
self.vbox.setAlignment(Qt.AlignTop)
|
||||
|
||||
self.hbox.addLayout(self.vbox)
|
||||
|
||||
self._chart_cache: dict[
|
||||
str,
|
||||
tuple[LinkedSplits, LinkedSplits],
|
||||
] = {}
|
||||
|
||||
self.hist_linked: LinkedSplits|None = None
|
||||
self.rt_linked: LinkedSplits|None = None
|
||||
self._active_cursor: Cursor|None = None
|
||||
|
||||
# assigned in the startup func `_async_main()`
|
||||
self._root_n: trio.Nursery = None
|
||||
|
||||
self._widgets: dict[str, QWidget] = {}
|
||||
self._resizing: bool = False
|
||||
|
||||
# TODO: do we need this, when would god get resized
|
||||
# and the window does not? Never right?!
|
||||
# self.reg_for_resize(self)
|
||||
|
||||
# TODO: strat loader/saver that we don't need yet.
|
||||
# def init_strategy_ui(self):
|
||||
# self.toolbar_layout = QHBoxLayout()
|
||||
# self.toolbar_layout.setContentsMargins(0, 0, 0, 0)
|
||||
# self.vbox.addLayout(self.toolbar_layout)
|
||||
# self.strategy_box = StrategyBoxWidget(self)
|
||||
# self.toolbar_layout.addWidget(self.strategy_box)
|
||||
|
||||
@property
|
||||
def linkedsplits(self) -> LinkedSplits:
|
||||
return self.rt_linked
|
||||
|
||||
def set_chart_symbols(
|
||||
self,
|
||||
group_key: tuple[str], # of form <fqme>.<providername>
|
||||
all_linked: tuple[LinkedSplits, LinkedSplits], # type: ignore
|
||||
|
||||
) -> None:
|
||||
# re-sort org cache symbol list in LIFO order
|
||||
cache = self._chart_cache
|
||||
cache.pop(group_key, None)
|
||||
cache[group_key] = all_linked
|
||||
|
||||
def get_chart_symbols(
|
||||
self,
|
||||
symbol_key: str,
|
||||
|
||||
) -> tuple[LinkedSplits, LinkedSplits]: # type: ignore
|
||||
return self._chart_cache.get(symbol_key)
|
||||
|
||||
async def load_symbols(
|
||||
self,
|
||||
fqmes: list[str],
|
||||
loglevel: str,
|
||||
reset: bool = False,
|
||||
|
||||
) -> trio.Event:
|
||||
'''
|
||||
Load a new contract into the charting app.
|
||||
|
||||
Expects a ``numpy`` structured array containing all the ohlcv fields.
|
||||
|
||||
'''
|
||||
# NOTE: for now we use the first symbol in the set as the "key"
|
||||
# for the overlay of feeds on the chart.
|
||||
group_key: tuple[str] = tuple(fqmes)
|
||||
|
||||
all_linked = self.get_chart_symbols(group_key)
|
||||
order_mode_started = trio.Event()
|
||||
|
||||
if not self.vbox.isEmpty():
|
||||
|
||||
# XXX: seems to make switching slower?
|
||||
# qframe = self.hist_linked.chart.qframe
|
||||
# if qframe.sidepane is self.search:
|
||||
# qframe.hbox.removeWidget(self.search)
|
||||
|
||||
for linked in [self.rt_linked, self.hist_linked]:
|
||||
# XXX: this is CRITICAL especially with pixel buffer caching
|
||||
linked.hide()
|
||||
linked.unfocus()
|
||||
|
||||
# XXX: pretty sure we don't need this
|
||||
# remove any existing plots?
|
||||
# XXX: ahh we might want to support cache unloading..
|
||||
# self.vbox.removeWidget(linked)
|
||||
|
||||
# switching to a new viewable chart
|
||||
if all_linked is None or reset:
|
||||
from ._display import display_symbol_data
|
||||
|
||||
# we must load a fresh linked charts set
|
||||
self.rt_linked = rt_charts = LinkedSplits(self)
|
||||
self.hist_linked = hist_charts = LinkedSplits(self)
|
||||
|
||||
# spawn new task to start up and update new sub-chart instances
|
||||
self._root_n.start_soon(
|
||||
display_symbol_data,
|
||||
self,
|
||||
fqmes,
|
||||
loglevel,
|
||||
order_mode_started,
|
||||
)
|
||||
|
||||
# self.vbox.addWidget(hist_charts)
|
||||
self.vbox.addWidget(rt_charts)
|
||||
self.set_chart_symbols(
|
||||
group_key,
|
||||
(hist_charts, rt_charts),
|
||||
)
|
||||
|
||||
for linked in [hist_charts, rt_charts]:
|
||||
linked.show()
|
||||
linked.focus()
|
||||
|
||||
await trio.sleep(0)
|
||||
|
||||
else:
|
||||
# symbol is already loaded and ems ready
|
||||
order_mode_started.set()
|
||||
|
||||
self.hist_linked, self.rt_linked = all_linked
|
||||
|
||||
for linked in all_linked:
|
||||
# TODO:
|
||||
# - we'll probably want per-instrument/provider state here?
|
||||
# change the order config form over to the new chart
|
||||
|
||||
# chart is already in memory so just focus it
|
||||
linked.show()
|
||||
linked.focus()
|
||||
linked.graphics_cycle()
|
||||
await trio.sleep(0)
|
||||
|
||||
# resume feeds *after* rendering chart view asap
|
||||
chart = linked.chart
|
||||
if chart:
|
||||
chart.resume_all_feeds()
|
||||
|
||||
# TODO: we need a check to see if the chart
|
||||
# last had the xlast in view, if so then shift so it's
|
||||
# still in view, if the user was viewing history then
|
||||
# do nothing yah?
|
||||
self.rt_linked.chart.main_viz.default_view(
|
||||
do_min_bars=True,
|
||||
)
|
||||
|
||||
# if a history chart instance is already up then
|
||||
# set the search widget as its sidepane.
|
||||
hist_chart = self.hist_linked.chart
|
||||
if hist_chart:
|
||||
hist_chart.qframe.set_sidepane(self.search)
|
||||
|
||||
# NOTE: this is really stupid/hard to follow.
|
||||
# we have to reposition the active position nav
|
||||
# **AFTER** applying the search bar as a sidepane
|
||||
# to the newly switched to symbol.
|
||||
await trio.sleep(0)
|
||||
|
||||
# TODO: probably stick this in some kinda `LooknFeel` API?
|
||||
for tracker in self.rt_linked.mode.trackers.values():
|
||||
pp_nav = tracker.nav
|
||||
if tracker.live_pp.cumsize:
|
||||
pp_nav.show()
|
||||
pp_nav.hide_info()
|
||||
else:
|
||||
pp_nav.hide()
|
||||
|
||||
# set window titlebar info
|
||||
symbol = self.rt_linked.mkt
|
||||
if symbol is not None:
|
||||
self.window.setWindowTitle(
|
||||
f'{symbol.fqme} '
|
||||
f'tick:{symbol.size_tick}'
|
||||
)
|
||||
|
||||
return order_mode_started
|
||||
|
||||
def focus(self) -> None:
|
||||
'''
|
||||
Focus the top level widget which in turn focusses the chart
|
||||
ala "view mode".
|
||||
|
||||
'''
|
||||
# go back to view-mode focus (aka chart focus)
|
||||
self.clearFocus()
|
||||
chart = self.rt_linked.chart
|
||||
if chart:
|
||||
chart.setFocus()
|
||||
|
||||
def reg_for_resize(
|
||||
self,
|
||||
widget: QWidget,
|
||||
) -> None:
|
||||
getattr(widget, 'on_resize')
|
||||
self._widgets[widget.mode_name] = widget
|
||||
|
||||
def on_win_resize(self, event: QtCore.QEvent) -> None:
|
||||
'''
|
||||
Top level god widget handler from window (the real yaweh) resize
|
||||
events such that any registered widgets which wish to be
|
||||
notified are invoked using our pythonic `.on_resize()` method
|
||||
api.
|
||||
|
||||
Where we do UX magic to make things not suck B)
|
||||
|
||||
'''
|
||||
if self._resizing:
|
||||
return
|
||||
|
||||
self._resizing = True
|
||||
|
||||
log.info('God widget resize')
|
||||
for name, widget in self._widgets.items():
|
||||
widget.on_resize()
|
||||
|
||||
self._resizing = False
|
||||
|
||||
# on_resize = on_win_resize
|
||||
|
||||
def get_cursor(self) -> Cursor:
|
||||
return self._active_cursor
|
||||
|
||||
def iter_linked(self) -> Iterator[LinkedSplits]:
|
||||
for linked in [self.hist_linked, self.rt_linked]:
|
||||
yield linked
|
||||
|
||||
def resize_all(self) -> None:
|
||||
'''
|
||||
Dynamic resize sequence: adjusts all sub-widgets/charts to
|
||||
sensible default ratios of what space is detected as available
|
||||
on the display / window.
|
||||
|
||||
'''
|
||||
rt_linked = self.rt_linked
|
||||
rt_linked.set_split_sizes()
|
||||
self.rt_linked.resize_sidepanes()
|
||||
self.hist_linked.resize_sidepanes(from_linked=rt_linked)
|
||||
self.search.on_resize()
|
||||
|
||||
|
||||
class ChartnPane(QFrame):
|
||||
'''
|
||||
One-off ``QFrame`` composite which pairs a chart
|
||||
|
|
@ -141,6 +438,7 @@ class LinkedSplits(QWidget):
|
|||
|
||||
'''
|
||||
def __init__(
|
||||
|
||||
self,
|
||||
godwidget: GodWidget,
|
||||
|
||||
|
|
@ -752,7 +1050,7 @@ class ChartPlotWidget(pg.PlotWidget):
|
|||
|
||||
) -> None:
|
||||
'''
|
||||
Increment the data view `datums`` steps toward y-axis thus
|
||||
Increment the data view ``datums``` steps toward y-axis thus
|
||||
"following" the current time slot/step/bar.
|
||||
|
||||
'''
|
||||
|
|
@ -762,7 +1060,7 @@ class ChartPlotWidget(pg.PlotWidget):
|
|||
x_shift = viz.index_step() * datums
|
||||
|
||||
if datums >= 300:
|
||||
log.warning('FUCKING FIX THE GLOBAL STEP BULLSHIT')
|
||||
print("FUCKING FIX THE GLOBAL STEP BULLSHIT")
|
||||
# breakpoint()
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -413,18 +413,9 @@ class Cursor(pg.GraphicsObject):
|
|||
self,
|
||||
item: pg.GraphicsObject,
|
||||
) -> None:
|
||||
assert getattr(
|
||||
item,
|
||||
'delete',
|
||||
), f"{item} must define a ``.delete()``"
|
||||
assert getattr(item, 'delete'), f"{item} must define a ``.delete()``"
|
||||
self._hovered.add(item)
|
||||
|
||||
def is_hovered(
|
||||
self,
|
||||
item: pg.GraphicsObject,
|
||||
) -> bool:
|
||||
return item in self._hovered
|
||||
|
||||
def add_plot(
|
||||
self,
|
||||
plot: ChartPlotWidget, # noqa
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ from piker.ui.qt import QLineF
|
|||
from ..data._sharedmem import (
|
||||
ShmArray,
|
||||
)
|
||||
from ..data.flows import Flume
|
||||
from ..data.feed import Flume
|
||||
from ..data._formatters import (
|
||||
IncrementalFormatter,
|
||||
OHLCBarsFmtr, # Plain OHLC renderer
|
||||
|
|
|
|||
|
|
@ -55,11 +55,6 @@ from ._style import (
|
|||
from ._lines import LevelLine
|
||||
from ..log import get_logger
|
||||
|
||||
# TODO, rm the cycle here!
|
||||
from ._widget import (
|
||||
GodWidget,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._chart import (
|
||||
GodWidget,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ from . import _style
|
|||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._widget import GodWidget
|
||||
from ._chart import GodWidget
|
||||
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ from pyqtgraph import (
|
|||
functions as fn,
|
||||
)
|
||||
import numpy as np
|
||||
import tractor
|
||||
import trio
|
||||
|
||||
from piker.ui.qt import (
|
||||
|
|
@ -73,10 +72,7 @@ if TYPE_CHECKING:
|
|||
GodWidget,
|
||||
)
|
||||
from ._dataviz import Viz
|
||||
from .order_mode import (
|
||||
OrderMode,
|
||||
Dialog,
|
||||
)
|
||||
from .order_mode import OrderMode
|
||||
from ._display import DisplayState
|
||||
|
||||
|
||||
|
|
@ -134,12 +130,7 @@ async def handle_viewmode_kb_inputs(
|
|||
|
||||
async for kbmsg in recv_chan:
|
||||
event, etype, key, mods, text = kbmsg.to_tuple()
|
||||
log.debug(
|
||||
f'View-mode kb-msg received,\n'
|
||||
f'mods: {mods!r}\n'
|
||||
f'key: {key!r}\n'
|
||||
f'text: {text!r}\n'
|
||||
)
|
||||
log.debug(f'key: {key}, mods: {mods}, text: {text}')
|
||||
now = time.time()
|
||||
period = now - last
|
||||
|
||||
|
|
@ -167,12 +158,8 @@ async def handle_viewmode_kb_inputs(
|
|||
# have no previous keys or we do and the min_tap period is
|
||||
# met
|
||||
if (
|
||||
not fast_key_seq
|
||||
or (
|
||||
period <= min_tap
|
||||
and
|
||||
fast_key_seq
|
||||
)
|
||||
not fast_key_seq or
|
||||
period <= min_tap and fast_key_seq
|
||||
):
|
||||
fast_key_seq.append(text)
|
||||
log.debug(f'fast keys seqs {fast_key_seq}')
|
||||
|
|
@ -187,8 +174,7 @@ async def handle_viewmode_kb_inputs(
|
|||
# UI REPL-shell, with ctrl-p (for "pause")
|
||||
if (
|
||||
ctrl
|
||||
and
|
||||
key in {
|
||||
and key in {
|
||||
Qt.Key_P,
|
||||
}
|
||||
):
|
||||
|
|
@ -198,6 +184,7 @@ async def handle_viewmode_kb_inputs(
|
|||
vlm_chart = chart.linked.subplots['volume'] # noqa
|
||||
vlm_viz = vlm_chart.main_viz # noqa
|
||||
dvlm_pi = vlm_chart._vizs['dolla_vlm'].plot # noqa
|
||||
import tractor
|
||||
await tractor.pause()
|
||||
view.interact_graphics_cycle()
|
||||
|
||||
|
|
@ -205,8 +192,7 @@ async def handle_viewmode_kb_inputs(
|
|||
# shown data `Viz`s for the current chart app.
|
||||
if (
|
||||
ctrl
|
||||
and
|
||||
key in {
|
||||
and key in {
|
||||
Qt.Key_R,
|
||||
}
|
||||
):
|
||||
|
|
@ -245,8 +231,7 @@ async def handle_viewmode_kb_inputs(
|
|||
key == Qt.Key_Escape
|
||||
or (
|
||||
ctrl
|
||||
and
|
||||
key == Qt.Key_C
|
||||
and key == Qt.Key_C
|
||||
)
|
||||
):
|
||||
# ctrl-c as cancel
|
||||
|
|
@ -257,35 +242,17 @@ async def handle_viewmode_kb_inputs(
|
|||
# cancel order or clear graphics
|
||||
if (
|
||||
key == Qt.Key_C
|
||||
or
|
||||
key == Qt.Key_Delete
|
||||
or key == Qt.Key_Delete
|
||||
):
|
||||
# log.info('Handling <c> hotkey!')
|
||||
try:
|
||||
dialogs: list[Dialog] = order_mode.cancel_orders_under_cursor()
|
||||
except BaseException:
|
||||
log.exception('Failed to cancel orders !?\n')
|
||||
await tractor.pause()
|
||||
|
||||
if not dialogs:
|
||||
log.warning(
|
||||
'No orders were cancelled?\n'
|
||||
'Is there an order-line under the cursor?\n'
|
||||
'If you think there IS your DE might be "hiding the mouse" before '
|
||||
'we rx the keyboard input via Qt..\n'
|
||||
'=> Check your DE and/or TWM settings to be sure! <=\n'
|
||||
)
|
||||
# ^TODO?, some way to detect if there's lines and
|
||||
# the DE is cuckin with things?
|
||||
# await tractor.pause()
|
||||
order_mode.cancel_orders_under_cursor()
|
||||
|
||||
# View modes
|
||||
if (
|
||||
ctrl
|
||||
and (
|
||||
key == Qt.Key_Equal
|
||||
or
|
||||
key == Qt.Key_I
|
||||
or key == Qt.Key_I
|
||||
)
|
||||
):
|
||||
view.wheelEvent(
|
||||
|
|
@ -297,8 +264,7 @@ async def handle_viewmode_kb_inputs(
|
|||
ctrl
|
||||
and (
|
||||
key == Qt.Key_Minus
|
||||
or
|
||||
key == Qt.Key_O
|
||||
or key == Qt.Key_O
|
||||
)
|
||||
):
|
||||
view.wheelEvent(
|
||||
|
|
@ -309,8 +275,7 @@ async def handle_viewmode_kb_inputs(
|
|||
|
||||
elif (
|
||||
not ctrl
|
||||
and
|
||||
key == Qt.Key_R
|
||||
and key == Qt.Key_R
|
||||
):
|
||||
# NOTE: seems that if we don't yield a Qt render
|
||||
# cycle then the m4 downsampled curves will show here
|
||||
|
|
@ -512,8 +477,7 @@ async def handle_viewmode_mouse(
|
|||
# view.raiseContextMenu(event)
|
||||
|
||||
if (
|
||||
view.order_mode.active
|
||||
and
|
||||
view.order_mode.active and
|
||||
button == QtCore.Qt.LeftButton
|
||||
):
|
||||
# when in order mode, submit execution
|
||||
|
|
@ -817,8 +781,7 @@ class ChartView(ViewBox):
|
|||
|
||||
# Scale or translate based on mouse button
|
||||
if btn & (
|
||||
QtCore.Qt.LeftButton
|
||||
| QtCore.Qt.MidButton
|
||||
QtCore.Qt.LeftButton | QtCore.Qt.MidButton
|
||||
):
|
||||
# zoom y-axis ONLY when click-n-drag on it
|
||||
# if axis == 1:
|
||||
|
|
|
|||
|
|
@ -51,13 +51,10 @@ from ._anchors import (
|
|||
from ..calc import humanize
|
||||
from ._label import Label
|
||||
from ._style import hcolor, _font
|
||||
from ..log import get_logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._cursor import Cursor
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
# TODO: probably worth investigating if we can
|
||||
# make .boundingRect() faster:
|
||||
|
|
@ -349,7 +346,7 @@ class LevelLine(pg.InfiniteLine):
|
|||
|
||||
) -> None:
|
||||
# TODO: enter labels edit mode
|
||||
log.debug(f'double click {ev}')
|
||||
print(f'double click {ev}')
|
||||
|
||||
def paint(
|
||||
self,
|
||||
|
|
@ -463,19 +460,10 @@ class LevelLine(pg.InfiniteLine):
|
|||
# hovered
|
||||
if (
|
||||
not ev.isExit()
|
||||
and
|
||||
ev.acceptDrags(QtCore.Qt.LeftButton)
|
||||
and ev.acceptDrags(QtCore.Qt.LeftButton)
|
||||
):
|
||||
# if already hovered we don't need to run again
|
||||
if (
|
||||
self.mouseHovering is True
|
||||
and
|
||||
cur.is_hovered(self)
|
||||
):
|
||||
log.debug(
|
||||
f'Already hovering ??\n'
|
||||
f'cur._hovered: {cur._hovered!r}\n'
|
||||
)
|
||||
if self.mouseHovering is True:
|
||||
return
|
||||
|
||||
if self.only_show_markers_on_hover:
|
||||
|
|
@ -492,7 +480,6 @@ class LevelLine(pg.InfiniteLine):
|
|||
cur._y_label_update = False
|
||||
|
||||
# add us to cursor state
|
||||
log.debug(f'Adding line {self!r}\n')
|
||||
cur.add_hovered(self)
|
||||
|
||||
if self._hide_xhair_on_hover:
|
||||
|
|
@ -520,7 +507,6 @@ class LevelLine(pg.InfiniteLine):
|
|||
|
||||
self.currentPen = self.pen
|
||||
|
||||
log.debug(f'Removing line {self!r}\n')
|
||||
cur._hovered.remove(self)
|
||||
|
||||
if self.only_show_markers_on_hover:
|
||||
|
|
|
|||
|
|
@ -1,346 +0,0 @@
|
|||
# piker: trading gear for hackers
|
||||
# Copyright (C) Tyler Goodlet (in stewardship for pikers)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
'''
|
||||
Root-most (what they call a "central widget") of every Qt-UI-app's
|
||||
window.
|
||||
|
||||
'''
|
||||
from __future__ import annotations
|
||||
from typing import (
|
||||
Iterator,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
import trio
|
||||
|
||||
from piker.ui.qt import (
|
||||
QtCore,
|
||||
Qt,
|
||||
QWidget,
|
||||
QHBoxLayout,
|
||||
QVBoxLayout,
|
||||
)
|
||||
from ..log import get_logger
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._search import SearchWidget
|
||||
from ._chart import (
|
||||
LinkedSplits,
|
||||
)
|
||||
from ._cursor import (
|
||||
Cursor,
|
||||
)
|
||||
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
_godw: GodWidget|None = None
|
||||
|
||||
def get_godw() -> GodWidget:
|
||||
'''
|
||||
Get the top level "god widget", the root/central-most Qt
|
||||
widget-object set as `QMainWindow.setCentralWidget(_godw)`.
|
||||
|
||||
See `piker.ui._exec` for the runtime init details and all the
|
||||
machinery for running `trio` on the Qt event loop in guest mode.
|
||||
|
||||
'''
|
||||
if _godw is None:
|
||||
raise RuntimeError(
|
||||
'No god-widget initialized ??\n'
|
||||
'Have you called `run_qtractor()` yet?\n'
|
||||
)
|
||||
return _godw
|
||||
|
||||
|
||||
class GodWidget(QWidget):
|
||||
'''
|
||||
"Our lord and savior, the holy child of window-shua, there is no
|
||||
widget above thee." - 6|6
|
||||
|
||||
The highest level composed widget which contains layouts for
|
||||
organizing charts as well as other sub-widgets used to control or
|
||||
modify them.
|
||||
|
||||
'''
|
||||
search: SearchWidget
|
||||
mode_name: str = 'god'
|
||||
|
||||
def __init__(
|
||||
|
||||
self,
|
||||
parent=None,
|
||||
|
||||
) -> None:
|
||||
|
||||
super().__init__(parent)
|
||||
|
||||
self.search: SearchWidget|None = None
|
||||
|
||||
self.hbox = QHBoxLayout(self)
|
||||
self.hbox.setContentsMargins(0, 0, 0, 0)
|
||||
self.hbox.setSpacing(6)
|
||||
self.hbox.setAlignment(Qt.AlignTop)
|
||||
|
||||
self.vbox = QVBoxLayout()
|
||||
self.vbox.setContentsMargins(0, 0, 0, 0)
|
||||
self.vbox.setSpacing(2)
|
||||
self.vbox.setAlignment(Qt.AlignTop)
|
||||
|
||||
self.hbox.addLayout(self.vbox)
|
||||
|
||||
self._chart_cache: dict[
|
||||
str,
|
||||
tuple[LinkedSplits, LinkedSplits],
|
||||
] = {}
|
||||
|
||||
self.hist_linked: LinkedSplits|None = None
|
||||
self.rt_linked: LinkedSplits|None = None
|
||||
self._active_cursor: Cursor|None = None
|
||||
|
||||
# assigned in the startup func `_async_main()`
|
||||
self._root_n: trio.Nursery = None
|
||||
|
||||
self._widgets: dict[str, QWidget] = {}
|
||||
self._resizing: bool = False
|
||||
|
||||
# TODO: do we need this, when would god get resized
|
||||
# and the window does not? Never right?!
|
||||
# self.reg_for_resize(self)
|
||||
|
||||
# TODO: strat loader/saver that we don't need yet.
|
||||
# def init_strategy_ui(self):
|
||||
# self.toolbar_layout = QHBoxLayout()
|
||||
# self.toolbar_layout.setContentsMargins(0, 0, 0, 0)
|
||||
# self.vbox.addLayout(self.toolbar_layout)
|
||||
# self.strategy_box = StrategyBoxWidget(self)
|
||||
# self.toolbar_layout.addWidget(self.strategy_box)
|
||||
|
||||
@property
|
||||
def linkedsplits(self) -> LinkedSplits:
|
||||
return self.rt_linked
|
||||
|
||||
def set_chart_symbols(
|
||||
self,
|
||||
group_key: tuple[str], # of form <fqme>.<providername>
|
||||
all_linked: tuple[LinkedSplits, LinkedSplits], # type: ignore
|
||||
|
||||
) -> None:
|
||||
# re-sort org cache symbol list in LIFO order
|
||||
cache = self._chart_cache
|
||||
cache.pop(group_key, None)
|
||||
cache[group_key] = all_linked
|
||||
|
||||
def get_chart_symbols(
|
||||
self,
|
||||
symbol_key: str,
|
||||
|
||||
) -> tuple[LinkedSplits, LinkedSplits]: # type: ignore
|
||||
return self._chart_cache.get(symbol_key)
|
||||
|
||||
async def load_symbols(
|
||||
self,
|
||||
fqmes: list[str],
|
||||
loglevel: str,
|
||||
reset: bool = False,
|
||||
|
||||
) -> trio.Event:
|
||||
'''
|
||||
Load a new contract into the charting app.
|
||||
|
||||
Expects a ``numpy`` structured array containing all the ohlcv fields.
|
||||
|
||||
'''
|
||||
# NOTE: for now we use the first symbol in the set as the "key"
|
||||
# for the overlay of feeds on the chart.
|
||||
group_key: tuple[str] = tuple(fqmes)
|
||||
|
||||
all_linked = self.get_chart_symbols(group_key)
|
||||
order_mode_started = trio.Event()
|
||||
|
||||
if not self.vbox.isEmpty():
|
||||
|
||||
# XXX: seems to make switching slower?
|
||||
# qframe = self.hist_linked.chart.qframe
|
||||
# if qframe.sidepane is self.search:
|
||||
# qframe.hbox.removeWidget(self.search)
|
||||
|
||||
for linked in [self.rt_linked, self.hist_linked]:
|
||||
# XXX: this is CRITICAL especially with pixel buffer caching
|
||||
linked.hide()
|
||||
linked.unfocus()
|
||||
|
||||
# XXX: pretty sure we don't need this
|
||||
# remove any existing plots?
|
||||
# XXX: ahh we might want to support cache unloading..
|
||||
# self.vbox.removeWidget(linked)
|
||||
|
||||
# switching to a new viewable chart
|
||||
if all_linked is None or reset:
|
||||
from ._display import display_symbol_data
|
||||
|
||||
# we must load a fresh linked charts set
|
||||
from ._chart import LinkedSplits
|
||||
self.rt_linked = rt_charts = LinkedSplits(self)
|
||||
self.hist_linked = hist_charts = LinkedSplits(self)
|
||||
|
||||
# spawn new task to start up and update new sub-chart instances
|
||||
self._root_n.start_soon(
|
||||
display_symbol_data,
|
||||
self,
|
||||
fqmes,
|
||||
loglevel,
|
||||
order_mode_started,
|
||||
)
|
||||
|
||||
# self.vbox.addWidget(hist_charts)
|
||||
self.vbox.addWidget(rt_charts)
|
||||
self.set_chart_symbols(
|
||||
group_key,
|
||||
(hist_charts, rt_charts),
|
||||
)
|
||||
|
||||
for linked in [hist_charts, rt_charts]:
|
||||
linked.show()
|
||||
linked.focus()
|
||||
|
||||
await trio.sleep(0)
|
||||
|
||||
else:
|
||||
# symbol is already loaded and ems ready
|
||||
order_mode_started.set()
|
||||
|
||||
self.hist_linked, self.rt_linked = all_linked
|
||||
|
||||
for linked in all_linked:
|
||||
# TODO:
|
||||
# - we'll probably want per-instrument/provider state here?
|
||||
# change the order config form over to the new chart
|
||||
|
||||
# chart is already in memory so just focus it
|
||||
linked.show()
|
||||
linked.focus()
|
||||
linked.graphics_cycle()
|
||||
await trio.sleep(0)
|
||||
|
||||
# resume feeds *after* rendering chart view asap
|
||||
chart = linked.chart
|
||||
if chart:
|
||||
chart.resume_all_feeds()
|
||||
|
||||
# TODO: we need a check to see if the chart
|
||||
# last had the xlast in view, if so then shift so it's
|
||||
# still in view, if the user was viewing history then
|
||||
# do nothing yah?
|
||||
self.rt_linked.chart.main_viz.default_view(
|
||||
do_min_bars=True,
|
||||
)
|
||||
|
||||
# if a history chart instance is already up then
|
||||
# set the search widget as its sidepane.
|
||||
hist_chart = self.hist_linked.chart
|
||||
if hist_chart:
|
||||
hist_chart.qframe.set_sidepane(self.search)
|
||||
|
||||
# NOTE: this is really stupid/hard to follow.
|
||||
# we have to reposition the active position nav
|
||||
# **AFTER** applying the search bar as a sidepane
|
||||
# to the newly switched to symbol.
|
||||
await trio.sleep(0)
|
||||
|
||||
# TODO: probably stick this in some kinda `LooknFeel` API?
|
||||
for tracker in self.rt_linked.mode.trackers.values():
|
||||
pp_nav = tracker.nav
|
||||
if tracker.live_pp.cumsize:
|
||||
pp_nav.show()
|
||||
pp_nav.hide_info()
|
||||
else:
|
||||
pp_nav.hide()
|
||||
|
||||
# set window titlebar info
|
||||
symbol = self.rt_linked.mkt
|
||||
if symbol is not None:
|
||||
self.window.setWindowTitle(
|
||||
f'{symbol.fqme} '
|
||||
f'tick:{symbol.size_tick}'
|
||||
)
|
||||
|
||||
return order_mode_started
|
||||
|
||||
def focus(self) -> None:
|
||||
'''
|
||||
Focus the top level widget which in turn focusses the chart
|
||||
ala "view mode".
|
||||
|
||||
'''
|
||||
# go back to view-mode focus (aka chart focus)
|
||||
self.clearFocus()
|
||||
chart = self.rt_linked.chart
|
||||
if chart:
|
||||
chart.setFocus()
|
||||
|
||||
def reg_for_resize(
|
||||
self,
|
||||
widget: QWidget,
|
||||
) -> None:
|
||||
getattr(widget, 'on_resize')
|
||||
self._widgets[widget.mode_name] = widget
|
||||
|
||||
def on_win_resize(self, event: QtCore.QEvent) -> None:
|
||||
'''
|
||||
Top level god widget handler from window (the real yaweh) resize
|
||||
events such that any registered widgets which wish to be
|
||||
notified are invoked using our pythonic `.on_resize()` method
|
||||
api.
|
||||
|
||||
Where we do UX magic to make things not suck B)
|
||||
|
||||
'''
|
||||
if self._resizing:
|
||||
return
|
||||
|
||||
self._resizing = True
|
||||
|
||||
log.info('God widget resize')
|
||||
for name, widget in self._widgets.items():
|
||||
widget.on_resize()
|
||||
|
||||
self._resizing = False
|
||||
|
||||
# on_resize = on_win_resize
|
||||
|
||||
def get_cursor(self) -> Cursor:
|
||||
return self._active_cursor
|
||||
|
||||
def iter_linked(self) -> Iterator[LinkedSplits]:
|
||||
for linked in [self.hist_linked, self.rt_linked]:
|
||||
yield linked
|
||||
|
||||
def resize_all(self) -> None:
|
||||
'''
|
||||
Dynamic resize sequence: adjusts all sub-widgets/charts to
|
||||
sensible default ratios of what space is detected as available
|
||||
on the display / window.
|
||||
|
||||
'''
|
||||
rt_linked = self.rt_linked
|
||||
rt_linked.set_split_sizes()
|
||||
self.rt_linked.resize_sidepanes()
|
||||
self.hist_linked.resize_sidepanes(from_linked=rt_linked)
|
||||
self.search.on_resize()
|
||||
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ from piker.ui.qt import (
|
|||
)
|
||||
from ..log import get_logger
|
||||
from ._style import _font_small, hcolor
|
||||
from ._widget import GodWidget
|
||||
from ._chart import GodWidget
|
||||
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ from ._style import _font
|
|||
from ._forms import open_form_input_handling
|
||||
from ._notify import notify_from_ems_status_msg
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._chart import (
|
||||
ChartPlotWidget,
|
||||
|
|
@ -435,7 +436,7 @@ class OrderMode:
|
|||
lines=lines,
|
||||
last_status_close=self.multistatus.open_status(
|
||||
f'submitting {order.exec_mode}-{order.action}',
|
||||
# final_msg=f'submitted {order.exec_mode}-{order.action}',
|
||||
final_msg=f'submitted {order.exec_mode}-{order.action}',
|
||||
clear_on_next=True,
|
||||
)
|
||||
)
|
||||
|
|
@ -527,7 +528,7 @@ class OrderMode:
|
|||
# a submission is the start of a new order dialog
|
||||
dialog = self.dialogs[uuid]
|
||||
dialog.lines = lines
|
||||
cls: Callable|None = dialog.last_status_close
|
||||
cls: Callable | None = dialog.last_status_close
|
||||
if cls:
|
||||
cls()
|
||||
|
||||
|
|
@ -657,7 +658,7 @@ class OrderMode:
|
|||
return True
|
||||
|
||||
|
||||
def cancel_orders_under_cursor(self) -> list[Dialog]:
|
||||
def cancel_orders_under_cursor(self) -> list[str]:
|
||||
return self.cancel_orders(
|
||||
self.oids_from_lines(
|
||||
self.lines.lines_under_cursor()
|
||||
|
|
@ -686,28 +687,24 @@ class OrderMode:
|
|||
self,
|
||||
oids: list[str],
|
||||
|
||||
) -> list[Dialog]:
|
||||
) -> None:
|
||||
'''
|
||||
Cancel all orders from a list of order ids: `oids`.
|
||||
|
||||
'''
|
||||
# key = self.multistatus.open_status(
|
||||
# f'cancelling {len(oids)} orders',
|
||||
# final_msg=f'cancelled orders:\n{oids}',
|
||||
# group_key=True
|
||||
# )
|
||||
dialogs: list[Dialog] = []
|
||||
key = self.multistatus.open_status(
|
||||
f'cancelling {len(oids)} orders',
|
||||
final_msg=f'cancelled orders:\n{oids}',
|
||||
group_key=True
|
||||
)
|
||||
for oid in oids:
|
||||
if dialog := self.dialogs.get(oid):
|
||||
self.client.cancel_nowait(uuid=oid)
|
||||
# cancel_status_close = self.multistatus.open_status(
|
||||
# f'cancelling order {oid}',
|
||||
# group_key=key,
|
||||
# )
|
||||
# dialog.last_status_close = cancel_status_close
|
||||
dialogs.append(dialog)
|
||||
|
||||
return dialogs
|
||||
cancel_status_close = self.multistatus.open_status(
|
||||
f'cancelling order {oid}',
|
||||
group_key=key,
|
||||
)
|
||||
dialog.last_status_close = cancel_status_close
|
||||
|
||||
def cancel_all_orders(self) -> None:
|
||||
'''
|
||||
|
|
@ -779,6 +776,7 @@ class OrderMode:
|
|||
|
||||
@asynccontextmanager
|
||||
async def open_order_mode(
|
||||
|
||||
feed: Feed,
|
||||
godw: GodWidget,
|
||||
fqme: str,
|
||||
|
|
|
|||
Loading…
Reference in New Issue