Rip out all usage of `quantdom.bases.Quotes` smh.

its_happening
Tyler Goodlet 2020-06-17 20:45:47 -04:00
parent feccadc331
commit 48f266e276
3 changed files with 45 additions and 23 deletions

View File

@ -5,7 +5,7 @@ import pyqtgraph as pg
from PyQt5 import QtCore, QtGui
from .quantdom.base import Quotes
# from .quantdom.base import Quotes
from .quantdom.utils import fromtimestamp
from ._style import _font
@ -36,10 +36,11 @@ class PriceAxis(pg.AxisItem):
class FromTimeFieldDateAxis(pg.AxisItem):
tick_tpl = {'D1': '%Y-%b-%d'}
def __init__(self, *args, **kwargs):
def __init__(self, splitter, *args, **kwargs):
super().__init__(*args, **kwargs)
self.splitter = splitter
self.setTickFont(_font)
self.quotes_count = len(Quotes) - 1
# self.quotes_count = len(self.splitter.chart._array) - 1
# default styling
self.setStyle(
@ -56,10 +57,13 @@ class FromTimeFieldDateAxis(pg.AxisItem):
# strings = super().tickStrings(values, scale, spacing)
s_period = 'D1'
strings = []
quotes_count = len(self.splitter.chart._array) - 1
for ibar in values:
if ibar > self.quotes_count:
if ibar > quotes_count:
return strings
dt_tick = fromtimestamp(Quotes[int(ibar)].time)
bars = self.splitter.chart._array
dt_tick = fromtimestamp(bars[int(ibar)].time)
strings.append(
dt_tick.strftime(self.tick_tpl[s_period])
)
@ -140,9 +144,10 @@ class XAxisLabel(AxisLabel):
def tick_to_string(self, tick_pos):
# TODO: change to actual period
tpl = self.parent.tick_tpl['D1']
if tick_pos > len(Quotes):
bars = self.parent.splitter.chart._array
if tick_pos > len(bars):
return 'Unknown Time'
return fromtimestamp(Quotes[round(tick_pos)].time).strftime(tpl)
return fromtimestamp(bars[round(tick_pos)].time).strftime(tpl)
def boundingRect(self): # noqa
return QtCore.QRectF(0, 0, 145, 50)

View File

@ -16,7 +16,7 @@ from ._style import _xaxis_at
from ._source import Symbol, ohlc_zeros
from .quantdom.charts import CenteredTextItem
from .quantdom.base import Quotes
# from .quantdom.base import Quotes
# from .quantdom.const import ChartType
from .quantdom.portfolio import Order, Portfolio
@ -101,10 +101,11 @@ class SplitterPlots(QtGui.QWidget):
self.signals_visible = False
self.indicators = []
self.xaxis = FromTimeFieldDateAxis(orientation='bottom')
self.xaxis = FromTimeFieldDateAxis(orientation='bottom', splitter=self)
# self.xaxis = pg.DateAxisItem()
self.xaxis_ind = FromTimeFieldDateAxis(orientation='bottom')
self.xaxis_ind = FromTimeFieldDateAxis(
orientation='bottom', splitter=self)
if _xaxis_at == 'bottom':
self.xaxis.setStyle(showValues=False)
@ -174,7 +175,9 @@ class SplitterPlots(QtGui.QWidget):
self.chart.draw_ohlc(data)
# TODO: this is where we would load an indicator chain
inds = [Quotes.open]
# XXX: note, if this isn't index aligned with
# the source data the chart will go haywire.
inds = [data.open]
for d in inds:
cv = ChartView()
@ -377,8 +380,8 @@ class ChartPlotWidget(pg.PlotWidget):
# update view limits
self.set_view_limits(
data[0]['id'],
data[-1]['id'],
data[0]['index'],
data[-1]['index'],
data['low'].min(),
data['high'].max()
)
@ -525,6 +528,7 @@ def main(symbol):
from datetime import datetime
from ._exec import run_qtrio
from ._source import from_df
# uses pandas_datareader
from .quantdom.loaders import get_quotes
@ -539,15 +543,28 @@ def main(symbol):
date_from=datetime(1900, 1, 1),
date_to=datetime(2030, 12, 31),
)
quotes = from_df(quotes)
# spawn chart
splitter_chart = chart_app.load_symbol(symbol, quotes)
import itertools
nums = itertools.cycle([315., 320., 325.])
nums = itertools.cycle([315., 320., 325., 310., 3])
def gen_nums():
for i in itertools.count():
yield quotes[-1].close + i
yield quotes[-1].close - i
chart = splitter_chart.chart
nums = gen_nums()
while True:
await trio.sleep(0.05)
splitter_chart.chart._graphics['ohlc'].update_last_bar(
{'last': next(nums)})
# splitter_chart.chart.plotItem.sigPlotChanged.emit(self)
# breakpoint()
await trio.sleep(0.1)
new = next(nums)
quotes[-1].close = new
chart._graphics['ohlc'].update_last_bar({'last': new})
# LOL this clearly isn't catching edge cases
chart._update_yrange_limits()
run_qtrio(_main, (), Chart)

View File

@ -11,7 +11,7 @@ from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import QLineF
from .quantdom.utils import timeit
from .quantdom.base import Quotes
# from .quantdom.base import Quotes
from ._style import _xaxis_at # , _tina_mode
from ._axes import YAxisLabel, XAxisLabel
@ -214,12 +214,12 @@ class BarItems(pg.GraphicsObject):
# indexing here is as per the below comments
lines[3*i:3*i+3] = (
# high_to_low
QLineF(q['id'], q['low'], q['id'], q['high']),
QLineF(q['index'], q['low'], q['index'], q['high']),
# open_sticks
QLineF(q['id'] - self.w, q['open'], q['id'], q['open']),
QLineF(q['index'] - self.w, q['open'], q['index'], q['open']),
# close_sticks
QtCore.QLineF(
q['id'] + self.w, q['close'], q['id'], q['close'])
q['index'] + self.w, q['close'], q['index'], q['close'])
)
else:
self._last_quote = q