From 33dbc320422936895ced99e7ed9cc1d2b05e8c05 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Fri, 5 Aug 2016 00:08:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=B6=E7=9B=98=E5=90=8E?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E6=89=80=E6=9C=89=E5=A7=94=E6=89=98=E6=B8=85?= =?UTF-8?q?=E5=8D=95=E8=87=B3=E8=BF=90=E8=A1=8C=E7=9B=AE=E5=BD=95=E5=AD=90?= =?UTF-8?q?=E7=9B=AE=E5=BD=95Ordres=E4=B8=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/uiBasicWidget.py | 29 +++++++++++++++++++++-------- vn.trader/uiMainWindow.py | 12 +++++++++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index c544da6f..dfb0ceb7 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -9,6 +9,7 @@ from PyQt4 import QtGui, QtCore from eventEngine import * from vtFunction import * from vtGateway import * +import os #---------------------------------------------------------------------- @@ -334,16 +335,21 @@ class BasicMonitor(QtGui.QTableWidget): self.sorting = sorting #---------------------------------------------------------------------- - def saveToCsv(self): + def saveToCsv(self, path=EMPTY_STRING): """保存表格内容到CSV文件""" - # 先隐藏右键菜单 - self.menu.close() - + # 获取想要保存的文件名 - path = QtGui.QFileDialog.getSaveFileName(self, '保存数据', '', 'CSV(*.csv)') + if not path: + # 先隐藏右键菜单 + self.menu.close() + + path = QtGui.QFileDialog.getSaveFileName(self, '保存数据', '', 'CSV(*.csv)') + + log = VtLogData() + log.gatewayName = u'-' try: - if not path.isEmpty(): + if not os.path.exists(path): with open(unicode(path), 'wb') as f: writer = csv.writer(f) @@ -361,9 +367,16 @@ class BasicMonitor(QtGui.QTableWidget): unicode(item.text()).encode('gbk')) else: rowdata.append('') - writer.writerow(rowdata) + writer.writerow(rowdata) + + log.logContent = u'数据保存至:{0}'.format(path) + except IOError: - pass + log.logContent = u'文件IO失败:{0}'.format(path) + + event1 = Event(type_=EVENT_LOG) + event1.dict_['data'] = log + self.eventEngine.put(event1) #---------------------------------------------------------------------- def initMenu(self): diff --git a/vn.trader/uiMainWindow.py b/vn.trader/uiMainWindow.py index 8be776a1..f819d39c 100644 --- a/vn.trader/uiMainWindow.py +++ b/vn.trader/uiMainWindow.py @@ -7,6 +7,8 @@ from ctaAlgo.uiCtaWidget import CtaEngineManager from dataRecorder.uiDrWidget import DrEngineManager from riskManager.uiRmWidget import RmEngineManager +import os + ######################################################################## class MainWindow(QtGui.QMainWindow): """主窗口""" @@ -41,7 +43,7 @@ class MainWindow(QtGui.QMainWindow): widgetLogM, dockLogM = self.createDock(LogMonitor, u'日志', QtCore.Qt.BottomDockWidgetArea) widgetErrorM, dockErrorM = self.createDock(ErrorMonitor, u'错误', QtCore.Qt.BottomDockWidgetArea) widgetTradeM, dockTradeM = self.createDock(TradeMonitor, u'成交', QtCore.Qt.BottomDockWidgetArea) - widgetOrderM, dockOrderM = self.createDock(OrderMonitor, u'委托', QtCore.Qt.RightDockWidgetArea) + self.widgetOrderM, dockOrderM = self.createDock(OrderMonitor, u'委托', QtCore.Qt.RightDockWidgetArea) widgetPositionM, dockPositionM = self.createDock(PositionMonitor, u'持仓', QtCore.Qt.BottomDockWidgetArea) widgetAccountM, dockAccountM = self.createDock(AccountMonitor, u'资金', QtCore.Qt.BottomDockWidgetArea) widgetTradingW, dockTradingW = self.createDock(TradingWidget, u'交易', QtCore.Qt.LeftDockWidgetArea) @@ -201,6 +203,14 @@ class MainWindow(QtGui.QMainWindow): if dt.minute == 40 and dt.second == 0 and self.connectGatewayName != EMPTY_STRING: self.mainEngine.writeLog(u'重新连接{0}'.format(self.connectGatewayName)) self.mainEngine.connect(self.connectGatewayName) + + # 收盘后保存所有委托记录 + if dt.hour == 15 and dt.minute == 1 and self.connectGatewayName != EMPTY_STRING: + orderfile = os.getcwd() +'/orders/{0}.csv'.format(datetime.now().strftime('%y%m%d')) + if os.path.exists(orderfile): + return + else: + self.widgetOrderM.saveToCsv(path=orderfile) # ---------------------------------------------------------------------- def getCpuMemory(self):