diff --git a/vn.trader/ContractData.vt b/vn.trader/ContractData.vt deleted file mode 100644 index 0b6f62ec..00000000 Binary files a/vn.trader/ContractData.vt and /dev/null differ diff --git a/vn.trader/VT_setting.json b/vn.trader/VT_setting.json new file mode 100644 index 00000000..d71864d1 --- /dev/null +++ b/vn.trader/VT_setting.json @@ -0,0 +1,4 @@ +{ + "fontFamily": "微软雅黑", + "fontSize": 12 +} \ No newline at end of file diff --git a/vn.trader/ctaAlgo/ctaEngine.py b/vn.trader/ctaAlgo/ctaEngine.py index 3835ab55..9fa53304 100644 --- a/vn.trader/ctaAlgo/ctaEngine.py +++ b/vn.trader/ctaAlgo/ctaEngine.py @@ -20,7 +20,7 @@ from vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData class CtaEngine(object): """CTA策略引擎""" settingFileName = 'CTA_setting.json' - settingFileName = os.getcwd() + '\\ctaAlgo\\' + settingFileName + settingFileName = os.getcwd() + '/ctaAlgo/' + settingFileName #---------------------------------------------------------------------- def __init__(self, mainEngine, eventEngine): diff --git a/vn.trader/ctpGateway/ctpGateway.py b/vn.trader/ctpGateway/ctpGateway.py index 7cafd021..bb9aad29 100644 --- a/vn.trader/ctpGateway/ctpGateway.py +++ b/vn.trader/ctpGateway/ctpGateway.py @@ -81,7 +81,7 @@ class CtpGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\ctpGateway\\' + fileName + fileName = os.getcwd() + '/ctpGateway/' + fileName try: f = file(fileName) @@ -368,7 +368,7 @@ class CtpMdApi(MdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcMdApi(path) @@ -1202,7 +1202,7 @@ class CtpTdApi(TdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcTraderApi(path) diff --git a/vn.trader/eventType.py b/vn.trader/eventType.py index 6ddaaacc..15f56cc6 100644 --- a/vn.trader/eventType.py +++ b/vn.trader/eventType.py @@ -31,13 +31,6 @@ EVENT_CTA_STRATEGY = 'eCtaStrategy.' # CTA策略状态变化事件 # Wind接口相关 EVENT_WIND_CONNECTREQ = 'eWindConnectReq' # Wind接口请求连接事件 -# 20151020后更新 -# LTS Gateway相关 -EVENT_LTS_SF = 'eLtsSf.' # SF基金查询推送事件 - -# 分级A算法相关 -EVENT_FUNDA_DATA = 'eFaData.' # 分级A基金更新事件 -EVENT_FUNDA_LOG = 'eFaLog' # 分级A算法日志事件 #---------------------------------------------------------------------- def test(): diff --git a/vn.trader/femasGateway/femasGateway.py b/vn.trader/femasGateway/femasGateway.py index 6ca69a6f..5ff9e22c 100644 --- a/vn.trader/femasGateway/femasGateway.py +++ b/vn.trader/femasGateway/femasGateway.py @@ -78,7 +78,7 @@ class FemasGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\femasGateway\\' + fileName + fileName = os.getcwd() + '/femasGateway/' + fileName try: f = file(fileName) @@ -361,7 +361,7 @@ class FemasMdApi(MdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcMdApi(path) @@ -444,7 +444,7 @@ class FemasTdApi(TdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcTraderApi(path) diff --git a/vn.trader/ibGateway/ibGateway.py b/vn.trader/ibGateway/ibGateway.py index 164914bc..036d907b 100644 --- a/vn.trader/ibGateway/ibGateway.py +++ b/vn.trader/ibGateway/ibGateway.py @@ -132,7 +132,7 @@ class IbGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\ibGateway\\' + fileName + fileName = os.getcwd() + '/ibGateway/' + fileName try: f = file(fileName) diff --git a/vn.trader/ksgoldGateway/ksgoldGateway.py b/vn.trader/ksgoldGateway/ksgoldGateway.py index e37d0556..81a210f0 100644 --- a/vn.trader/ksgoldGateway/ksgoldGateway.py +++ b/vn.trader/ksgoldGateway/ksgoldGateway.py @@ -51,7 +51,7 @@ class KsgoldGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\ksgoldGateway\\' + fileName + fileName = os.getcwd() + '/ksgoldGateway/' + fileName try: f = file(fileName) diff --git a/vn.trader/ksotpGateway/ksotpGateway.py b/vn.trader/ksotpGateway/ksotpGateway.py index 50d820ca..dd1b4b48 100644 --- a/vn.trader/ksotpGateway/ksotpGateway.py +++ b/vn.trader/ksotpGateway/ksotpGateway.py @@ -74,7 +74,7 @@ class KsotpGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\ksotpGateway\\' + fileName + fileName = os.getcwd() + '/ksotpGateway/' + fileName try: f = file(fileName) @@ -354,7 +354,7 @@ class KsotpMdApi(MdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createOTPMdApi(path) @@ -1140,7 +1140,7 @@ class KsotpTdApi(TdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createOTPTraderApi(path) diff --git a/vn.trader/ltsGateway/ltsGateway.py b/vn.trader/ltsGateway/ltsGateway.py index 86c2aad0..10bc0939 100644 --- a/vn.trader/ltsGateway/ltsGateway.py +++ b/vn.trader/ltsGateway/ltsGateway.py @@ -75,7 +75,7 @@ class LtsGateway(VtGateway): """连接""" # 载入json 文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\ltsGateway\\' + fileName + fileName = os.getcwd() + '/ltsGateway/' + fileName try: f = file(fileName) @@ -373,7 +373,7 @@ class LtsMdApi(MdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcMdApi(path) @@ -727,7 +727,7 @@ class LtsTdApi(TdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcTraderApi(path) @@ -1065,17 +1065,7 @@ class LtsQryApi(QryApi): #---------------------------------------------------------------------- def onRspQrySFInstrument(self, data, error, n, last): """SF合约查询回报""" - event1 = Event(type_=EVENT_LTS_SF) - event1.dict_['data'] = data - self.gateway.eventEngine.put(event1) - - symbol = data['InstrumentID'] - exchange = exchangeMapReverse[data['ExchangeID']] - vtSymbol = '.'.join([symbol, exchange]) - - event2 = Event(type_=EVENT_LTS_SF + vtSymbol) - event2.dict_['data'] = data - self.gateway.eventEngine.put(event2) + pass #---------------------------------------------------------------------- def onRspQryInstrumentUnitMargin(self, data, error, n, last): @@ -1193,7 +1183,7 @@ class LtsQryApi(QryApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcQueryApi(path) diff --git a/vn.trader/oandaGateway/oandaGateway.py b/vn.trader/oandaGateway/oandaGateway.py index 6ac3ce11..6bc6f50d 100644 --- a/vn.trader/oandaGateway/oandaGateway.py +++ b/vn.trader/oandaGateway/oandaGateway.py @@ -58,7 +58,7 @@ class OandaGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\oandaGateway\\' + fileName + fileName = os.getcwd() + '/oandaGateway/' + fileName try: f = file(fileName) diff --git a/vn.trader/sgitGateway/sgitGateway.py b/vn.trader/sgitGateway/sgitGateway.py index 8a04ce3a..10b8eb71 100644 --- a/vn.trader/sgitGateway/sgitGateway.py +++ b/vn.trader/sgitGateway/sgitGateway.py @@ -94,7 +94,7 @@ class SgitGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\sgitGateway\\' + fileName + fileName = os.getcwd() + '/sgitGateway/' + fileName try: f = file(fileName) @@ -239,7 +239,7 @@ class SgitMdApi(MdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcMdApi(path) @@ -431,7 +431,7 @@ class SgitTdApi(TdApi): # 如果尚未建立服务器连接,则进行连接 if not self.connectionStatus: # 创建C++环境中的API对象,这里传入的参数是需要用来保存.con文件的文件夹路径 - path = os.getcwd() + '\\temp\\' + self.gatewayName + '\\' + path = os.getcwd() + '/temp/' + self.gatewayName + '/' if not os.path.exists(path): os.makedirs(path) self.createFtdcTraderApi(path) diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index 3f7a5c02..0554d692 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -1,5 +1,7 @@ # encoding: UTF-8 +import json +import csv from collections import OrderedDict from PyQt4 import QtGui, QtCore @@ -9,7 +11,20 @@ from vtFunction import * from vtGateway import * -BASIC_FONT = QtGui.QFont(u'微软雅黑', 12) +#---------------------------------------------------------------------- +def loadFont(): + """载入字体设置""" + try: + f = file("VT_setting.json") + setting = json.load(f) + family = setting['fontFamily'] + size = setting['fontSize'] + font = QtGui.QFont(family, size) + except: + font = QtGui.QFont(u'微软雅黑', 12) + return font + +BASIC_FONT = loadFont() ######################################################################## @@ -181,6 +196,9 @@ class BasicMonitor(QtGui.QTableWidget): # 默认不允许根据表头进行排序,需要的组件可以开启 self.sorting = False + # 初始化右键菜单 + self.initMenu() + #---------------------------------------------------------------------- def setHeaderDict(self, headerDict): """设置表头有序字典""" @@ -313,7 +331,53 @@ class BasicMonitor(QtGui.QTableWidget): """设置是否允许根据表头排序""" self.sorting = sorting - + #---------------------------------------------------------------------- + def saveToCsv(self): + """保存表格内容到CSV文件""" + # 先隐藏右键菜单 + self.menu.close() + + # 获取想要保存的文件名 + path = QtGui.QFileDialog.getSaveFileName(self, '保存数据', '', 'CSV(*.csv)') + + try: + if not path.isEmpty(): + with open(unicode(path), 'wb') as f: + writer = csv.writer(f) + + # 保存标签 + headers = [header.encode('gbk') for header in self.headerList] + writer.writerow(headers) + + # 保存每行内容 + for row in range(self.rowCount()): + rowdata = [] + for column in range(self.columnCount()): + item = self.item(row, column) + if item is not None: + rowdata.append( + unicode(item.text()).encode('gbk')) + else: + rowdata.append('') + writer.writerow(rowdata) + except IOError: + pass + + #---------------------------------------------------------------------- + def initMenu(self): + """初始化右键菜单""" + self.menu = QtGui.QMenu(self) + + saveAction = QtGui.QAction(u'保存内容', self) + saveAction.triggered.connect(self.saveToCsv) + + self.menu.addAction(saveAction) + + #---------------------------------------------------------------------- + def contextMenuEvent(self, event): + """右键点击事件""" + self.menu.popup(QtGui.QCursor.pos()) + ######################################################################## class MarketMonitor(BasicMonitor): @@ -979,7 +1043,7 @@ class ContractMonitor(BasicMonitor): self.setMinimumSize(800, 800) self.setFont(BASIC_FONT) self.initTable() - self.initMenu() + self.addMenuAction() #---------------------------------------------------------------------- def showAllContracts(self): @@ -1010,24 +1074,18 @@ class ContractMonitor(BasicMonitor): #---------------------------------------------------------------------- def refresh(self): """刷新""" + self.menu.close() # 关闭菜单 self.clearContents() self.setRowCount(0) self.showAllContracts() - self.menu.close() # 关闭菜单 #---------------------------------------------------------------------- - def initMenu(self): - """初始化右键菜单""" + def addMenuAction(self): + """增加右键菜单内容""" refreshAction = QtGui.QAction(u'刷新', self) refreshAction.triggered.connect(self.refresh) - - self.menu = QtGui.QMenu(self) - self.menu.addAction(refreshAction) - #---------------------------------------------------------------------- - def contextMenuEvent(self, event): - """右键点击事件""" - self.menu.popup(QtGui.QCursor.pos()) + self.menu.addAction(refreshAction) #---------------------------------------------------------------------- def show(self): diff --git a/vn.trader/xspeedGateway/XSPEED_connect.json b/vn.trader/xspeedGateway/XSPEED_connect.json index f27672e8..71f0b84a 100644 --- a/vn.trader/xspeedGateway/XSPEED_connect.json +++ b/vn.trader/xspeedGateway/XSPEED_connect.json @@ -1,6 +1,6 @@ { "tdAddress": "tcp://203.187.171.250:10910", - "password": "123", + "password": "请联系飞创申请", "mdAddress": "tcp://203.187.171.250:10915", - "accountID": "000200002874" + "accountID": "请联系飞创申请" } \ No newline at end of file diff --git a/vn.trader/xspeedGateway/xspeedGateway.py b/vn.trader/xspeedGateway/xspeedGateway.py index e365ae53..670ff236 100644 --- a/vn.trader/xspeedGateway/xspeedGateway.py +++ b/vn.trader/xspeedGateway/xspeedGateway.py @@ -76,7 +76,7 @@ class XspeedGateway(VtGateway): """连接""" # 载入json文件 fileName = self.gatewayName + '_connect.json' - fileName = os.getcwd() + '\\xspeedGateway\\' + fileName + fileName = os.getcwd() + '/xspeedGateway/' + fileName try: f = file(fileName)