Esempio n. 1
0
 def initUi(self):
     """初始化界面"""
     self.setWindowTitle(u'CTA Strategy')
     
     # 按钮
     loadButton = QtWidgets.QPushButton(u'Load Strategy')
     updateMCButton = QtWidgets.QPushButton(u'Update Margin/Commission')
     
     loadButton.clicked.connect(self.load)
     updateMCButton.clicked.connect(self.updateMC)
     
     # 滚动区域,放置所有的ArbStrategyManager
     self.scrollArea = QtWidgets.QScrollArea()
     self.scrollArea.setWidgetResizable(True)
     
     # ARB组件的日志监控
     self.arbLogMonitor = QtWidgets.QTextEdit()
     self.arbLogMonitor.setReadOnly(True)
     self.arbLogMonitor.setMaximumHeight(200)
     
     # 设置布局
     hbox2 = QtWidgets.QHBoxLayout()
     hbox2.addWidget(loadButton)
     hbox2.addWidget(updateMCButton)
     hbox2.addStretch()
     
     vbox = QtWidgets.QVBoxLayout()
     vbox.addLayout(hbox2)
     vbox.addWidget(self.scrollArea)
     vbox.addWidget(self.arbLogMonitor)
     self.setLayout(vbox)
Esempio n. 2
0
    def updateStatus(self, status_dict):
        """更新状态数据"""
        if not self.mainEngine:
            return

        if not self.initVarMonitors:
            w = QtWidgets.QWidget()
            self.monitor_vbox = QtWidgets.QVBoxLayout()

            strategy_names = status_dict.keys()
            sorted_strategy_names = sorted(strategy_names)
            for k in sorted_strategy_names:
                monitor = StrategyMonitorWidget(name=k,
                                                mainEngine=self.mainEngine,
                                                parent=self)
                self.strategy_monitors[k] = monitor
                self.monitor_vbox.addWidget(monitor)

            w.setLayout(self.monitor_vbox)
            self.scrollArea.setWidget(w)
            self.initVarMonitors = True

        for k, v in status_dict.items():
            if k in self.strategy_monitors:
                monitor = self.strategy_monitors[k]
                monitor.updateStatus(v)
            else:
                monitor = StrategyMonitorWidget(name=k,
                                                mainEngine=self.mainEngine,
                                                parent=self)
                self.strategy_monitors[k] = monitor
                if self.monitor_vbox is not None:
                    self.monitor_vbox.addWidget(monitor)
                monitor.updateStatus(v)
Esempio n. 3
0
    def updateStatus(self, status_dict):
        """更新状态数据"""
        if not self.mainEngine:
            return

        if not self.initVarMonitors:
            w = QtWidgets.QWidget()
            vbox = QtWidgets.QVBoxLayout()
            for k, v in status_dict.items():
                monitor = StrategyMonitorWidget(name=k,
                                                mainEngine=self.mainEngine,
                                                parent=self)
                #height = 65
                #monitor.setFixedHeight(height)

                self.strategy_monitors[k] = monitor
                vbox.addWidget(monitor)

            w.setLayout(vbox)
            self.scrollArea.setWidget(w)
            self.initVarMonitors = True

        for k, v in status_dict.items():
            if k in self.strategy_monitors:
                monitor = self.strategy_monitors[k]
                monitor.updateStatus(v)
Esempio n. 4
0
    def initUi(self):
        self.setTitle(self.name)
        # 策略的操作按钮:初始化/启动/停止/强制初始化
        btnInitStrategy = QtWidgets.QPushButton(u'Init')
        btnInitStrategy.clicked.connect(self.init_strategy)
        btnStartStrategy = QtWidgets.QPushButton(u'Start')
        btnStartStrategy.clicked.connect(self.start_strategy)
        btnStopStrategy = QtWidgets.QPushButton(u'Stop')
        btnStopStrategy.clicked.connect(self.stop_strategy)
        btnForceInitStrategy = QtWidgets.QPushButton(u'ForceInit')
        btnForceInitStrategy.clicked.connect(self.force_init_strategy)
        btnDispatchOutStrategy = QtWidgets.QPushButton(u'Dispatch Out')
        btnDispatchOutStrategy.clicked.connect(self.remove_strategy)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(btnInitStrategy)
        hbox1.addWidget(btnStartStrategy)
        hbox1.addWidget(btnStopStrategy)
        hbox1.addWidget(btnForceInitStrategy)
        #hbox1.addWidget(btnDispatchOutStrategy)
        hbox1.addStretch()

        # 策略的运行数据表
        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(self.varTable)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        self.setLayout(vbox)
Esempio n. 5
0
    def initUi(self):
        """初始化界面"""
        self.setTitle(self.name)
        self.paramMonitor = CtaValueMonitor(self)
        self.varMonitor = CtaValueMonitor(self)

        # height = 70
        # self.paramMonitor.setFixedHeight(height)
        # self.varMonitor.setFixedHeight(height)

        buttonInit = QtWidgets.QPushButton(text.INIT)
        buttonStart = QtWidgets.QPushButton(text.START)
        buttonStop = QtWidgets.QPushButton(text.STOP)
        buttonInit.clicked.connect(self.init)
        buttonStart.clicked.connect(self.start)
        buttonStop.clicked.connect(self.stop)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(buttonInit)
        hbox1.addWidget(buttonStart)
        hbox1.addWidget(buttonStop)
        hbox1.addStretch()

        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(self.paramMonitor)

        hbox3 = QtWidgets.QHBoxLayout()
        hbox3.addWidget(self.varMonitor)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)
        self.setLayout(vbox)
Esempio n. 6
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(u'行情数据记录工具')

        # 记录合约配置监控
        tickLabel = QtWidgets.QLabel(u'Tick记录')
        self.tickTable = QtWidgets.QTableWidget()
        self.tickTable.setColumnCount(2)
        self.tickTable.verticalHeader().setVisible(False)
        self.tickTable.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
        self.tickTable.horizontalHeader().setResizeMode(
            QtWidgets.QHeaderView.Stretch)
        self.tickTable.setAlternatingRowColors(True)
        self.tickTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])

        barLabel = QtWidgets.QLabel(u'Bar记录')
        self.barTable = QtWidgets.QTableWidget()
        self.barTable.setColumnCount(2)
        self.barTable.verticalHeader().setVisible(False)
        self.barTable.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
        self.barTable.horizontalHeader().setResizeMode(
            QtWidgets.QHeaderView.Stretch)
        self.barTable.setAlternatingRowColors(True)
        self.barTable.setHorizontalHeaderLabels([u'合约代码', u'接口'])

        activeLabel = QtWidgets.QLabel(u'主力合约')
        self.activeTable = QtWidgets.QTableWidget()
        self.activeTable.setColumnCount(2)
        self.activeTable.verticalHeader().setVisible(False)
        self.activeTable.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
        self.activeTable.horizontalHeader().setResizeMode(
            QtWidgets.QHeaderView.Stretch)
        self.activeTable.setAlternatingRowColors(True)
        self.activeTable.setHorizontalHeaderLabels([u'主力代码', u'合约代码'])

        # 日志监控
        self.logMonitor = QtWidgets.QTextEdit()
        self.logMonitor.setReadOnly(True)
        self.logMonitor.setMinimumHeight(600)

        # 设置布局
        grid = QtWidgets.QGridLayout()

        grid.addWidget(tickLabel, 0, 0)
        grid.addWidget(barLabel, 0, 1)
        grid.addWidget(activeLabel, 0, 2)
        grid.addWidget(self.tickTable, 1, 0)
        grid.addWidget(self.barTable, 1, 1)
        grid.addWidget(self.activeTable, 1, 2)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addWidget(self.logMonitor)
        self.setLayout(vbox)
Esempio n. 7
0
    def initUi(self):
        Label = QtWidgets.QLabel
        grid = QtWidgets.QGridLayout()
        grid.addWidget(Label(u'CPU'), 0, 0)
        grid.addWidget(self.label_cpu_percent, 0, 1)
        grid.addWidget(Label(u'Memory'), 0, 2)
        grid.addWidget(self.label_mem_percent, 0, 3)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(grid)
        self.setLayout(vbox)
Esempio n. 8
0
    def __init__(self, parent=None):
        """Constructor"""
        super(CtaEngineMonitorWidget, self).__init__(parent)
        self.mainEngine = None
        self.strategy_monitors = {}

        self.scrollArea = QtWidgets.QScrollArea()
        self.scrollArea.setWidgetResizable(True)

        self.scrollLayout = QtWidgets.QVBoxLayout()

        self.initUi()
        self.initVarMonitors = False
Esempio n. 9
0
    def initStrategyManager(self):
        """初始化策略管理组件界面"""
        w = QtWidgets.QWidget()
        vbox = QtWidgets.QVBoxLayout()

        for name in list(self.ctaEngine.strategyDict.keys()):
            strategyManager = CtaStrategyManager(self.ctaEngine, self.eventEngine, name)
            vbox.addWidget(strategyManager)

        vbox.addStretch()

        w.setLayout(vbox)
        self.scrollArea.setWidget(w)
Esempio n. 10
0
    def initUi(self):
        """初始化界面"""
        self.lineSymbol = QtWidgets.QLineEdit(u'rb1805')
        self.pushButton = QtWidgets.QPushButton(u'订阅合约')

        self.pushButton.clicked.connect(self.symbolTextSelect)
        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(self.lineSymbol)
        hbox.addWidget(self.pushButton)
        hbox.addStretch()

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox)

        self.setLayout(vbox)
Esempio n. 11
0
 def initStrategyManager(self):
     """初始化策略管理组件界面"""        
     w = QtWidgets.QWidget()
     vbox = QtWidgets.QVBoxLayout()
     
     for name in self.cmaEngine.strategyDict.keys():
         # 为每一个策略实例,创建对应的管理组件实例
         strategyManager = CmaStrategyManager(self.cmaEngine, self.eventEngine, name)
         vbox.addWidget(strategyManager)
         sleep(0.2)
     
     vbox.addStretch()
     
     w.setLayout(vbox)
     self.scrollArea.setWidget(w)   
Esempio n. 12
0
    def initStrategyManager(self):
        """初始化策略管理组件界面"""
        w = QtWidgets.QWidget()
        vbox = QtWidgets.QVBoxLayout()

        l = self.account.getStrategyNames()
        for name in l:
            strategyManager = AShStrategyManager(self.account,
                                                 self._eventChannel, name)
            vbox.addWidget(strategyManager)

        vbox.addStretch()

        w.setLayout(vbox)
        self.scrollArea.setWidget(w)
Esempio n. 13
0
    def initStrategyManager(self):
        """初始化策略管理组件界面"""        
        w = QtWidgets.QWidget()
	vbox = QtWidgets.QVBoxLayout()
        
        for name in sorted(self.arbEngine.strategyDict.keys()):
	    if name not in self.nameList:
		strategyManager = ArbStrategyManager(self.arbEngine, self.eventEngine, name)
		self.strategyManagers[name] = strategyManager
	    else:
		strategyManager = self.strategyManagers[name]
	    vbox.addWidget(strategyManager)
	    self.nameList.append(name)
        
        vbox.addStretch()
        
        w.setLayout(vbox)
        self.scrollArea.setWidget(w)   
Esempio n. 14
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(text.CTA_STRATEGY)

        # 按钮
        loadButton = QtWidgets.QPushButton(text.LOAD_STRATEGY)
        initAllButton = QtWidgets.QPushButton(text.INIT_ALL)
        startAllButton = QtWidgets.QPushButton(text.START_ALL)
        stopAllButton = QtWidgets.QPushButton(text.STOP_ALL)

        loadButton.clicked.connect(self.load)
        initAllButton.clicked.connect(self.initAll)
        startAllButton.clicked.connect(self.startAll)
        stopAllButton.clicked.connect(self.stopAll)

        # 滚动区域,放置所有的CtaStrategyManager
        self.scrollArea = QtWidgets.QScrollArea()
        self.scrollArea.setWidgetResizable(True)

        # CTA组件的日志监控
        self.ctaLogMonitor = QtWidgets.QTextEdit()
        self.ctaLogMonitor.setReadOnly(True)
        self.ctaLogMonitor.setMaximumHeight(200)

        # 设置布局
        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(loadButton)
        hbox2.addWidget(initAllButton)
        hbox2.addWidget(startAllButton)
        hbox2.addWidget(stopAllButton)
        hbox2.addStretch()

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox2)
        vbox.addWidget(self.scrollArea)
        vbox.addWidget(self.ctaLogMonitor)

        self.setLayout(vbox)
        self.resize(1024, 800)  #ROBINLIN

        # ROBINLIN 窗口显示后,立即加载和初始化策略。
        self.load()
        self.initAll()
        self.startAll()
Esempio n. 15
0
    def initUi(self):
        """初始化界面"""
        self.setTitle(self.name)

        self.paramMonitor = CtaValueMonitor(self)
        self.varMonitor = CtaValueMonitor(self)
        self.dictMonitor = GridControlDictMonitor(self)

        height = 65
        self.paramMonitor.setFixedHeight(height)
        self.varMonitor.setFixedHeight(height)

        buttonInit = QtWidgets.QPushButton(text.INIT)
        buttonStart = QtWidgets.QPushButton(text.START)
        buttonStop = QtWidgets.QPushButton(text.STOP)
        buttonInit.clicked.connect(self.init)
        buttonStart.clicked.connect(self.start)
        buttonStop.clicked.connect(self.stop)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(buttonInit)
        hbox1.addWidget(buttonStart)
        hbox1.addWidget(buttonStop)
        hbox1.addStretch()

        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(self.paramMonitor)

        hbox3 = QtWidgets.QHBoxLayout()
        hbox3.addWidget(self.varMonitor)

        # ROBINLIN add QTableWidget to show the control_dic
        hbox4 = QtWidgets.QHBoxLayout()
        hbox4.addWidget(self.dictMonitor)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)
        vbox.addLayout(hbox4)

        self.setLayout(vbox)
Esempio n. 16
0
    def initUi(self):
        btnLoadStrategies = QtWidgets.QPushButton(u'Load All Strategies')
        btnStartStrategies = QtWidgets.QPushButton(u'Start All Strategies')
        btnStopStrategies = QtWidgets.QPushButton(u'Stop All Strategies')

        btnLoadStrategies.clicked.connect(self.load_all_strategies)
        btnStartStrategies.clicked.connect(self.start_all_strategies)
        btnStopStrategies.clicked.connect(self.stop_all_strategies)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(btnLoadStrategies)
        hbox1.addWidget(btnStartStrategies)
        hbox1.addWidget(btnStopStrategies)
        hbox1.addStretch()

        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.addLayout(hbox1)
        self.vbox.addWidget(self.scrollArea)

        self.setLayout(self.vbox)
Esempio n. 17
0
    def load_rpc_servers(self):
        """从vt_Setting.Json加载所有RPC服务器信息"""

        if self.rpc_servers_loaded:
            QtWidgets.QMessageBox.warning(self, u'Already Loaded')
            return

        try:
            zmqAddressDict = globalSetting['ZMQ']

            w = QtWidgets.QWidget()
            vbox = QtWidgets.QVBoxLayout()

            for k, v in zmqAddressDict.items():
                if k == 'CTP_Post':
                    continue
                reqAddress = v['ReqAddress']
                pubAddress = v['PubAddress']
                subscribes = v['SubscribeTopic']
                sub_window = QtWidgets.QMdiSubWindow()
                sub_window.setWindowTitle(k)
                rpc_monitor = RpcServerMonitor(name=k,
                                               req_addr=reqAddress,
                                               sub_addr=pubAddress,
                                               sub_topics=subscribes,
                                               parent=self)
                sub_window.setWidget(rpc_monitor)
                self.mdi.addSubWindow(rpc_monitor)
                rpc_monitor.show()

            self.mdi.tileSubWindows()

        except Exception as ex:
            traceback.print_exc()
            QtWidgets.QMessageBox.warning(self, 'Exception',
                                          u'Load vt_Setting.json Exception',
                                          QtWidgets.QMessageBox.Cancel,
                                          QtWidgets.QMessageBox.NoButton,
                                          QtGui.QMessageBox.NoButton)

            return
Esempio n. 18
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(text.CTA_STRATEGY)

        # 按钮
        loadButton = QtWidgets.QPushButton(text.LOAD_STRATEGY)
        initAllButton = QtWidgets.QPushButton(text.INIT_ALL)
        startAllButton = QtWidgets.QPushButton(text.START_ALL)
        stopAllButton = QtWidgets.QPushButton(text.STOP_ALL)
        savePositionButton = QtWidgets.QPushButton(text.SAVE_POSITION_DATA)

        loadButton.clicked.connect(self.load)
        initAllButton.clicked.connect(self.initAll)
        startAllButton.clicked.connect(self.startAll)
        stopAllButton.clicked.connect(self.stopAll)
        savePositionButton.clicked.connect(self.ctaEngine.savePosition)

        # 滚动区域,放置所有的CtaStrategyManager
        self.scrollArea = QtWidgets.QScrollArea()
        self.scrollArea.setWidgetResizable(True)

        # CTA组件的日志监控
        self.ctaLogMonitor = QtWidgets.QTextEdit()
        self.ctaLogMonitor.setReadOnly(True)
        self.ctaLogMonitor.setMaximumHeight(200)

        # 设置布局
        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(loadButton)
        hbox2.addWidget(initAllButton)
        hbox2.addWidget(startAllButton)
        hbox2.addWidget(stopAllButton)
        hbox2.addWidget(savePositionButton)
        hbox2.addStretch()

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox2)
        vbox.addWidget(self.scrollArea)
        vbox.addWidget(self.ctaLogMonitor)
        self.setLayout(vbox)
Esempio n. 19
0
    def initUi(self):
        """初始化界面"""
        self.setTitle(self.name)

        self.paramMonitor = ValueMonitor(True, self)
        self.varMonitor = ValueMonitor(False, self)

        height = 65
        self.paramMonitor.setFixedHeight(height)
        self.varMonitor.setFixedHeight(height)

        buttonInit = QtWidgets.QPushButton(u'初始化')
        buttonStart = QtWidgets.QPushButton(u'启动')
        buttonStop = QtWidgets.QPushButton(u'停止')
        buttonInit.clicked.connect(self.init)
        buttonStart.clicked.connect(self.start)
        buttonStop.clicked.connect(self.stop)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(buttonInit)
        hbox1.addWidget(buttonStart)
        hbox1.addWidget(buttonStop)
        hbox1.addStretch()

        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(self.paramMonitor)

        hbox3 = QtWidgets.QHBoxLayout()
        hbox3.addWidget(self.varMonitor)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)

        self.setLayout(vbox)

        self.paramMonitor.itemChanged.connect(self.setParam)
Esempio n. 20
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(u'期权策略')

        # 按钮
        loadButton = QtWidgets.QPushButton(u'加载策略')
        initAllButton = QtWidgets.QPushButton(u'全部初始化')
        startAllButton = QtWidgets.QPushButton(u'全部启动')
        stopAllButton = QtWidgets.QPushButton(u'全部停止')

        loadButton.clicked.connect(self.load)
        initAllButton.clicked.connect(self.initAll)
        startAllButton.clicked.connect(self.startAll)
        stopAllButton.clicked.connect(self.stopAll)

        # 滚动区域,放置所有的StrategyManager
        self.scrollArea = QtWidgets.QScrollArea()
        self.scrollArea.setWidgetResizable(True)

        # 日志监控
        self.ctaLogMonitor = QtWidgets.QTextEdit()
        self.ctaLogMonitor.setReadOnly(True)
        self.ctaLogMonitor.setMaximumHeight(200)

        # 设置布局
        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(loadButton)
        hbox2.addWidget(initAllButton)
        hbox2.addWidget(startAllButton)
        hbox2.addWidget(stopAllButton)
        hbox2.addStretch()

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox2)
        vbox.addWidget(self.scrollArea)
        vbox.addWidget(self.ctaLogMonitor)
        self.setLayout(vbox)
Esempio n. 21
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(u'风险管理')

        # 设置界面
        self.buttonSwitchEngineStatus = QtWidgets.QPushButton(u'风控模块未启动')

        self.spinOrderFlowLimit = RmSpinBox(self.rmEngine.orderFlowLimit)
        self.spinOrderFlowClear = RmSpinBox(self.rmEngine.orderFlowClear)
        self.spinOrderSizeLimit = RmSpinBox(self.rmEngine.orderSizeLimit)
        self.spinTradeLimit = RmSpinBox(self.rmEngine.tradeLimit)
        self.spinWorkingOrderLimit = RmSpinBox(self.rmEngine.workingOrderLimit)

        # 最大开仓比例
        self.spinPercentLimit = RmSpinBox(self.rmEngine.percentLimit)

        # 最大净值止损比例,满足后强制止损
        self.spinLossLimit = RmSpinBox(self.rmEngine.lossLimit)

        buttonClearOrderFlowCount = QtWidgets.QPushButton(u'清空流控计数')
        buttonClearTradeCount = QtWidgets.QPushButton(u'清空总成交计数')
        buttonSaveSetting = QtWidgets.QPushButton(u'保存设置')

        Label = QtWidgets.QLabel
        grid = QtWidgets.QGridLayout()
        grid.addWidget(Label(u'工作状态'), 0, 0)
        grid.addWidget(self.buttonSwitchEngineStatus, 0, 1)
        grid.addWidget(RmLine(), 1, 0, 1, 2)
        grid.addWidget(Label(u'流控上限'), 2, 0)
        grid.addWidget(self.spinOrderFlowLimit, 2, 1)
        grid.addWidget(Label(u'流控清空(秒)'), 3, 0)
        grid.addWidget(self.spinOrderFlowClear, 3, 1)
        grid.addWidget(RmLine(), 4, 0, 1, 2)
        grid.addWidget(Label(u'单笔委托上限'), 5, 0)
        grid.addWidget(self.spinOrderSizeLimit, 5, 1)
        grid.addWidget(RmLine(), 6, 0, 1, 2)
        grid.addWidget(Label(u'总成交上限'), 7, 0)
        grid.addWidget(self.spinTradeLimit, 7, 1)
        grid.addWidget(RmLine(), 8, 0, 1, 2)
        grid.addWidget(Label(u'活动订单上限'), 9, 0)
        grid.addWidget(self.spinWorkingOrderLimit, 9, 1)

        grid.addWidget(RmLine(), 10, 0, 1, 2)
        grid.addWidget(Label(u'仓位上限(1~100)'), 11, 0)
        grid.addWidget(self.spinPercentLimit, 11, 1)
        grid.addWidget(Label(u'强制止损净值'), 12, 0)
        grid.addWidget(self.spinLossLimit, 12, 1)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(buttonClearOrderFlowCount)
        hbox.addWidget(buttonClearTradeCount)
        hbox.addStretch()
        hbox.addWidget(buttonSaveSetting)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addLayout(hbox)
        self.setLayout(vbox)

        # 连接组件信号
        self.spinOrderFlowLimit.valueChanged.connect(
            self.rmEngine.setOrderFlowLimit)
        self.spinOrderFlowClear.valueChanged.connect(
            self.rmEngine.setOrderFlowClear)
        self.spinOrderSizeLimit.valueChanged.connect(
            self.rmEngine.setOrderSizeLimit)
        self.spinTradeLimit.valueChanged.connect(self.rmEngine.setTradeLimit)
        self.spinWorkingOrderLimit.valueChanged.connect(
            self.rmEngine.setWorkingOrderLimit)
        self.spinPercentLimit.valueChanged.connect(
            self.rmEngine.setAccountPercentLimit)
        self.spinLossLimit.valueChanged.connect(self.rmEngine.setLossLimit)

        self.buttonSwitchEngineStatus.clicked.connect(self.switchEngineSatus)
        buttonClearOrderFlowCount.clicked.connect(
            self.rmEngine.clearOrderFlowCount)
        buttonClearTradeCount.clicked.connect(self.rmEngine.clearTradeCount)
        buttonSaveSetting.clicked.connect(self.rmEngine.saveSetting)

        # 设为固定大小
        self.setFixedSize(self.sizeHint())
Esempio n. 22
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(text.RISK_MANAGER)

        # 设置界面
        self.buttonSwitchEngineStatus = QtWidgets.QPushButton(
            text.RISK_MANAGER_STOP)

        self.spinOrderFlowLimit = RmSpinBox(self.rmEngine.orderFlowLimit)
        self.spinOrderFlowClear = RmSpinBox(self.rmEngine.orderFlowClear)
        self.spinOrderSizeLimit = RmSpinBox(self.rmEngine.orderSizeLimit)
        self.spinTradeLimit = RmSpinBox(self.rmEngine.tradeLimit)
        self.spinWorkingOrderLimit = RmSpinBox(self.rmEngine.workingOrderLimit)
        self.spinOrderCancelLimit = RmSpinBox(self.rmEngine.orderCancelLimit)

        self.spinMarginRatioLimit = RmSpinBox(self.rmEngine.marginRatioLimit *
                                              100)  # 百分比显示配置
        self.spinMarginRatioLimit.setMaximum(100)
        self.spinMarginRatioLimit.setSuffix('%')

        buttonClearOrderFlowCount = QtWidgets.QPushButton(
            text.CLEAR_ORDER_FLOW_COUNT)
        buttonClearTradeCount = QtWidgets.QPushButton(
            text.CLEAR_TOTAL_FILL_COUNT)
        buttonSaveSetting = QtWidgets.QPushButton(text.SAVE_SETTING)

        Label = QtWidgets.QLabel
        grid = QtWidgets.QGridLayout()
        grid.addWidget(Label(text.WORKING_STATUS), 0, 0)
        grid.addWidget(self.buttonSwitchEngineStatus, 0, 1)
        grid.addWidget(RmLine(), 1, 0, 1, 2)
        grid.addWidget(Label(text.ORDER_FLOW_LIMIT), 2, 0)
        grid.addWidget(self.spinOrderFlowLimit, 2, 1)
        grid.addWidget(Label(text.ORDER_FLOW_CLEAR), 3, 0)
        grid.addWidget(self.spinOrderFlowClear, 3, 1)
        grid.addWidget(RmLine(), 4, 0, 1, 2)
        grid.addWidget(Label(text.ORDER_SIZE_LIMIT), 5, 0)
        grid.addWidget(self.spinOrderSizeLimit, 5, 1)
        grid.addWidget(RmLine(), 6, 0, 1, 2)
        grid.addWidget(Label(text.TOTAL_TRADE_LIMIT), 7, 0)
        grid.addWidget(self.spinTradeLimit, 7, 1)
        grid.addWidget(RmLine(), 8, 0, 1, 2)
        grid.addWidget(Label(text.WORKING_ORDER_LIMIT), 9, 0)
        grid.addWidget(self.spinWorkingOrderLimit, 9, 1)
        grid.addWidget(RmLine(), 10, 0, 1, 2)
        grid.addWidget(Label(text.CONTRACT_CANCEL_LIMIT), 11, 0)
        grid.addWidget(self.spinOrderCancelLimit, 11, 1)
        grid.addWidget(RmLine(), 12, 0, 1, 2)
        grid.addWidget(Label(text.MARGIN_RATIO_LIMIT), 13, 0)
        grid.addWidget(self.spinMarginRatioLimit, 13, 1)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(buttonClearOrderFlowCount)
        hbox.addWidget(buttonClearTradeCount)
        hbox.addStretch()
        hbox.addWidget(buttonSaveSetting)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addLayout(hbox)
        self.setLayout(vbox)

        # 连接组件信号
        self.spinOrderFlowLimit.valueChanged.connect(
            self.rmEngine.setOrderFlowLimit)
        self.spinOrderFlowClear.valueChanged.connect(
            self.rmEngine.setOrderFlowClear)
        self.spinOrderSizeLimit.valueChanged.connect(
            self.rmEngine.setOrderSizeLimit)
        self.spinTradeLimit.valueChanged.connect(self.rmEngine.setTradeLimit)
        self.spinWorkingOrderLimit.valueChanged.connect(
            self.rmEngine.setWorkingOrderLimit)
        self.spinOrderCancelLimit.valueChanged.connect(
            self.rmEngine.setOrderCancelLimit)
        self.spinMarginRatioLimit.valueChanged.connect(
            self.rmEngine.setMarginRatioLimit)

        self.buttonSwitchEngineStatus.clicked.connect(self.switchEngineSatus)
        buttonClearOrderFlowCount.clicked.connect(
            self.rmEngine.clearOrderFlowCount)
        buttonClearTradeCount.clicked.connect(self.rmEngine.clearTradeCount)
        buttonSaveSetting.clicked.connect(self.rmEngine.saveSetting)

        # 设为固定大小
        self.setFixedSize(self.sizeHint())
Esempio n. 23
0
    def initUi(self):
        """初始化界面"""

        # 1) 服务端级别按钮,
        btnConnectRpcServer = QtWidgets.QPushButton(u'Connect {0}'.format(
            self.name))
        btnActivateGateWayConnection = QtWidgets.QPushButton(u'activate CTP')
        btnDeactivateGateway = QtWidgets.QPushButton(u'Deactivate CTP')
        btnQryStatus = QtWidgets.QPushButton(u'Qry Status')

        btnConnectRpcServer.clicked.connect(self.connect_rpc_server)
        btnActivateGateWayConnection.clicked.connect(
            self.activate_gateway_connection)
        btnDeactivateGateway.clicked.connect(
            self.deactivate_gateway_connection)
        btnQryStatus.clicked.connect(self.qryStatus)

        hbox1 = QtWidgets.QHBoxLayout()
        hbox1.addWidget(btnConnectRpcServer)
        hbox1.addWidget(btnActivateGateWayConnection)
        hbox1.addWidget(btnDeactivateGateway)
        hbox1.addWidget(btnQryStatus)

        self.chkCritical = QtWidgets.QCheckBox('Critical')
        self.chkCritical.setChecked(True)
        self.chkError = QtWidgets.QCheckBox('Error')
        self.chkError.setChecked(True)
        self.chkWarning = QtWidgets.QCheckBox('Warning')
        self.chkWarning.setChecked(True)
        self.chkCtaLog = QtWidgets.QCheckBox('CtaLog')
        self.chkCtaLog.setChecked(True)
        self.chkTicks = QtWidgets.QCheckBox('Ticks')
        self.chkTicks.setChecked(False)
        self.chkSignal = QtWidgets.QCheckBox('Signal')
        self.chkSignal.setChecked(True)

        hbox1.addWidget(self.chkCritical)
        hbox1.addWidget(self.chkError)
        hbox1.addWidget(self.chkWarning)
        hbox1.addWidget(self.chkCtaLog)
        hbox1.addWidget(self.chkTicks)
        hbox1.addWidget(self.chkSignal)

        hbox1.addStretch()

        self.server_info_monitor = ServerInfoWidget()

        # 滚动区域,放置所有的CtaStrategyManager
        self.scrollArea = QtWidgets.QScrollArea()
        self.scrollArea.setWidgetResizable(True)

        # 2)服务端策略监控widget
        self.ctaMonitor = CtaEngineMonitorWidget(self)  # 参数监控
        self.ctaMonitor.setMinimumHeight(200)
        #self.ctaMonitor.setMinimumWidth(800)

        hbox2 = QtWidgets.QVBoxLayout()
        hbox2.addWidget(self.ctaMonitor)
        self.scrollArea.setLayout(hbox2)

        # 服务端日志监控widget
        self.logMonitor = QtWidgets.QTextEdit()
        self.logMonitor.setReadOnly(True)
        self.logMonitor.setMaximumHeight(200)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(hbox1)
        vbox.addWidget(self.server_info_monitor)  # 添加服务监控
        vbox.addWidget(self.logMonitor)
        vbox.addWidget(self.scrollArea)

        self.setLayout(vbox)
Esempio n. 24
0
    def initUi(self):
        """初始化界面"""
	self.setTitle(self.name)

        self.directionList = [u'LONG',
                              u'SHORT',
	                      u'NONE']

        self.offsetList = [u'OPEN',
                           u'CLOSE']

        labelX1 = QtWidgets.QLabel(u'Multiplier 1')
        labelS1 = QtWidgets.QLabel(u'   x')
        labelC1 =  QtWidgets.QLabel(u'Contract 1')
        self.lineX1 = QtWidgets.QLineEdit()
        self.lineS1 = QtWidgets.QLabel(u'   x')
        self.lineC1 = QtWidgets.QLineEdit()

        labelP2 = QtWidgets.QLabel(u'   +')
        labelX2 = QtWidgets.QLabel(u'Multiplier 2')
        labelS2 = QtWidgets.QLabel(u'   x')
        labelC2 =  QtWidgets.QLabel(u'Contract 2')
        self.lineP2 = QtWidgets.QLabel(u'   +')
        self.lineX2 = QtWidgets.QLineEdit()
        self.lineS2 = QtWidgets.QLabel(u'   x')
        self.lineC2 = QtWidgets.QLineEdit()

        labelP3 = QtWidgets.QLabel(u'   +')
        labelX3 = QtWidgets.QLabel(u'Multiplier 3')
        labelS3 = QtWidgets.QLabel(u'   x')
        labelC3 =  QtWidgets.QLabel(u'Contract 3')
        self.lineP3 = QtWidgets.QLabel(u'   +')
        self.lineX3 = QtWidgets.QLineEdit()
        self.lineS3 = QtWidgets.QLabel(u'   x')
        self.lineC3 = QtWidgets.QLineEdit()

        labelP4 = QtWidgets.QLabel(u'   +')
        labelX4 = QtWidgets.QLabel(u'Multiplier 4')
        labelS4 = QtWidgets.QLabel(u'   x')
        labelC4 =  QtWidgets.QLabel(u'Contract 4')
        self.lineP4 = QtWidgets.QLabel(u'   +')
        self.lineX4 = QtWidgets.QLineEdit()
        self.lineS4 = QtWidgets.QLabel(u'   x')
        self.lineC4 = QtWidgets.QLineEdit()

        labelX5 = QtWidgets.QLabel(u'Spread')
        labelC5 =  QtWidgets.QLabel(u'Quantity')
        self.lineX5 = QtWidgets.QLineEdit()
        self.lineC5 = QtWidgets.QLineEdit()

        labelX7 = QtWidgets.QLabel(u'Bought at')
        labelC7 =  QtWidgets.QLabel(u'Sold at')
        self.lineX7 = QtWidgets.QLabel(u'3349')
        self.lineC7 = QtWidgets.QLabel(u'3312')

        labelX6 =  QtWidgets.QLabel(u'Direction')
        self.comboDirection = QtWidgets.QComboBox()
        self.comboDirection.addItems(self.directionList)

        labelC6 =  QtWidgets.QLabel(u'Offset')
        self.comboOffset = QtWidgets.QComboBox()
        self.comboOffset.addItems(self.offsetList)

        # 代码输入框
        gridup = QtWidgets.QGridLayout()
        gridup.addWidget(labelX1, 0, 0)
        gridup.addWidget(labelS1, 0, 1)
        gridup.addWidget(labelC1, 0, 2)
        gridup.addWidget(labelP2, 0, 3)
        gridup.addWidget(labelX2, 0, 4)
        gridup.addWidget(labelS2, 0, 5)
        gridup.addWidget(labelC2, 0, 6)
        gridup.addWidget(labelP3, 0, 7)
        gridup.addWidget(labelX3, 0, 8)
        gridup.addWidget(labelS3, 0, 9)
        gridup.addWidget(labelC3, 0, 10)
        gridup.addWidget(labelP4, 0, 11)
        gridup.addWidget(labelX4, 0, 12)
        gridup.addWidget(labelS4, 0, 13)
        gridup.addWidget(labelC4, 0, 14)
        gridup.addWidget(self.lineX1, 1, 0)
        gridup.addWidget(self.lineS1, 1, 1)
        gridup.addWidget(self.lineC1, 1, 2)
        gridup.addWidget(self.lineP2, 1, 3)
        gridup.addWidget(self.lineX2, 1, 4)
        gridup.addWidget(self.lineS2, 1, 5)
        gridup.addWidget(self.lineC2, 1, 6)
        gridup.addWidget(self.lineP3, 1, 7)
        gridup.addWidget(self.lineX3, 1, 8)
        gridup.addWidget(self.lineS3, 1, 9)
        gridup.addWidget(self.lineC3, 1, 10)
        gridup.addWidget(self.lineP4, 1, 11)
        gridup.addWidget(self.lineX4, 1, 12)
        gridup.addWidget(self.lineS4, 1, 13)
        gridup.addWidget(self.lineC4, 1, 14)
        gridup.setColumnStretch(0, 1)
        gridup.setColumnStretch(1, 1)
        gridup.setColumnStretch(2, 2)
        gridup.setColumnStretch(3, 1)
        gridup.setColumnStretch(4, 1)
        gridup.setColumnStretch(5, 1)
        gridup.setColumnStretch(6, 2)
        gridup.setColumnStretch(7, 1)
        gridup.setColumnStretch(8, 1)
        gridup.setColumnStretch(9, 1)
        gridup.setColumnStretch(10, 2)
        gridup.setColumnStretch(11, 1)
        gridup.setColumnStretch(12, 1)
        gridup.setColumnStretch(13, 1)
        gridup.setColumnStretch(14, 2)
        gridup.setContentsMargins(2,2,600,10)

        griddown = QtWidgets.QGridLayout()
        griddown.addWidget(labelX7, 0, 0)
        griddown.addWidget(labelC7, 0, 1)
        griddown.addWidget(labelX5, 0, 2)
        griddown.addWidget(labelC5, 0, 3)
        griddown.addWidget(labelX6, 0, 4)
        griddown.addWidget(labelC6, 0, 5)
        griddown.addWidget(self.lineX7, 1, 0)
        griddown.addWidget(self.lineC7, 1, 1)
        griddown.addWidget(self.lineX5, 1, 2)
        griddown.addWidget(self.lineC5, 1, 3)
        griddown.addWidget(self.comboDirection, 1, 4)
        griddown.addWidget(self.comboOffset, 1, 5)
        griddown.setContentsMargins(2,2,1300,20)

        
        self.paramMonitor = ArbValueMonitor(self)
        self.varMonitor = ArbValueMonitor(self)
        
        maxHeight = 80
        #self.paramMonitor.setMaximumHeight(maxHeight)
        self.paramMonitor.setMinimumHeight(maxHeight)
        self.paramMonitor.resizeRowsToContents() 
        #self.varMonitor.setMaximumHeight(maxHeight)
        self.varMonitor.setMinimumHeight(maxHeight)
        self.varMonitor.resizeRowsToContents()
        
        buttonUpdate = QtWidgets.QPushButton(u'Update Contracts')
	buttonInit = QtWidgets.QPushButton(u'Initialize')
	buttonSend = QtWidgets.QPushButton(u'Trigger')
	buttonStart = QtWidgets.QPushButton(u'Start')	
        buttonClear = QtWidgets.QPushButton(u'Clear Strategy')
        buttonQrypos = QtWidgets.QPushButton(u'Query Position')
        buttonReport = QtWidgets.QPushButton(u'Report Strategy')
        buttonStop = QtWidgets.QPushButton(u'Stop')
        buttonUpdate.clicked.connect(self.update)
	buttonInit.clicked.connect(self.init)
	buttonSend.clicked.connect(self.send)
	buttonStart.clicked.connect(self.start)	
        buttonClear.clicked.connect(self.clear)
        buttonQrypos.clicked.connect(self.qrypos)
        buttonReport.clicked.connect(self.report)
        buttonStop.clicked.connect(self.stop)
        
        hbox1 = QtWidgets.QHBoxLayout()     
        hbox1.addWidget(buttonUpdate)
	hbox1.addWidget(buttonInit)
	hbox1.addWidget(buttonSend)
	hbox1.addWidget(buttonStart)	
        hbox1.addWidget(buttonClear)
        hbox1.addWidget(buttonQrypos)
        hbox1.addWidget(buttonReport)
        hbox1.addWidget(buttonStop)
        hbox1.addStretch()
        
        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.addWidget(self.paramMonitor)
        
        hbox3 = QtWidgets.QHBoxLayout()
        hbox3.addWidget(self.varMonitor)
        
        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(gridup)
        vbox.addLayout(griddown)
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addLayout(hbox3)

        vbox.setContentsMargins(20,50,20,20)

        self.setLayout(vbox)
Esempio n. 25
0
    def initUi(self):
        """初始化界面"""
        self.setWindowTitle(u'套利交易')

        # 连接运行中的套利测试(策略名称[下拉菜单],连接按钮)
        self.btnSwitchConnectStatus = QtWidgets.QPushButton(u'套利策略未连接')
        self.btnSwitchConnectStatus.clicked.connect(self.btnSwitchClick)

        Label = QtWidgets.QLabel
        grid = QtWidgets.QGridLayout()
        grid.addWidget(Label(u'状态'), 0, 0)
        grid.addWidget(self.btnSwitchConnectStatus, 0, 1)

        self.spreadStraty = QtWidgets.QComboBox()
        self.strategy_name_list = self.ctaEngine.strategyDict.keys()
        self.spreadStraty.addItems(self.strategy_name_list)

        grid.addWidget(Label(u'套利策略'), 1, 0)
        grid.addWidget(self.spreadStraty, 1, 1)


        # 网格信息+操作(新增,删除,更新)

        grid.addWidget(Label(u'方向'), 2, 0)
        self.gridDirection = QtWidgets.QComboBox()
        self.gridDirection.addItems(self.directionList)
        grid.addWidget(self.gridDirection, 2, 1)

        self.spinOpenPrice = QtWidgets.QDoubleSpinBox()
        self.spinOpenPrice.setDecimals(4)
        self.spinOpenPrice.setMinimum(-10000)    # 原来是0,为支持套利,改为-10000
        self.spinOpenPrice.setMaximum(100000)
        self.spinOpenPrice.valueChanged.connect(self.spinOpenPrice_valueChanged)

        grid.addWidget(Label(u'开仓价'), 3, 0)
        grid.addWidget(self.spinOpenPrice, 3, 1)

        self.spinClosePrice = QtWidgets.QDoubleSpinBox()
        self.spinClosePrice.setDecimals(4)
        self.spinClosePrice.setMinimum(-10000)  # 原来是0,为支持套利,改为-10000
        self.spinClosePrice.setMaximum(100000)

        grid.addWidget(Label(u'平仓价'), 4, 0)
        grid.addWidget(self.spinClosePrice, 4, 1)

        self.spinOrderVolume = QtWidgets.QSpinBox()
        self.spinOrderVolume.setMinimum(0)
        self.spinClosePrice.setDecimals(4)
        self.spinOrderVolume.setMaximum(1000)

        grid.addWidget(Label(u'委托数量'), 5, 0)
        grid.addWidget(self.spinOrderVolume, 5, 1)

        self.spinTradedVolume = QtWidgets.QSpinBox()
        self.spinTradedVolume.setMinimum(0)
        self.spinTradedVolume.setMaximum(1000)

        grid.addWidget(Label(u'成交数量'), 6, 0)
        grid.addWidget(self.spinTradedVolume, 6, 1)

        self.openStatus = QtWidgets.QCheckBox(u'')  # 开仓状态
        grid.addWidget(Label(u'开仓状态'), 7, 0)
        grid.addWidget(self.openStatus, 7, 1)

        self.orderStatus = QtWidgets.QCheckBox(u'')  # 委托状态
        grid.addWidget(Label(u'委托状态'), 8, 0)
        grid.addWidget(self.orderStatus, 8, 1)

        self.closeStatus = QtWidgets.QCheckBox(u'')  # 平仓状态
        grid.addWidget(Label(u'平仓状态'), 9, 0)
        grid.addWidget(self.closeStatus, 9, 1)

        self.reuseStatus = QtWidgets.QCheckBox(u'')  # 平仓状态
        grid.addWidget(Label(u'重用网格'), 10, 0)
        grid.addWidget(self.reuseStatus, 10, 1)

        btnAddGrid = QtWidgets.QPushButton(u'增加')
        btnAddGrid.clicked.connect(self.btnAddGridClick)
        btnUpdateGrid = QtWidgets.QPushButton(u'更新')
        btnUpdateGrid.clicked.connect(self.btnUpdateGridClick)
        btnRemoveGrid = QtWidgets.QPushButton(u'删除')
        btnRemoveGrid.clicked.connect(self.btnRemoveGridClick)
        btnRemoveAll = QtWidgets.QPushButton(u'全删除')
        btnRemoveAll.clicked.connect(self.btnRemoveAllClick)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(btnAddGrid)
        hbox.addWidget(btnUpdateGrid)
        hbox.addStretch()
        hbox.addWidget(btnRemoveGrid)
        hbox.addWidget(btnRemoveAll)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addLayout(grid)
        vbox.addLayout(hbox)

        # 状态信息(通过定时器,显示 上网格清单,下网格清单)

        #日志监控
        self.logMsgs = QtWidgets.QTextEdit()
        self.logMsgs.setReadOnly(True)
        self.logMsgs.setMaximumHeight(200)
        vbox.addWidget(self.logMsgs)

        self.setLayout(vbox)