增加收盘后保持所有委托清单至运行目录子目录Ordres下。

This commit is contained in:
msincenselee 2016-08-05 00:08:29 +08:00
parent 414e319529
commit 33dbc32042
2 changed files with 32 additions and 9 deletions

View File

@ -9,6 +9,7 @@ from PyQt4 import QtGui, QtCore
from eventEngine import * from eventEngine import *
from vtFunction import * from vtFunction import *
from vtGateway import * from vtGateway import *
import os
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -334,16 +335,21 @@ class BasicMonitor(QtGui.QTableWidget):
self.sorting = sorting self.sorting = sorting
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def saveToCsv(self): def saveToCsv(self, path=EMPTY_STRING):
"""保存表格内容到CSV文件""" """保存表格内容到CSV文件"""
# 获取想要保存的文件名
if not path:
# 先隐藏右键菜单 # 先隐藏右键菜单
self.menu.close() self.menu.close()
# 获取想要保存的文件名
path = QtGui.QFileDialog.getSaveFileName(self, '保存数据', '', 'CSV(*.csv)') path = QtGui.QFileDialog.getSaveFileName(self, '保存数据', '', 'CSV(*.csv)')
log = VtLogData()
log.gatewayName = u'-'
try: try:
if not path.isEmpty(): if not os.path.exists(path):
with open(unicode(path), 'wb') as f: with open(unicode(path), 'wb') as f:
writer = csv.writer(f) writer = csv.writer(f)
@ -362,8 +368,15 @@ class BasicMonitor(QtGui.QTableWidget):
else: else:
rowdata.append('') rowdata.append('')
writer.writerow(rowdata) writer.writerow(rowdata)
log.logContent = u'数据保存至:{0}'.format(path)
except IOError: 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): def initMenu(self):

View File

@ -7,6 +7,8 @@ from ctaAlgo.uiCtaWidget import CtaEngineManager
from dataRecorder.uiDrWidget import DrEngineManager from dataRecorder.uiDrWidget import DrEngineManager
from riskManager.uiRmWidget import RmEngineManager from riskManager.uiRmWidget import RmEngineManager
import os
######################################################################## ########################################################################
class MainWindow(QtGui.QMainWindow): class MainWindow(QtGui.QMainWindow):
"""主窗口""" """主窗口"""
@ -41,7 +43,7 @@ class MainWindow(QtGui.QMainWindow):
widgetLogM, dockLogM = self.createDock(LogMonitor, u'日志', QtCore.Qt.BottomDockWidgetArea) widgetLogM, dockLogM = self.createDock(LogMonitor, u'日志', QtCore.Qt.BottomDockWidgetArea)
widgetErrorM, dockErrorM = self.createDock(ErrorMonitor, u'错误', QtCore.Qt.BottomDockWidgetArea) widgetErrorM, dockErrorM = self.createDock(ErrorMonitor, u'错误', QtCore.Qt.BottomDockWidgetArea)
widgetTradeM, dockTradeM = self.createDock(TradeMonitor, 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) widgetPositionM, dockPositionM = self.createDock(PositionMonitor, u'持仓', QtCore.Qt.BottomDockWidgetArea)
widgetAccountM, dockAccountM = self.createDock(AccountMonitor, u'资金', QtCore.Qt.BottomDockWidgetArea) widgetAccountM, dockAccountM = self.createDock(AccountMonitor, u'资金', QtCore.Qt.BottomDockWidgetArea)
widgetTradingW, dockTradingW = self.createDock(TradingWidget, u'交易', QtCore.Qt.LeftDockWidgetArea) widgetTradingW, dockTradingW = self.createDock(TradingWidget, u'交易', QtCore.Qt.LeftDockWidgetArea)
@ -202,6 +204,14 @@ class MainWindow(QtGui.QMainWindow):
self.mainEngine.writeLog(u'重新连接{0}'.format(self.connectGatewayName)) self.mainEngine.writeLog(u'重新连接{0}'.format(self.connectGatewayName))
self.mainEngine.connect(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): def getCpuMemory(self):
"""获取CPU和内存状态信息""" """获取CPU和内存状态信息"""