1. 更换目录分隔符,兼容win和linux
2. 增加BasicMonitor用于保存表格内容到csv文件的功能 3. 增加VT_setting.json用于保存trader的一些配置(如字体)
This commit is contained in:
parent
af66f04356
commit
cb675f7887
Binary file not shown.
4
vn.trader/VT_setting.json
Normal file
4
vn.trader/VT_setting.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"fontFamily": "微软雅黑",
|
||||
"fontSize": 12
|
||||
}
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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():
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"tdAddress": "tcp://203.187.171.250:10910",
|
||||
"password": "123",
|
||||
"password": "请联系飞创申请",
|
||||
"mdAddress": "tcp://203.187.171.250:10915",
|
||||
"accountID": "000200002874"
|
||||
"accountID": "请联系飞创申请"
|
||||
}
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user