Super fast switching, just hide loaded charts

symbol_search
Tyler Goodlet 2021-04-13 10:21:19 -04:00
parent 0627f7dcee
commit 1f9f2b873a
1 changed files with 31 additions and 24 deletions

View File

@ -24,13 +24,11 @@ from types import ModuleType
from functools import partial from functools import partial
from PyQt5 import QtCore, QtGui from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import Qt
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
import numpy as np import numpy as np
import pyqtgraph as pg import pyqtgraph as pg
import tractor import tractor
import trio import trio
from trio_typing import TaskStatus
from ._axes import ( from ._axes import (
DynamicDateAxis, DynamicDateAxis,
@ -241,15 +239,14 @@ class ChartSpace(QtGui.QWidget):
# switching to a new viewable chart # switching to a new viewable chart
if not self.v_layout.isEmpty(): if not self.v_layout.isEmpty():
# and not (
# self.linkedcharts is linkedcharts
# ):
# XXX: this is CRITICAL especially with pixel buffer caching # XXX: this is CRITICAL especially with pixel buffer caching
self.linkedcharts.hide() self.linkedcharts.hide()
# remove any existing plots # XXX: pretty sure we don't need this
self.v_layout.removeWidget(self.linkedcharts) # remove any existing plots?
# self.v_layout.removeWidget(self.linkedcharts)
# switching to a new viewable chart
if linkedcharts is None or reset: if linkedcharts is None or reset:
# we must load a fresh linked charts set # we must load a fresh linked charts set
@ -262,24 +259,23 @@ class ChartSpace(QtGui.QWidget):
loglevel, loglevel,
) )
self.v_layout.addWidget(linkedcharts) self.v_layout.addWidget(linkedcharts)
self._chart_cache[symbol_key] = linkedcharts
# if linkedcharts.chart:
# breakpoint()
# else:
# chart is already in memory so just focus it # chart is already in memory so just focus it
if self.linkedcharts: if self.linkedcharts:
self.linkedcharts.unfocus() self.linkedcharts.unfocus()
# self.v_layout.addWidget(linkedcharts) # self.v_layout.addWidget(linkedcharts)
self.linkedcharts = linkedcharts linkedcharts.show()
linkedcharts.focus() linkedcharts.focus()
self.linkedcharts = linkedcharts
# return linkedcharts symbol = linkedcharts.symbol
if symbol is not None:
# TODO: add signalling painter system self.window.setWindowTitle(
# def add_signals(self): f'{symbol.key}@{symbol.brokers} '
# self.chart.add_signals() f'tick:{symbol.tick_size}'
)
class LinkedSplitCharts(QtGui.QWidget): class LinkedSplitCharts(QtGui.QWidget):
@ -352,7 +348,7 @@ class LinkedSplitCharts(QtGui.QWidget):
def focus(self) -> None: def focus(self) -> None:
if self.chart is not None: if self.chart is not None:
self.chart.setFocus() self.chart.focus()
def unfocus(self) -> None: def unfocus(self) -> None:
if self.chart is not None: if self.chart is not None:
@ -573,6 +569,10 @@ class ChartPlotWidget(pg.PlotWidget):
# for when the splitter(s) are resized # for when the splitter(s) are resized
self._vb.sigResized.connect(self._set_yrange) self._vb.sigResized.connect(self._set_yrange)
def focus(self) -> None:
# self.setFocus()
self._vb.setFocus()
def last_bar_in_view(self) -> int: def last_bar_in_view(self) -> int:
self._ohlc[-1]['index'] self._ohlc[-1]['index']
@ -1253,6 +1253,9 @@ async def spawn_fsps(
Pass target entrypoint and historical data. Pass target entrypoint and historical data.
""" """
linked_charts.focus()
# spawns sub-processes which execute cpu bound FSP code # spawns sub-processes which execute cpu bound FSP code
async with tractor.open_nursery(loglevel=loglevel) as n: async with tractor.open_nursery(loglevel=loglevel) as n:
@ -1515,6 +1518,12 @@ async def chart_symbol(
sym: str, sym: str,
loglevel: str, loglevel: str,
) -> None: ) -> None:
"""Spawn a real-time chart widget for this symbol and app session.
These widgets can remain up but hidden so that multiple symbols
can be viewed and switched between extremely fast.
"""
# historical data fetch # historical data fetch
brokermod = brokers.get_brokermod(brokername) brokermod = brokers.get_brokermod(brokername)
@ -1533,12 +1542,12 @@ async def chart_symbol(
f'{symbol.key}@{symbol.brokers} ' f'{symbol.key}@{symbol.brokers} '
f'tick:{symbol.tick_size}' f'tick:{symbol.tick_size}'
) )
# await tractor.breakpoint() # await tractor.breakpoint()
linked_charts = chart_app.linkedcharts linked_charts = chart_app.linkedcharts
linked_charts._symbol = symbol linked_charts._symbol = symbol
chart = linked_charts.plot_ohlc_main(symbol, bars) chart = linked_charts.plot_ohlc_main(symbol, bars)
chart.setFocus()
linked_charts.focus()
# plot historical vwap if available # plot historical vwap if available
wap_in_history = False wap_in_history = False
@ -1611,9 +1620,6 @@ async def chart_symbol(
wap_in_history, wap_in_history,
) )
# await tractor.breakpoint()
# chart_app.linkedcharts.focus()
# wait for a first quote before we start any update tasks # wait for a first quote before we start any update tasks
quote = await feed.receive() quote = await feed.receive()
@ -1634,7 +1640,8 @@ async def chart_symbol(
# chart, # chart,
# linked_charts, # linked_charts,
# ) # )
chart_app.linkedcharts.focus() # chart.focus()
await start_order_mode(chart, symbol, brokername) await start_order_mode(chart, symbol, brokername)