Rip out all usage of `quantdom.bases.Quotes` smh.
parent
feccadc331
commit
48f266e276
|
@ -5,7 +5,7 @@ import pyqtgraph as pg
|
||||||
from PyQt5 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui
|
||||||
|
|
||||||
|
|
||||||
from .quantdom.base import Quotes
|
# from .quantdom.base import Quotes
|
||||||
from .quantdom.utils import fromtimestamp
|
from .quantdom.utils import fromtimestamp
|
||||||
from ._style import _font
|
from ._style import _font
|
||||||
|
|
||||||
|
@ -36,10 +36,11 @@ class PriceAxis(pg.AxisItem):
|
||||||
class FromTimeFieldDateAxis(pg.AxisItem):
|
class FromTimeFieldDateAxis(pg.AxisItem):
|
||||||
tick_tpl = {'D1': '%Y-%b-%d'}
|
tick_tpl = {'D1': '%Y-%b-%d'}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, splitter, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.splitter = splitter
|
||||||
self.setTickFont(_font)
|
self.setTickFont(_font)
|
||||||
self.quotes_count = len(Quotes) - 1
|
# self.quotes_count = len(self.splitter.chart._array) - 1
|
||||||
|
|
||||||
# default styling
|
# default styling
|
||||||
self.setStyle(
|
self.setStyle(
|
||||||
|
@ -56,10 +57,13 @@ class FromTimeFieldDateAxis(pg.AxisItem):
|
||||||
# strings = super().tickStrings(values, scale, spacing)
|
# strings = super().tickStrings(values, scale, spacing)
|
||||||
s_period = 'D1'
|
s_period = 'D1'
|
||||||
strings = []
|
strings = []
|
||||||
|
quotes_count = len(self.splitter.chart._array) - 1
|
||||||
|
|
||||||
for ibar in values:
|
for ibar in values:
|
||||||
if ibar > self.quotes_count:
|
if ibar > quotes_count:
|
||||||
return strings
|
return strings
|
||||||
dt_tick = fromtimestamp(Quotes[int(ibar)].time)
|
bars = self.splitter.chart._array
|
||||||
|
dt_tick = fromtimestamp(bars[int(ibar)].time)
|
||||||
strings.append(
|
strings.append(
|
||||||
dt_tick.strftime(self.tick_tpl[s_period])
|
dt_tick.strftime(self.tick_tpl[s_period])
|
||||||
)
|
)
|
||||||
|
@ -140,9 +144,10 @@ class XAxisLabel(AxisLabel):
|
||||||
def tick_to_string(self, tick_pos):
|
def tick_to_string(self, tick_pos):
|
||||||
# TODO: change to actual period
|
# TODO: change to actual period
|
||||||
tpl = self.parent.tick_tpl['D1']
|
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 'Unknown Time'
|
||||||
return fromtimestamp(Quotes[round(tick_pos)].time).strftime(tpl)
|
return fromtimestamp(bars[round(tick_pos)].time).strftime(tpl)
|
||||||
|
|
||||||
def boundingRect(self): # noqa
|
def boundingRect(self): # noqa
|
||||||
return QtCore.QRectF(0, 0, 145, 50)
|
return QtCore.QRectF(0, 0, 145, 50)
|
||||||
|
|
|
@ -16,7 +16,7 @@ from ._style import _xaxis_at
|
||||||
from ._source import Symbol, ohlc_zeros
|
from ._source import Symbol, ohlc_zeros
|
||||||
|
|
||||||
from .quantdom.charts import CenteredTextItem
|
from .quantdom.charts import CenteredTextItem
|
||||||
from .quantdom.base import Quotes
|
# from .quantdom.base import Quotes
|
||||||
# from .quantdom.const import ChartType
|
# from .quantdom.const import ChartType
|
||||||
from .quantdom.portfolio import Order, Portfolio
|
from .quantdom.portfolio import Order, Portfolio
|
||||||
|
|
||||||
|
@ -101,10 +101,11 @@ class SplitterPlots(QtGui.QWidget):
|
||||||
self.signals_visible = False
|
self.signals_visible = False
|
||||||
self.indicators = []
|
self.indicators = []
|
||||||
|
|
||||||
self.xaxis = FromTimeFieldDateAxis(orientation='bottom')
|
self.xaxis = FromTimeFieldDateAxis(orientation='bottom', splitter=self)
|
||||||
# self.xaxis = pg.DateAxisItem()
|
# self.xaxis = pg.DateAxisItem()
|
||||||
|
|
||||||
self.xaxis_ind = FromTimeFieldDateAxis(orientation='bottom')
|
self.xaxis_ind = FromTimeFieldDateAxis(
|
||||||
|
orientation='bottom', splitter=self)
|
||||||
|
|
||||||
if _xaxis_at == 'bottom':
|
if _xaxis_at == 'bottom':
|
||||||
self.xaxis.setStyle(showValues=False)
|
self.xaxis.setStyle(showValues=False)
|
||||||
|
@ -174,7 +175,9 @@ class SplitterPlots(QtGui.QWidget):
|
||||||
self.chart.draw_ohlc(data)
|
self.chart.draw_ohlc(data)
|
||||||
|
|
||||||
# TODO: this is where we would load an indicator chain
|
# 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:
|
for d in inds:
|
||||||
cv = ChartView()
|
cv = ChartView()
|
||||||
|
@ -377,8 +380,8 @@ class ChartPlotWidget(pg.PlotWidget):
|
||||||
|
|
||||||
# update view limits
|
# update view limits
|
||||||
self.set_view_limits(
|
self.set_view_limits(
|
||||||
data[0]['id'],
|
data[0]['index'],
|
||||||
data[-1]['id'],
|
data[-1]['index'],
|
||||||
data['low'].min(),
|
data['low'].min(),
|
||||||
data['high'].max()
|
data['high'].max()
|
||||||
)
|
)
|
||||||
|
@ -525,6 +528,7 @@ def main(symbol):
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from ._exec import run_qtrio
|
from ._exec import run_qtrio
|
||||||
|
from ._source import from_df
|
||||||
# uses pandas_datareader
|
# uses pandas_datareader
|
||||||
from .quantdom.loaders import get_quotes
|
from .quantdom.loaders import get_quotes
|
||||||
|
|
||||||
|
@ -539,15 +543,28 @@ def main(symbol):
|
||||||
date_from=datetime(1900, 1, 1),
|
date_from=datetime(1900, 1, 1),
|
||||||
date_to=datetime(2030, 12, 31),
|
date_to=datetime(2030, 12, 31),
|
||||||
)
|
)
|
||||||
|
quotes = from_df(quotes)
|
||||||
|
|
||||||
# spawn chart
|
# spawn chart
|
||||||
splitter_chart = chart_app.load_symbol(symbol, quotes)
|
splitter_chart = chart_app.load_symbol(symbol, quotes)
|
||||||
import itertools
|
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:
|
while True:
|
||||||
await trio.sleep(0.05)
|
await trio.sleep(0.1)
|
||||||
splitter_chart.chart._graphics['ohlc'].update_last_bar(
|
new = next(nums)
|
||||||
{'last': next(nums)})
|
quotes[-1].close = new
|
||||||
# splitter_chart.chart.plotItem.sigPlotChanged.emit(self)
|
chart._graphics['ohlc'].update_last_bar({'last': new})
|
||||||
# breakpoint()
|
|
||||||
|
# LOL this clearly isn't catching edge cases
|
||||||
|
chart._update_yrange_limits()
|
||||||
|
|
||||||
run_qtrio(_main, (), Chart)
|
run_qtrio(_main, (), Chart)
|
||||||
|
|
|
@ -11,7 +11,7 @@ from PyQt5 import QtCore, QtGui
|
||||||
from PyQt5.QtCore import QLineF
|
from PyQt5.QtCore import QLineF
|
||||||
|
|
||||||
from .quantdom.utils import timeit
|
from .quantdom.utils import timeit
|
||||||
from .quantdom.base import Quotes
|
# from .quantdom.base import Quotes
|
||||||
|
|
||||||
from ._style import _xaxis_at # , _tina_mode
|
from ._style import _xaxis_at # , _tina_mode
|
||||||
from ._axes import YAxisLabel, XAxisLabel
|
from ._axes import YAxisLabel, XAxisLabel
|
||||||
|
@ -214,12 +214,12 @@ class BarItems(pg.GraphicsObject):
|
||||||
# indexing here is as per the below comments
|
# indexing here is as per the below comments
|
||||||
lines[3*i:3*i+3] = (
|
lines[3*i:3*i+3] = (
|
||||||
# high_to_low
|
# high_to_low
|
||||||
QLineF(q['id'], q['low'], q['id'], q['high']),
|
QLineF(q['index'], q['low'], q['index'], q['high']),
|
||||||
# open_sticks
|
# 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
|
# close_sticks
|
||||||
QtCore.QLineF(
|
QtCore.QLineF(
|
||||||
q['id'] + self.w, q['close'], q['id'], q['close'])
|
q['index'] + self.w, q['close'], q['index'], q['close'])
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._last_quote = q
|
self._last_quote = q
|
||||||
|
|
Loading…
Reference in New Issue