2019-07-17 07:37:53 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2019-07-18 04:35:28 +00:00
|
|
|
from vnpy.trader.ui import create_qapp, QtCore
|
2019-07-17 07:37:53 +00:00
|
|
|
from vnpy.trader.database import database_manager
|
|
|
|
from vnpy.trader.constant import Exchange, Interval
|
2019-07-18 04:35:28 +00:00
|
|
|
from vnpy.chart import ChartWidget, VolumeItem, CandleItem
|
2019-07-17 07:37:53 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-07-18 04:35:28 +00:00
|
|
|
app = create_qapp()
|
2019-07-17 07:37:53 +00:00
|
|
|
|
|
|
|
bars = database_manager.load_bar_data(
|
|
|
|
"IF88",
|
|
|
|
Exchange.CFFEX,
|
|
|
|
interval=Interval.MINUTE,
|
|
|
|
start=datetime(2019, 7, 1),
|
|
|
|
end=datetime(2019, 7, 17)
|
|
|
|
)
|
|
|
|
|
|
|
|
widget = ChartWidget()
|
2019-07-18 04:35:28 +00:00
|
|
|
widget.add_plot("candle", hide_x_axis=True)
|
2019-07-18 08:41:40 +00:00
|
|
|
widget.add_plot("volume", maximum_height=200)
|
2019-07-18 04:35:28 +00:00
|
|
|
widget.add_item(CandleItem, "candle", "candle")
|
|
|
|
widget.add_item(VolumeItem, "volume", "volume")
|
|
|
|
widget.add_cursor()
|
|
|
|
|
|
|
|
n = 1000
|
|
|
|
history = bars[:n]
|
|
|
|
new_data = bars[n:]
|
|
|
|
|
|
|
|
widget.update_history(history)
|
2019-07-17 07:37:53 +00:00
|
|
|
|
2019-07-18 04:35:28 +00:00
|
|
|
def update_bar():
|
|
|
|
bar = new_data.pop(0)
|
|
|
|
widget.update_bar(bar)
|
|
|
|
|
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.timeout.connect(update_bar)
|
2019-07-18 13:14:28 +00:00
|
|
|
# timer.start(100)
|
2019-07-18 04:35:28 +00:00
|
|
|
|
|
|
|
widget.show()
|
2019-07-17 07:37:53 +00:00
|
|
|
app.exec_()
|