[Add] Add monitor into mainwindow
@ -15,9 +15,6 @@ def main():
|
|||||||
main_window = MainWindow(main_engine, event_engine)
|
main_window = MainWindow(main_engine, event_engine)
|
||||||
main_window.showMaximized()
|
main_window.showMaximized()
|
||||||
|
|
||||||
monitor = TickMonitor(main_engine, event_engine)
|
|
||||||
monitor.show()
|
|
||||||
|
|
||||||
qapp.exec()
|
qapp.exec()
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from vnpy.event import EventEngine, Event
|
from vnpy.event import EventEngine, Event
|
||||||
|
|
||||||
@ -22,23 +23,6 @@ from .setting import SETTINGS
|
|||||||
from .gateway import BaseGateway
|
from .gateway import BaseGateway
|
||||||
|
|
||||||
|
|
||||||
class BaseEngine(ABC):
|
|
||||||
"""
|
|
||||||
Abstract class for implementing an function engine.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
main_engine: MainEngine,
|
|
||||||
event_engine: EventEngine,
|
|
||||||
engine_name: str
|
|
||||||
):
|
|
||||||
""""""
|
|
||||||
self.main_engine = main_engine
|
|
||||||
self.event_engine = event_engine
|
|
||||||
self.engine_name = engine_name
|
|
||||||
|
|
||||||
|
|
||||||
class MainEngine:
|
class MainEngine:
|
||||||
"""
|
"""
|
||||||
Acts as the core of VN Trader.
|
Acts as the core of VN Trader.
|
||||||
@ -58,7 +42,7 @@ class MainEngine:
|
|||||||
|
|
||||||
self.init_engines()
|
self.init_engines()
|
||||||
|
|
||||||
def add_engine(self, engine_class: BaseEngine):
|
def add_engine(self, engine_class: Any):
|
||||||
"""
|
"""
|
||||||
Add function engine.
|
Add function engine.
|
||||||
"""
|
"""
|
||||||
@ -149,6 +133,23 @@ class MainEngine:
|
|||||||
self.event_engine.stop()
|
self.event_engine.stop()
|
||||||
|
|
||||||
|
|
||||||
|
class BaseEngine(ABC):
|
||||||
|
"""
|
||||||
|
Abstract class for implementing an function engine.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
main_engine: MainEngine,
|
||||||
|
event_engine: EventEngine,
|
||||||
|
engine_name: str
|
||||||
|
):
|
||||||
|
""""""
|
||||||
|
self.main_engine = main_engine
|
||||||
|
self.event_engine = event_engine
|
||||||
|
self.engine_name = engine_name
|
||||||
|
|
||||||
|
|
||||||
class LogEngine(BaseEngine):
|
class LogEngine(BaseEngine):
|
||||||
"""
|
"""
|
||||||
Processes log event and output with logging module.
|
Processes log event and output with logging module.
|
||||||
@ -227,7 +228,7 @@ class OmsEngine(BaseEngine):
|
|||||||
|
|
||||||
def __init__(self, main_engine: MainEngine, event_engine: EventEngine):
|
def __init__(self, main_engine: MainEngine, event_engine: EventEngine):
|
||||||
""""""
|
""""""
|
||||||
super(OmsEngine, self).__init__(main_engine, event_engine, oms)
|
super(OmsEngine, self).__init__(main_engine, event_engine, "oms")
|
||||||
|
|
||||||
self.ticks = {}
|
self.ticks = {}
|
||||||
self.orders = {}
|
self.orders = {}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from vnpy.event import EventEngine, Event
|
from vnpy.event import EventEngine, Event
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import platform
|
import platform
|
||||||
import ctypes
|
import ctypes
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import qdarkstyle
|
import qdarkstyle
|
||||||
from PyQt5 import QtWidgets, QtGui
|
from PyQt5 import QtWidgets, QtGui
|
||||||
@ -7,6 +8,7 @@ from PyQt5 import QtWidgets, QtGui
|
|||||||
from .mainwindow import MainWindow
|
from .mainwindow import MainWindow
|
||||||
from ..setting import SETTINGS
|
from ..setting import SETTINGS
|
||||||
|
|
||||||
|
|
||||||
def create_qapp():
|
def create_qapp():
|
||||||
"""
|
"""
|
||||||
Create Qt Application.
|
Create Qt Application.
|
||||||
@ -17,8 +19,14 @@ def create_qapp():
|
|||||||
font = QtGui.QFont(SETTINGS["font.family"], SETTINGS["font.size"])
|
font = QtGui.QFont(SETTINGS["font.family"], SETTINGS["font.size"])
|
||||||
qapp.setFont(font)
|
qapp.setFont(font)
|
||||||
|
|
||||||
|
ui_path = Path(__file__).parent
|
||||||
|
icon_path = ui_path.joinpath("ico", "vnpy.ico")
|
||||||
|
icon = QtGui.QIcon(str(icon_path))
|
||||||
|
qapp.setWindowIcon(icon)
|
||||||
|
|
||||||
if 'Windows' in platform.uname():
|
if 'Windows' in platform.uname():
|
||||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
|
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
|
||||||
'VN Trader')
|
'VN Trader'
|
||||||
|
)
|
||||||
|
|
||||||
return qapp
|
return qapp
|
BIN
vnpy/trader/ui/ico/about.ico
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
vnpy/trader/ui/ico/connect.ico
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
vnpy/trader/ui/ico/contract.ico
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
vnpy/trader/ui/ico/database.ico
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
vnpy/trader/ui/ico/editor.ico
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
vnpy/trader/ui/ico/exit.ico
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
vnpy/trader/ui/ico/restore.ico
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
vnpy/trader/ui/ico/test.ico
Normal file
After Width: | Height: | Size: 51 KiB |
BIN
vnpy/trader/ui/ico/vnpy.ico
Normal file
After Width: | Height: | Size: 66 KiB |
@ -1,7 +1,15 @@
|
|||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets, QtCore
|
||||||
|
|
||||||
from vnpy.event import EventEngine
|
from vnpy.event import EventEngine
|
||||||
from ..engine import MainEngine
|
from ..engine import MainEngine
|
||||||
|
from .widget import (
|
||||||
|
TickMonitor,
|
||||||
|
OrderMonitor,
|
||||||
|
TradeMonitor,
|
||||||
|
PositionMonitor,
|
||||||
|
AccountMonitor,
|
||||||
|
LogMonitor
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
@ -15,12 +23,43 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.main_engine = main_engine
|
self.main_engine = main_engine
|
||||||
self.event_engine = event_engine
|
self.event_engine = event_engine
|
||||||
|
|
||||||
|
self.widgets = {}
|
||||||
|
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
|
||||||
def init_ui(self):
|
def init_ui(self):
|
||||||
""""""
|
""""""
|
||||||
self.setWindowTitle("VN Trader")
|
self.setWindowTitle("VN Trader")
|
||||||
|
self.init_dock()
|
||||||
|
self.init_menu()
|
||||||
|
|
||||||
def register_event(self):
|
def init_dock(self):
|
||||||
""""""
|
""""""
|
||||||
pass
|
tick_widget, tick_dock = self.create_dock(TickMonitor, "行情", QtCore.Qt.RightDockWidgetArea)
|
||||||
|
order_widget, order_dock = self.create_dock(OrderMonitor, "委托", QtCore.Qt.RightDockWidgetArea)
|
||||||
|
trade_widget, trade_dock = self.create_dock(TradeMonitor, "成交", QtCore.Qt.RightDockWidgetArea)
|
||||||
|
log_widget, log_dock = self.create_dock(LogMonitor, "日志", QtCore.Qt.BottomDockWidgetArea)
|
||||||
|
account_widget, account_dock = self.create_dock(AccountMonitor, "资金", QtCore.Qt.BottomDockWidgetArea)
|
||||||
|
position_widget, position_dock = self.create_dock(PositionMonitor, "持仓", QtCore.Qt.BottomDockWidgetArea)
|
||||||
|
|
||||||
|
def init_menu(self):
|
||||||
|
""""""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def create_dock(
|
||||||
|
self,
|
||||||
|
widget_class: QtWidgets.QWidget,
|
||||||
|
name: str,
|
||||||
|
area: int
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Initialize a dock widget.
|
||||||
|
"""
|
||||||
|
widget = widget_class(self.main_engine, self.event_engine)
|
||||||
|
|
||||||
|
dock = QtWidgets.QDockWidget(name)
|
||||||
|
dock.setWidget(widget)
|
||||||
|
dock.setObjectName(name)
|
||||||
|
dock.setFeatures(dock.DockWidgetFloatable | dock.DockWidgetMovable)
|
||||||
|
self.addDockWidget(area, dock)
|
||||||
|
return widget, dock
|
@ -581,5 +581,10 @@ class AccountMonitor(BaseMonitor):
|
|||||||
'display': '可用',
|
'display': '可用',
|
||||||
'cell': BaseCell,
|
'cell': BaseCell,
|
||||||
'update': True
|
'update': True
|
||||||
|
},
|
||||||
|
'gateway_name': {
|
||||||
|
'display': '接口',
|
||||||
|
'cell': BaseCell,
|
||||||
|
'update': False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,4 +50,4 @@ def check_order_active(status: str):
|
|||||||
if status in ACTIVE_STATUSES:
|
if status in ACTIVE_STATUSES:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|