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):