新增配置编辑组件

This commit is contained in:
vn.py 2017-07-09 23:54:52 +08:00
parent 08fc156595
commit fe92850996
24 changed files with 196 additions and 77 deletions

View File

@ -0,0 +1,11 @@
{
"fontFamily": "微软雅黑",
"fontSize": 12,
"mongoHost": "localhost",
"mongoPort": 27017,
"mongoLogging": true,
"darkStyle": true,
"language": "chinese"
}

View File

@ -218,7 +218,9 @@ class DrEngine(object):
bar = self.barDict[vtSymbol]
# 如果第一个TICK或者新的一分钟
if not bar.datetime or bar.datetime.minute != tick.datetime.minute:
if (not bar.datetime or
bar.datetime.minute != tick.datetime.minute or
bar.datetime.hour != tick.datetime.hour):
if bar.vtSymbol:
newBar = copy.copy(bar)
self.insertData(MINUTE_DB_NAME, vtSymbol, newBar)

View File

@ -92,15 +92,15 @@ class CshshlpGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -92,15 +92,14 @@ class CtpGateway(VtGateway):
self.qryEnabled = False # 循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -72,15 +72,15 @@ class FemasGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -60,15 +60,15 @@ class HuobiGateway(VtGateway):
self.tradeApi = HuobiTradeApi(self)
self.dataApi = HuobiDataApi(self)
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -138,16 +138,16 @@ class IbGateway(VtGateway):
self.connected = False # 连接状态
self.api = IbWrapper(self) # API接口
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -46,15 +46,15 @@ class KsgoldGateway(VtGateway):
self.orderInited = False # 委托初始化查询
self.tradeInited = False # 成交初始化查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -68,15 +68,15 @@ class KsotpGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -47,15 +47,15 @@ class LhangGateway(VtGateway):
self.api = LhangApi(self)
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -68,16 +68,16 @@ class LtsGateway(VtGateway):
self.qryConnected = False
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json 文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -54,15 +54,15 @@ class OandaGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -118,15 +118,15 @@ class OkcoinGateway(VtGateway):
self.leverage = 0
self.connected = False
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -78,15 +78,14 @@ class QdpGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
"""连接"""
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -89,15 +89,14 @@ class SgitGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -69,15 +69,14 @@ class ShzdGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

View File

@ -78,15 +78,14 @@ class XspeedGateway(VtGateway):
self.qryEnabled = False # 是否要启动循环查询
self.fileName = self.gatewayName + '_connect.json'
self.filePath = getJsonPath(self.fileName, __file__)
#----------------------------------------------------------------------
def connect(self):
"""连接"""
# 载入json文件
fileName = self.gatewayName + '_connect.json'
filePath = getJsonPath(fileName, __file__)
"""连接"""
try:
f = file(filePath)
f = file(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName

BIN
vnpy/trader/ico/editor.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -121,6 +121,9 @@ RESTORE = u'还原窗口'
ABOUT = u'关于'
TEST = u'测试'
CONNECT = u'连接'
EDIT_SETTING = u'编辑配置'
LOAD = u'读取'
SAVE = u'保存'
CPU_MEMORY_INFO = u'CPU使用率{cpu}% 内存使用率:{memory}%'
CONFIRM_EXIT = u'确认退出?'

View File

@ -121,6 +121,9 @@ RESTORE = u'Restore Window'
ABOUT = u'About'
TEST = u'Test'
CONNECT = u'Connect '
EDIT_SETTING = 'Edit Setting'
LOAD = 'Load'
SAVE = 'Save'
CPU_MEMORY_INFO = u'CPU Usage{cpu}% Memory Usage{memory}%'
CONFIRM_EXIT = u'Confirm Exit'

View File

@ -7,11 +7,12 @@ import platform
from collections import OrderedDict
from vnpy.event import *
from vnpy.trader.vtEvent import *
from vnpy.trader.vtFunction import *
from vnpy.trader.vtGateway import *
from vnpy.trader import vtText
from vnpy.trader.uiQt import QtGui, QtWidgets, QtCore, BASIC_FONT
from .vtEvent import *
from .vtFunction import *
from .vtGateway import *
from . import vtText
from .uiQt import QtGui, QtWidgets, QtCore, BASIC_FONT
from .vtFunction import jsonPathDict
COLOR_RED = QtGui.QColor('red')
@ -1229,3 +1230,90 @@ class ContractManager(QtWidgets.QWidget):
self.monitor.refresh()
########################################################################
class SettingEditor(QtWidgets.QWidget):
"""配置编辑器"""
#----------------------------------------------------------------------
def __init__(self, mainEngine, parent=None):
"""Constructor"""
super(SettingEditor, self).__init__(parent)
self.mainEngine = mainEngine
self.currentFileName = ''
self.initUi()
#----------------------------------------------------------------------
def initUi(self):
"""初始化界面"""
self.setWindowTitle(vtText.EDIT_SETTING)
self.comboFileName = QtWidgets.QComboBox()
self.comboFileName.addItems(jsonPathDict.keys())
buttonLoad = QtWidgets.QPushButton(vtText.LOAD)
buttonSave = QtWidgets.QPushButton(vtText.SAVE)
buttonLoad.clicked.connect(self.loadSetting)
buttonSave.clicked.connect(self.saveSetting)
self.editSetting = QtWidgets.QTextEdit()
self.labelPath = QtWidgets.QLabel()
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(self.comboFileName)
hbox.addWidget(buttonLoad)
hbox.addWidget(buttonSave)
hbox.addStretch()
vbox = QtWidgets.QVBoxLayout()
vbox.addLayout(hbox)
vbox.addWidget(self.editSetting)
vbox.addWidget(self.labelPath)
self.setLayout(vbox)
#----------------------------------------------------------------------
def loadSetting(self):
"""加载配置"""
self.currentFileName = str(self.comboFileName.currentText())
filePath = jsonPathDict[self.currentFileName]
self.labelPath.setText(filePath)
with open(filePath) as f:
self.editSetting.clear()
for line in f:
line = line.replace('\n', '') # 移除换行符号
line = line.decode('UTF-8')
self.editSetting.append(line)
#----------------------------------------------------------------------
def saveSetting(self):
"""保存配置"""
if not self.currentFileName:
return
filePath = jsonPathDict[self.currentFileName]
with open(filePath, 'w') as f:
content = self.editSetting.toPlainText()
content = content.encode('UTF-8')
f.write(content)
#----------------------------------------------------------------------
def show(self):
"""显示"""
self.comboFileName.clear()
self.comboFileName.addItems(jsonPathDict.keys())
super(SettingEditor, self).showMaximized()

View File

@ -117,6 +117,7 @@ class MainWindow(QtWidgets.QMainWindow):
# 帮助
helpMenu = menubar.addMenu(vtText.HELP)
helpMenu.addAction(self.createAction(vtText.CONTRACT_SEARCH, self.openContract, loadIconPath('contract.ico')))
helpMenu.addAction(self.createAction(vtText.EDIT_SETTING, self.openSettingEditor, loadIconPath('editor.ico')))
helpMenu.addSeparator()
helpMenu.addAction(self.createAction(vtText.RESTORE, self.restoreWindow, loadIconPath('restore.ico')))
helpMenu.addAction(self.createAction(vtText.ABOUT, self.openAbout, loadIconPath('about.ico')))
@ -219,6 +220,15 @@ class MainWindow(QtWidgets.QMainWindow):
except KeyError:
self.widgetDict['contractM'] = ContractManager(self.mainEngine)
self.widgetDict['contractM'].show()
#----------------------------------------------------------------------
def openSettingEditor(self):
"""打开配置编辑"""
try:
self.widgetDict['settingEditor'].show()
except KeyError:
self.widgetDict['settingEditor'] = SettingEditor(self.mainEngine)
self.widgetDict['settingEditor'].show()
#----------------------------------------------------------------------
def closeEvent(self, event):

View File

@ -63,7 +63,11 @@ def getTempPath(name):
path = os.path.join(tempPath, name)
return path
# JSON配置文件路径
jsonPathDict = {}
#----------------------------------------------------------------------
def getJsonPath(name, moduleFile):
"""
@ -74,10 +78,14 @@ def getJsonPath(name, moduleFile):
currentFolder = os.getcwd()
currentJsonPath = os.path.join(currentFolder, name)
if os.path.isfile(currentJsonPath):
jsonPathDict[name] = currentJsonPath
return currentJsonPath
moduleFolder = os.path.abspath(os.path.dirname(moduleFile))
moduleJsonPath = os.path.join(moduleFolder, '.', name)
jsonPathDict[name] = moduleJsonPath
return moduleJsonPath

View File

@ -7,14 +7,13 @@
import os
import traceback
import json
from vtFunction import getJsonPath
globalSetting = {} # 全局配置字典
settingFileName = "VT_setting.json"
path = os.path.abspath(os.path.dirname(__file__))
settingFileName = os.path.join(path, settingFileName)
settingFilePath = getJsonPath(settingFileName, __file__)
try:
f = file(settingFileName)