-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added CandleStick live plot support
- changed update_leading_text, x, y leading line text must be specified now. This was necessary change to display Candlestick plot data. - typing update
- Loading branch information
1 parent
c6d9cd8
commit 7adbea7
Showing
15 changed files
with
265 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import signal | ||
from threading import Thread | ||
|
||
import pglive.examples_pyqt5 as examples | ||
from pglive.sources.data_connector import DataConnector | ||
from pglive.sources.live_candleStickPlot import LiveCandleStickPlot | ||
from pglive.sources.live_plot_widget import LivePlotWidget | ||
|
||
""" | ||
In this example Scatter plot is displayed. | ||
""" | ||
win = LivePlotWidget(title="Candlestick Plot @ 10Hz") | ||
plot = LiveCandleStickPlot() | ||
win.addItem(plot) | ||
|
||
data_connector = DataConnector(plot, max_points=50, update_rate=10) | ||
|
||
win.show() | ||
|
||
Thread(target=examples.candle_generator, args=(data_connector,)).start() | ||
signal.signal(signal.SIGINT, lambda sig, frame: examples.stop()) | ||
examples.app.exec() | ||
examples.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import signal | ||
from threading import Thread | ||
|
||
import pglive.examples_pyqt6 as examples | ||
from pglive.sources.data_connector import DataConnector | ||
from pglive.sources.live_candleStickPlot import LiveCandleStickPlot | ||
from pglive.sources.live_plot_widget import LivePlotWidget | ||
|
||
""" | ||
In this example Scatter plot is displayed. | ||
""" | ||
win = LivePlotWidget(title="Candlestick Plot @ 10Hz") | ||
plot = LiveCandleStickPlot() | ||
win.addItem(plot) | ||
|
||
data_connector = DataConnector(plot, max_points=50, update_rate=10) | ||
|
||
win.show() | ||
|
||
Thread(target=examples.candle_generator, args=(data_connector,)).start() | ||
signal.signal(signal.SIGINT, lambda sig, frame: examples.stop()) | ||
examples.app.exec() | ||
examples.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import signal | ||
from threading import Thread | ||
|
||
import pglive.examples_pyside2 as examples | ||
from pglive.sources.data_connector import DataConnector | ||
from pglive.sources.live_candleStickPlot import LiveCandleStickPlot | ||
from pglive.sources.live_plot_widget import LivePlotWidget | ||
|
||
""" | ||
In this example Scatter plot is displayed. | ||
""" | ||
win = LivePlotWidget(title="Candlestick Plot @ 10Hz") | ||
plot = LiveCandleStickPlot() | ||
win.addItem(plot) | ||
|
||
data_connector = DataConnector(plot, max_points=50, update_rate=10) | ||
|
||
win.show() | ||
|
||
Thread(target=examples.candle_generator, args=(data_connector,)).start() | ||
signal.signal(signal.SIGINT, lambda sig, frame: examples.stop()) | ||
examples.app.exec_() | ||
examples.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import signal | ||
from threading import Thread | ||
|
||
import pglive.examples_pyside6 as examples | ||
from pglive.sources.data_connector import DataConnector | ||
from pglive.sources.live_candleStickPlot import LiveCandleStickPlot | ||
from pglive.sources.live_plot_widget import LivePlotWidget | ||
|
||
""" | ||
In this example Scatter plot is displayed. | ||
""" | ||
win = LivePlotWidget(title="Candlestick Plot @ 10Hz") | ||
plot = LiveCandleStickPlot() | ||
win.addItem(plot) | ||
|
||
data_connector = DataConnector(plot, max_points=50, update_rate=10) | ||
|
||
win.show() | ||
|
||
Thread(target=examples.candle_generator, args=(data_connector,)).start() | ||
signal.signal(signal.SIGINT, lambda sig, frame: examples.stop()) | ||
examples.app.exec() | ||
examples.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from typing import List, Tuple | ||
|
||
import pyqtgraph as pg | ||
from pyqtgraph.Qt import QtCore, QtGui | ||
|
||
from pglive.sources.live_mixins import MixinLivePlot, MixinLeadingLine | ||
|
||
|
||
class LiveCandleStickPlot(pg.GraphicsObject, MixinLivePlot, MixinLeadingLine): | ||
"""Live candlestick plot, plotting data [[open, close, min, max], ...]""" | ||
sigPlotChanged = QtCore.Signal(object) | ||
|
||
def __init__(self, outline_color: str = "w", high_color: str = 'g', low_color: str = 'r') -> None: | ||
"""Choose colors of candle""" | ||
pg.GraphicsObject.__init__(self) | ||
self.x_data = [] | ||
self.y_data = [] | ||
self.outline_pen = pg.mkPen(outline_color) | ||
self.high_brush = pg.mkBrush(high_color) | ||
self.low_brush = pg.mkBrush(low_color) | ||
self.picture = QtGui.QPicture() | ||
|
||
def paint(self, p, *args) -> None: | ||
p.drawPicture(0, 0, self.picture) | ||
|
||
def boundingRect(self) -> QtCore.QRect: | ||
return QtCore.QRectF(self.picture.boundingRect()) | ||
|
||
def setData(self, x_data: List[float], y_data: List[Tuple[float]]) -> None: | ||
"""y_data must be in format [[open, close, min, max], ...]""" | ||
self.x_data = x_data | ||
self.y_data = y_data | ||
if len(x_data) != len(y_data): | ||
raise Exception("Len of x_data must be the same as y_data") | ||
|
||
self.picture = QtGui.QPicture() | ||
p = QtGui.QPainter(self.picture) | ||
p.setPen(self.outline_pen) | ||
try: | ||
w = (x_data[1] - x_data[0]) / 3. | ||
except IndexError: | ||
w = 1 / 3 | ||
|
||
for index, (open, close, min, max) in enumerate(y_data): | ||
t = x_data[index] | ||
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) | ||
if open > close: | ||
p.setBrush(self.low_brush) | ||
else: | ||
p.setBrush(self.high_brush) | ||
p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) | ||
p.end() | ||
|
||
self.prepareGeometryChange() | ||
self.informViewBoundsChanged() | ||
self.bounds = [None, None] | ||
self.sigPlotChanged.emit(self) | ||
|
||
def update_leading_line(self) -> None: | ||
"""Leading line will display all four fields""" | ||
last_x_point = self.x_data[-1] | ||
last_y_point = self.y_data[-1][0] | ||
if self._vl_kwargs is not None: | ||
self._vl_kwargs["line"].setPos(last_x_point) | ||
if self._hl_kwargs is not None: | ||
self._hl_kwargs["line"].setPos(last_y_point) | ||
|
||
y_text = str([round(x, 4) for x in self.y_data[-1]]) | ||
self.update_leading_text(last_x_point, last_y_point, str(last_x_point), y_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.