def __init__(self, analysisEngine): # 初始化方法 QtGui.QWidget.__init__(self) # 调用父类初始化方法 self.setWindowTitle('NetCurve') # 设置窗口标题 self.path = os.getcwd() + '/ctaLogFile/ctaPosFile' # self.path = os.getcwd() + '/statement/netSource' self.analysisEngine = analysisEngine # self.resize(300,200) # 设置窗口大小 gridlayout = QtGui.QGridLayout() # 创建布局组件 self.cbAccount = QtGui.QComboBox() self.cbContract = QtGui.QComboBox() self.buttonStart = QtGui.QPushButton() self.lineedit = QtGui.QLineEdit('1000000') self.labelAcct = QtGui.QLabel(u'账户') self.labelCon = QtGui.QLabel(u'标的') self.labelAmount = QtGui.QLabel(u'初始金额') self.labelEvaluate = QtGui.QLabel() tree = lambda: collections.defaultdict(tree) self.dataList = tree() self.fileName = [] self.loadAllPosFile() self.cbAccount.addItems( [k for k in self.groupByPosFile('name').keys()]) self.cbContract.addItems( [k for k in self.groupByPosFile('contract').keys()])
def initUi(self): """初始化界面""" self.setWindowTitle(u'登录') # 设置界面 self.userName = QtGui.QLineEdit() self.password = QtGui.QTextEdit() self.comboStrategy = QtGui.QComboBox() grid = QtGui.QGridLayout() grid.addWidget(LoginLine(), 1, 0, 1, 2) grid.addWidget(QtGui.QLabel(u'用户名'), 2, 0) grid.addWidget(self.userName, 2, 1) grid.addWidget(QtGui.QLabel(u'令牌'), 3, 0) grid.addWidget(self.password, 3, 1) grid.addWidget(LoginLine(), 4, 0, 1, 2) grid.addWidget(QtGui.QLabel(u'策略'), 5, 0) grid.addWidget(self.comboStrategy, 5, 1) grid.addWidget(LoginLine(), 6, 0, 1, 2) self.buttonCancel = QtGui.QPushButton(u'取消') self.buttonConfirm = QtGui.QPushButton(u'确认') hbox = QtGui.QHBoxLayout() hbox.addWidget(self.buttonConfirm) hbox.addWidget(self.buttonCancel) self.buttonConfirm.setDefault(True) vbox = QtGui.QVBoxLayout() vbox.addLayout(grid) vbox.addLayout(hbox) self.setLayout(vbox) # 设为固定大小 self.setFixedSize(self.sizeHint()) self.buttonCancel.clicked.connect(self.close) self.buttonConfirm.clicked.connect(self.login) self.userName.returnPressed.connect(self.password.setFocus) # init username & token username = self.setting['username'] token = self.setting['token'] self.userName.setText(username) self.password.setText(token)
def updateData(self, data): """更新数据""" self.data = data if not self.inited: if 'run_id' in data.keys(): self.setEditTriggers(self.DoubleClicked) self.setColumnCount(len(self.lables)) self.setFixedHeight(85) self.setHorizontalHeaderLabels(self.lables) self.resizeColumnsToContents() self.resizeRowsToContents() col = 0 cell = QtGui.QTableWidgetItem(unicode(data['run_id'])) self.resizeColumnsToContents() self.keyCellDict['run_id'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QTableWidgetItem(unicode(data['strategy_file'])) self.resizeColumnsToContents() self.keyCellDict['strategy_file'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QTableWidgetItem(unicode(data['start_date'])) self.resizeColumnsToContents() self.keyCellDict['start_date'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QTableWidgetItem(unicode(data['end_date'])) self.resizeColumnsToContents() self.keyCellDict['end_date'] = cell self.setItem(0, col, cell) col += 1 """ cell = QtGui.QCalendarWidget() self.resizeColumnsToContents() self.resizeRowsToContents() self.keyCellDict['start_date'] = cell self.setCellWidget(0, col, cell) col += 1 cell = QtGui.QCalendarWidget() self.resizeColumnsToContents() self.resizeRowsToContents() self.keyCellDict['end_date'] = cell self.setCellWidget(0, col, cell) col += 1 """ cell = QtGui.QTableWidgetItem( unicode(data['stock_starting_cash'])) self.resizeColumnsToContents() self.keyCellDict['stock_starting_cash'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QComboBox() cell.addItem("1d") cell.addItem("1m") cell.addItem("tick") self.resizeColumnsToContents() self.keyCellDict['frequency'] = cell self.setCellWidget(0, col, cell) cell.currentIndexChanged.connect(self.sendChangeSignal2) col += 1 cell = QtGui.QComboBox() cell.addItem("current_bar") cell.addItem("next_bar") self.resizeColumnsToContents() self.keyCellDict['matching_type'] = cell self.setCellWidget(0, col, cell) cell.currentIndexChanged.connect(self.sendChangeSignal3) col += 1 cell = QtGui.QTableWidgetItem(unicode(data['benchmark'])) self.resizeColumnsToContents() self.keyCellDict['benchmark'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QTableWidgetItem(unicode(data['slippage'])) self.resizeColumnsToContents() self.keyCellDict['slippage'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QTableWidgetItem( unicode(data['commission_multiplier'])) self.resizeColumnsToContents() self.keyCellDict['commission_multiplier'] = cell self.setItem(0, col, cell) col += 1 cell = QtGui.QTableWidgetItem( unicode(data['margin_multiplier'])) self.resizeColumnsToContents() self.keyCellDict['margin_multiplier'] = cell self.setItem(0, col, cell) col += 1 else: self.setEditTriggers(self.NoEditTriggers) self.setColumnCount(len(data)) self.setFixedHeight(85) self.setHorizontalHeaderLabels(data.keys()) self.resizeColumnsToContents() col = 0 for k, v in data.items(): cell = QtGui.QTableWidgetItem(unicode(v)) self.keyCellDict[k] = cell self.setItem(0, col, cell) col += 1 self.inited = True else: for k, v in data.items(): cell = self.keyCellDict[k] cell.setText(unicode(v)) self.cellChanged.connect(self.sendChangeSignal)
def initUi(self): """初始化界面""" self.setWindowTitle(u'行情数据记录工具') # 菜单 lineSelect = QtGui.QLabel(u'需要收集的合约:') buttonSelect = QtGui.QPushButton(u'选择') lineType = QtGui.QLabel(u'合成Bar类型:') barType = ['1m', '5m', '15m', '30m', '60m'] comboType = QtGui.QComboBox() comboType.addItems(barType) lineStart = QtGui.QLabel(u'开始收集:') buttonStart = QtGui.QPushButton(u'收集') buttonSelect.clicked.connect(self.select) buttonStart.clicked.connect(self.start) # 记录合约配置监控 tickLabel = QtGui.QLabel(u'Tick记录') self.tickTable = QtGui.QTableWidget() self.tickTable.setColumnCount(2) self.tickTable.verticalHeader().setVisible(False) self.tickTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers) self.tickTable.horizontalHeader().setResizeMode( QtGui.QHeaderView.Stretch) self.tickTable.setAlternatingRowColors(True) self.tickTable.setHorizontalHeaderLabels([u'合约代码', u'接口']) barLabel = QtGui.QLabel(u'Bar记录') self.barTable = QtGui.QTableWidget() self.barTable.setColumnCount(2) self.barTable.verticalHeader().setVisible(False) self.barTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers) self.barTable.horizontalHeader().setResizeMode( QtGui.QHeaderView.Stretch) self.barTable.setAlternatingRowColors(True) self.barTable.setHorizontalHeaderLabels([u'合约代码', u'接口']) activeLabel = QtGui.QLabel(u'主力合约') self.activeTable = QtGui.QTableWidget() self.activeTable.setColumnCount(2) self.activeTable.verticalHeader().setVisible(False) self.activeTable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers) self.activeTable.horizontalHeader().setResizeMode( QtGui.QHeaderView.Stretch) self.activeTable.setAlternatingRowColors(True) self.activeTable.setHorizontalHeaderLabels([u'主力代码', u'合约代码']) # 日志监控 self.logMonitor = QtGui.QTextEdit() self.logMonitor.setReadOnly(True) self.logMonitor.setMinimumHeight(600) self.logMonitor2 = QtGui.QTextEdit() self.logMonitor2.setReadOnly(True) self.logMonitor2.setMinimumHeight(600) self.logMonitor3 = QtGui.QTextEdit() self.logMonitor3.setReadOnly(True) self.logMonitor3.setMinimumHeight(600) # 设置布局 hbox = QtGui.QHBoxLayout() hbox.addWidget(lineSelect) hbox.addWidget(buttonSelect) hbox.addWidget(lineType) hbox.addWidget(comboType) hbox.addWidget(lineStart) hbox.addWidget(buttonStart) grid = QtGui.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) grid2 = QtGui.QGridLayout() grid2.addWidget(self.logMonitor, 0, 0) grid2.addWidget(self.logMonitor2, 0, 1) grid2.addWidget(self.logMonitor3, 0, 2) vbox = QtGui.QVBoxLayout() vbox.addLayout(hbox) vbox.addLayout(grid) vbox.addLayout(grid2) self.setLayout(vbox)
def initLabel(self): if self.name == "": strategyname_label = QtGui.QLabel(u"策略名", self) strategyname_label.setGeometry(QtCore.QRect(25, 25, 70, 22)) self.strategyname_label = QtGui.QLineEdit(self) self.strategyname_label.setGeometry(QtCore.QRect(120, 25, 70, 22)) self.closeFirst = QtGui.QCheckBox(u'平仓优先', self) self.closeFirst.setGeometry(QtCore.QRect(210, 25, 90, 22)) label_symbol = QtGui.QLabel(u"合约", self) label_symbol.setGeometry(QtCore.QRect(25, 50, 70, 22)) self.lineEdit_label_symbol = QtGui.QLineEdit(self) self.lineEdit_label_symbol.setGeometry(QtCore.QRect(120, 50, 70, 22)) symbolDirection = QtGui.QLabel(u"方向", self) symbolDirection.setGeometry(QtCore.QRect(210, 50, 70, 22)) self.directionCombo = QtGui.QComboBox(self) self.directionCombo.addItem("") self.directionCombo.addItem("long") self.directionCombo.addItem('short') self.directionCombo.setGeometry(QtCore.QRect(245, 50, 50, 22)) label_longBuyUnit = QtGui.QLabel(u"每笔数量", self) label_longBuyUnit.setGeometry(QtCore.QRect(25, 75, 50, 22)) self.lineEdit_label_longBuyUnit = QtGui.QLineEdit(self) self.lineEdit_label_longBuyUnit.setGeometry( QtCore.QRect(120, 75, 70, 22)) maxStpLos = QtGui.QLabel(u'止损', self) maxStpLos.setGeometry(QtCore.QRect(210, 75, 70, 22)) self.lineEdit_label_maxStpLos = QtGui.QLineEdit(self) self.lineEdit_label_maxStpLos.setGeometry(QtCore.QRect( 245, 75, 60, 22)) label_longPriceCoe = QtGui.QLabel(u"价格系数", self) label_longPriceCoe.setGeometry(QtCore.QRect(25, 100, 50, 22)) self.lineEdit_label_longPriceCoe = QtGui.QLineEdit(self) self.lineEdit_label_longPriceCoe.setGeometry( QtCore.QRect(120, 100, 70, 22)) label_longPosition = QtGui.QLabel(u"当前持仓量", self) label_longPosition.setGeometry(QtCore.QRect(25, 125, 50, 22)) self.lineEdit_label_longPosition = QtGui.QLineEdit(self) self.lineEdit_label_longPosition.setGeometry( QtCore.QRect(120, 125, 70, 22)) label_stpProfit = QtGui.QLabel(u"止赢", self) label_stpProfit.setGeometry(QtCore.QRect(25, 150, 50, 22)) self.lineEdit_label_stpProfit = QtGui.QLineEdit(self) self.lineEdit_label_stpProfit.setGeometry( QtCore.QRect(120, 150, 70, 22)) label_slippage = QtGui.QLabel(u"滑点", self) label_slippage.setGeometry(QtCore.QRect(25, 175, 50, 22)) self.lineEdit_label_slippage = QtGui.QLineEdit(self) self.lineEdit_label_slippage.setGeometry(QtCore.QRect( 120, 175, 70, 22)) label_mail = QtGui.QLabel(u"邮箱", self) label_mail.setGeometry(QtCore.QRect(25, 200, 50, 22)) self.lineEdit_label_mail = QtGui.QLineEdit(self) self.lineEdit_label_mail.setGeometry(QtCore.QRect(120, 200, 200, 22)) label_buyPrice = QtGui.QLabel(u"开仓价差", self) label_buyPrice.setGeometry(QtCore.QRect(25, 225, 50, 22)) self.lineEdit_label_buyPrice = QtGui.QLineEdit(self) self.lineEdit_label_buyPrice.setGeometry( QtCore.QRect(120, 225, 200, 22)) label_stoptime = QtGui.QLabel(u"停止时间", self) label_stoptime.setGeometry(QtCore.QRect(25, 250, 50, 22)) self.lineEdit_label_stoptime = QtGui.QLineEdit(self) self.lineEdit_label_stoptime.setGeometry( QtCore.QRect(120, 250, 200, 22)) self.isFilter = QtGui.QCheckBox(u'当波动大于', self) self.isFilter.setGeometry(QtCore.QRect(25, 275, 150, 22)) self.lineEdit_label_var = QtGui.QLineEdit(self) self.lineEdit_label_var.setGeometry(QtCore.QRect(120, 275, 20, 22)) label_pct = QtGui.QLabel(u'% 时忽略', self) label_pct.setGeometry(QtCore.QRect(141, 275, 80, 22))