2016-05-03 12:35:59 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
'''
|
|
|
|
风控模块相关的GUI控制组件
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
from uiBasicWidget import QtGui, QtCore
|
|
|
|
from eventEngine import *
|
2017-03-19 15:10:34 +00:00
|
|
|
from language import text
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
class RmSpinBox(QtGui.QSpinBox):
|
|
|
|
"""调整参数用的数值框"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def __init__(self, value):
|
|
|
|
"""Constructor"""
|
|
|
|
super(RmSpinBox, self).__init__()
|
2016-05-04 12:54:38 +00:00
|
|
|
|
2016-05-03 12:35:59 +00:00
|
|
|
self.setMinimum(0)
|
|
|
|
self.setMaximum(1000000)
|
2016-05-04 12:54:38 +00:00
|
|
|
|
|
|
|
self.setValue(value)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
class RmLine(QtGui.QFrame):
|
|
|
|
"""水平分割线"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def __init__(self):
|
|
|
|
"""Constructor"""
|
|
|
|
super(RmLine, self).__init__()
|
|
|
|
self.setFrameShape(self.HLine)
|
|
|
|
self.setFrameShadow(self.Sunken)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
class RmEngineManager(QtGui.QWidget):
|
|
|
|
"""风控引擎的管理组件"""
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def __init__(self, rmEngine, eventEngine, parent=None):
|
|
|
|
"""Constructor"""
|
|
|
|
super(RmEngineManager, self).__init__(parent)
|
|
|
|
|
|
|
|
self.rmEngine = rmEngine
|
|
|
|
self.eventEngine = eventEngine
|
|
|
|
|
|
|
|
self.initUi()
|
|
|
|
self.updateEngineStatus()
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def initUi(self):
|
|
|
|
"""初始化界面"""
|
2017-03-19 15:10:34 +00:00
|
|
|
self.setWindowTitle(text.RISK_MANAGER)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
# 设置界面
|
2017-03-19 15:10:34 +00:00
|
|
|
self.buttonSwitchEngineStatus = QtGui.QPushButton(text.RISK_MANAGER_STOP)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
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)
|
2017-03-08 14:27:08 +00:00
|
|
|
self.spinOrderCancelLimit = RmSpinBox(self.rmEngine.orderCancelLimit)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
2017-03-19 15:10:34 +00:00
|
|
|
buttonClearOrderFlowCount = QtGui.QPushButton(text.CLEAR_ORDER_FLOW_COUNT)
|
|
|
|
buttonClearTradeCount = QtGui.QPushButton(text.CLEAR_TOTAL_FILL_COUNT)
|
|
|
|
buttonSaveSetting = QtGui.QPushButton(text.SAVE_SETTING)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
Label = QtGui.QLabel
|
|
|
|
grid = QtGui.QGridLayout()
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.WORKING_STATUS), 0, 0)
|
2016-05-03 12:35:59 +00:00
|
|
|
grid.addWidget(self.buttonSwitchEngineStatus, 0, 1)
|
|
|
|
grid.addWidget(RmLine(), 1, 0, 1, 2)
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.ORDER_FLOW_LIMIT), 2, 0)
|
2016-05-03 12:35:59 +00:00
|
|
|
grid.addWidget(self.spinOrderFlowLimit, 2, 1)
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.ORDER_FLOW_CLEAR), 3, 0)
|
2016-05-03 12:35:59 +00:00
|
|
|
grid.addWidget(self.spinOrderFlowClear, 3, 1)
|
|
|
|
grid.addWidget(RmLine(), 4, 0, 1, 2)
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.ORDER_SIZE_LIMIT), 5, 0)
|
2016-05-03 12:35:59 +00:00
|
|
|
grid.addWidget(self.spinOrderSizeLimit, 5, 1)
|
|
|
|
grid.addWidget(RmLine(), 6, 0, 1, 2)
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.TOTAL_TRADE_LIMIT), 7, 0)
|
2016-05-03 12:35:59 +00:00
|
|
|
grid.addWidget(self.spinTradeLimit, 7, 1)
|
|
|
|
grid.addWidget(RmLine(), 8, 0, 1, 2)
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.WORKING_ORDER_LIMIT), 9, 0)
|
2016-05-03 12:35:59 +00:00
|
|
|
grid.addWidget(self.spinWorkingOrderLimit, 9, 1)
|
2017-03-08 14:27:08 +00:00
|
|
|
grid.addWidget(RmLine(), 10, 0, 1, 2)
|
2017-03-19 15:10:34 +00:00
|
|
|
grid.addWidget(Label(text.CONTRACT_CANCEL_LIMIT), 11, 0)
|
2017-03-08 14:27:08 +00:00
|
|
|
grid.addWidget(self.spinOrderCancelLimit, 11, 1)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
hbox = QtGui.QHBoxLayout()
|
|
|
|
hbox.addWidget(buttonClearOrderFlowCount)
|
|
|
|
hbox.addWidget(buttonClearTradeCount)
|
|
|
|
hbox.addStretch()
|
|
|
|
hbox.addWidget(buttonSaveSetting)
|
|
|
|
|
|
|
|
vbox = QtGui.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)
|
2016-05-04 12:54:38 +00:00
|
|
|
self.spinWorkingOrderLimit.valueChanged.connect(self.rmEngine.setWorkingOrderLimit)
|
2017-03-08 14:27:08 +00:00
|
|
|
self.spinOrderCancelLimit.valueChanged.connect(self.rmEngine.setOrderCancelLimit)
|
2017-03-07 14:22:21 +00:00
|
|
|
|
2016-05-03 12:35:59 +00:00
|
|
|
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())
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def switchEngineSatus(self):
|
|
|
|
"""控制风控引擎开关"""
|
|
|
|
self.rmEngine.switchEngineStatus()
|
|
|
|
self.updateEngineStatus()
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def updateEngineStatus(self):
|
|
|
|
"""更新引擎状态"""
|
|
|
|
if self.rmEngine.active:
|
2017-03-19 15:10:34 +00:00
|
|
|
self.buttonSwitchEngineStatus.setText(text.RISK_MANAGER_RUNNING)
|
2016-05-03 12:35:59 +00:00
|
|
|
else:
|
2017-03-19 15:10:34 +00:00
|
|
|
self.buttonSwitchEngineStatus.setText(text.RISK_MANAGER_STOP)
|
2016-05-03 12:35:59 +00:00
|
|
|
|
|
|
|
|