From b10e62152c07758605828cd8fcd0df70eeb8563f Mon Sep 17 00:00:00 2001 From: msincenselee Date: Wed, 7 Feb 2018 17:47:57 +0800 Subject: [PATCH] =>Py3.5 --- README.md | 8 ++++++++ requirements.txt | 4 +++- vnpy/trader/uiBasicWidget.py | 8 ++++---- vnpy/trader/uiMainWindow.py | 8 ++++---- vnpy/trader/uiQt.py | 2 +- vnpy/trader/util_gpid.py | 4 ++-- vnpy/trader/util_monitor.py | 4 ++-- vnpy/trader/vtClient.py | 5 +---- vnpy/trader/vtConstant.py | 6 ++++++ vnpy/trader/vtEngine.py | 17 +++++++++++++++-- vnpy/trader/vtGateway.py | 6 ++++-- vnpy/trader/vtGlobal.py | 7 +++---- 12 files changed, 53 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9318f354..9e798d7b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +### “当你想放弃时,想想你为什么开始。” + #Fork版本主要改进如下: 1、增加CtaLineBar,CtaPosition,CtaPolicy,UtlSinaClient等基础组件 2、增加自动断线重连功能,在开盘前启动,收盘后重连CTP @@ -76,6 +78,12 @@ QQ/Wechat:28888502 #5、碰到的问题:version `GLIBCXX_3.4.21' not found conda install libgcc +#6、碰到的问题:在3.5 env下安装RqPlus时,报错:talib/common.c:242:28: fatal error: ta-lib/ta_defs.h: No such file or directory + locate ta_defs.h + 找到地址:/home/user/anaconda3/pkgs/ta-lib-0.4.9-np111py27_0/include/ta-lib + # 复制一份到/usr/include目录下 + sudo cp /home/user/anaconda3/pkgs/ta-lib-0.4.9-np111py27_0/include/ta-lib /usr/include -R + -------------------------------------------------------------------------------------------- # vn.py - 基于python的开源交易平台开发框架 diff --git a/requirements.txt b/requirements.txt index 39515317..d52798ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,6 @@ zmq qtpy pyqt qdarkstyle -SortedContainers \ No newline at end of file +SortedContainers +statsmodels +openpyxl \ No newline at end of file diff --git a/vnpy/trader/uiBasicWidget.py b/vnpy/trader/uiBasicWidget.py index 2c861f5a..8e0d38f6 100644 --- a/vnpy/trader/uiBasicWidget.py +++ b/vnpy/trader/uiBasicWidget.py @@ -262,7 +262,7 @@ class BasicMonitor(QtWidgets.QTableWidget): self.setColumnCount(col) # 设置列表头 - labels = [d['chinese'] for d in self.headerDict.values()] + labels = [d['chinese'] for d in list(self.headerDict.values())] self.setHorizontalHeaderLabels(labels) # 关闭左边的垂直表头 @@ -383,7 +383,7 @@ class BasicMonitor(QtWidgets.QTableWidget): try: if not os.path.exists(path): - with open(path, 'wb') as f: + with open(path, 'w',encoding='utf8') as f: writer = csv.writer(f) # 保存标签 @@ -1359,7 +1359,7 @@ class SettingEditor(QtWidgets.QWidget): filePath = jsonPathDict[self.currentFileName] self.labelPath.setText(filePath) - with open(filePath,'rb',encoding='utf8') as f: + with open(filePath,'r',encoding='utf8') as f: self.editSetting.clear() for line in f: @@ -1375,7 +1375,7 @@ class SettingEditor(QtWidgets.QWidget): filePath = jsonPathDict[self.currentFileName] - with open(filePath, 'wb', encoding='utf8') as f: + with open(filePath, 'w', encoding='utf8') as f: content = self.editSetting.toPlainText() #content = content.encode('UTF-8') f.write(content) diff --git a/vnpy/trader/uiMainWindow.py b/vnpy/trader/uiMainWindow.py index 121aa193..b41c203a 100644 --- a/vnpy/trader/uiMainWindow.py +++ b/vnpy/trader/uiMainWindow.py @@ -208,7 +208,7 @@ class MainWindow(QtWidgets.QMainWindow): self.statusLabel.setText(info) if self.connectGatewayDict: - s = u','.join(str(e) for e in self.connectGatewayDict.values()) + s = u','.join(str(e) for e in list(self.connectGatewayDict.values())) if not self.connected: s = s + u' [已断开]' @@ -218,7 +218,7 @@ class MainWindow(QtWidgets.QMainWindow): # 定时断开 if self.connected and self.trade_off() and self.autoDisConnect: self.disconnect() - self.mainEngine.writeLog(u'断开连接{0}'.format(self.connectGatewayDict.values())) + self.mainEngine.writeLog(u'断开连接{0}'.format(list(self.connectGatewayDict.values()))) self.mainEngine.writeLog(u'清空数据引擎') self.mainEngine.clearData() self.mainEngine.writeLog(u'清空委托列表') @@ -238,7 +238,7 @@ class MainWindow(QtWidgets.QMainWindow): self.widgetOrderM.clearData() self.mainEngine.writeLog(u'清空交易列表') self.widgetTradeM.clearData() - s = u''.join(str(e) for e in self.connectGatewayDict.values()) + s = u''.join(str(e) for e in list(self.connectGatewayDict.values())) self.mainEngine.writeLog(u'重新连接{0}'.format(s)) for key in self.connectGatewayDict.keys(): @@ -423,7 +423,7 @@ class MainWindow(QtWidgets.QMainWindow): QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: - for widget in self.widgetDict.values(): + for widget in list(self.widgetDict.values()): widget.close() self.saveWindowSettings('custom') diff --git a/vnpy/trader/uiQt.py b/vnpy/trader/uiQt.py index 27efd999..c54a20d1 100644 --- a/vnpy/trader/uiQt.py +++ b/vnpy/trader/uiQt.py @@ -27,7 +27,7 @@ def createQApp(): import qdarkstyle qApp.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) except : - print( "Unexpected error when import darkStyle:", sys.exc_info()[0]) + print("Unexpected error when import darkStyle:", sys.exc_info()[0]) # 设置Windows底部任务栏图标 if 'Windows' in platform.uname(): diff --git a/vnpy/trader/util_gpid.py b/vnpy/trader/util_gpid.py index 299cd2f2..4a236b16 100644 --- a/vnpy/trader/util_gpid.py +++ b/vnpy/trader/util_gpid.py @@ -4,8 +4,8 @@ import subprocess import os import sys import platform -base_path = os.path.dirname(os.path.realpath(sys.argv[0])) -gpid_file = os.path.abspath(os.path.join(base_path, 'logs','gpid.txt')) + +gpid_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'logs','gpid.txt')) def _check_gpid(gpid): plat = str(platform.system()) diff --git a/vnpy/trader/util_monitor.py b/vnpy/trader/util_monitor.py index 7c061007..a81fc776 100644 --- a/vnpy/trader/util_monitor.py +++ b/vnpy/trader/util_monitor.py @@ -2,8 +2,8 @@ from collections import OrderedDict -from vtGateway import * -from setup_logger import setup_logger +from .vtGateway import * +from .setup_logger import setup_logger ######################################################################## class BasicMonitor(object): diff --git a/vnpy/trader/vtClient.py b/vnpy/trader/vtClient.py index 6a6d1da4..d827ce11 100644 --- a/vnpy/trader/vtClient.py +++ b/vnpy/trader/vtClient.py @@ -183,10 +183,7 @@ class ClientEngine(object): #---------------------------------------------------------------------- def main(): """客户端主程序入口""" - # 重载sys模块,设置默认字符串编码方式为utf8 - reload(sys) - sys.setdefaultencoding('utf8') - + # 设置Windows底部任务栏图标 if 'Windows' in platform.uname() : ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader') diff --git a/vnpy/trader/vtConstant.py b/vnpy/trader/vtConstant.py index b33cfdd5..60907e35 100644 --- a/vnpy/trader/vtConstant.py +++ b/vnpy/trader/vtConstant.py @@ -13,6 +13,12 @@ COLOR_RED = u'Red' # 上升K线 COLOR_BLUE = u'Blue' # 下降K线 COLOR_EQUAL = u'Equal' # 平K线 +# 策略若干判断状态 +NOTRUN = u'NotRun' # 没有运行; +RUNING = u'Runing' # 正常运行; +FORCECLOSING = u'ForceClosing' #正在关闭 +FORCECLOSED = u'ForceClosed' #:已经关闭 + from vnpy.trader.language import constant # 将常量定义添加到vtConstant.py的局部字典中 diff --git a/vnpy/trader/vtEngine.py b/vnpy/trader/vtEngine.py index 798fcd5f..d7a0bb36 100644 --- a/vnpy/trader/vtEngine.py +++ b/vnpy/trader/vtEngine.py @@ -5,6 +5,7 @@ print( 'load vtEngine.py') import shelve from collections import OrderedDict import os +import copy from pymongo import MongoClient from pymongo.errors import ConnectionFailure @@ -21,9 +22,9 @@ from vnpy.trader.setup_logger import get_logger,setup_logger import psutil try: - from util_mail import * + from .util_mail import * except: - pass + print('import util_mail fail') ######################################################################## class MainEngine(object): @@ -228,6 +229,18 @@ class MainEngine(object): else: return 0, 0, 0, 0 + def qryAccountNo(self,gatewayName): + """ + 根据gateway名称,返回账号 + :param gatewayName: + :return: + """ + if gatewayName in self.gatewayDict: + gateway = self.gatewayDict[gatewayName] + if gateway.accountID: + return copy.copy(gateway.accountID) + + return gatewayName # ---------------------------------------------------------------------- def qryPosition(self, gatewayName): """查询特定接口的持仓""" diff --git a/vnpy/trader/vtGateway.py b/vnpy/trader/vtGateway.py index 1ce1b769..1fc633b1 100644 --- a/vnpy/trader/vtGateway.py +++ b/vnpy/trader/vtGateway.py @@ -20,7 +20,7 @@ class VtGateway(object): self.eventEngine = eventEngine self.gatewayName = gatewayName self.logger = None - + self.accountID = 'AccountID' self.createLogger() # ---------------------------------------------------------------------- @@ -87,7 +87,9 @@ class VtGateway(object): event2 = Event(type_=EVENT_ACCOUNT+account.vtAccountID) event2.dict_['data'] = account self.eventEngine.put(event2) - + + # 更新账号ID + self.accountID = account.vtAccountID # ---------------------------------------------------------------------- def onError(self, error): """错误信息推送""" diff --git a/vnpy/trader/vtGlobal.py b/vnpy/trader/vtGlobal.py index ddf225b3..a5bdda2f 100644 --- a/vnpy/trader/vtGlobal.py +++ b/vnpy/trader/vtGlobal.py @@ -7,15 +7,14 @@ print('load vtGlobal.py') 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: - with open(settingFileName,'r',encoding="utf8") as f: + with open(settingFilePath,'r',encoding="utf8") as f: globalSetting = json.load(f) except: traceback.print_exc() \ No newline at end of file