重构目录,将应用模块放到单独的app文件夹下
This commit is contained in:
parent
06ab98e95b
commit
1fb9eaf3ab
1
vnpy/trader/app/__init__.py
Normal file
1
vnpy/trader/app/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# encoding: UTF-8
|
Can't render this file because it is too large.
|
9
vnpy/trader/app/ctaStrategy/__init__.py
Normal file
9
vnpy/trader/app/ctaStrategy/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from ctaEngine import CtaEngine
|
||||
from uiCtaWidget import CtaEngineManager
|
||||
|
||||
appName = 'CtaStrategy'
|
||||
appDisplayName = u'CTA策略'
|
||||
appEngine = CtaEngine
|
||||
appWidget = CtaEngineManager
|
@ -17,7 +17,7 @@ from vnpy.trader.vtObject import VtTickData, VtBarData
|
||||
from vnpy.trader.vtConstant import *
|
||||
from vnpy.trader.vtGateway import VtOrderData, VtTradeData
|
||||
|
||||
from vnpy.trader.ctaStrategy.ctaBase import *
|
||||
from vnpy.trader.app.ctaStrategy.ctaBase import *
|
||||
|
||||
|
||||
########################################################################
|
@ -31,8 +31,8 @@ from vnpy.trader.vtObject import VtTickData, VtBarData
|
||||
from vnpy.trader.vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData
|
||||
from vnpy.trader.vtFunction import todayDate
|
||||
|
||||
from vnpy.trader.ctaStrategy.ctaBase import *
|
||||
from vnpy.trader.ctaStrategy.strategy import STRATEGY_CLASS
|
||||
from vnpy.trader.app.ctaStrategy.ctaBase import *
|
||||
from vnpy.trader.app.ctaStrategy.strategy import STRATEGY_CLASS
|
||||
|
||||
|
||||
########################################################################
|
@ -17,7 +17,7 @@ from vnpy.trader.vtGlobal import globalSetting
|
||||
from vnpy.trader.vtConstant import *
|
||||
from vnpy.trader.vtObject import VtBarData
|
||||
|
||||
from vnpy.trader.ctaStrategy.datayesClient import DatayesClient
|
||||
from vnpy.trader.app.ctaStrategy.datayesClient import DatayesClient
|
||||
|
||||
|
||||
# 以下为vn.trader和通联数据规定的交易所代码映射
|
@ -6,7 +6,7 @@
|
||||
|
||||
from vnpy.trader.vtConstant import *
|
||||
|
||||
from vnpy.trader.ctaStrategy.ctaBase import *
|
||||
from vnpy.trader.app.ctaStrategy.ctaBase import *
|
||||
|
||||
########################################################################
|
||||
class CtaTemplate(object):
|
13
vnpy/trader/app/ctaStrategy/language/__init__.py
Normal file
13
vnpy/trader/app/ctaStrategy/language/__init__.py
Normal file
@ -0,0 +1,13 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from chinese import text
|
||||
|
||||
# 是否要使用英文
|
||||
from vnpy.trader.vtGlobal import globalSetting
|
||||
if globalSetting['language'] == 'english':
|
||||
from english import text
|
@ -20,7 +20,7 @@ for root, subdirs, files in os.walk(path):
|
||||
# 只有文件名中包含strategy且非.pyc的文件,才是策略文件
|
||||
if 'strategy' in name and '.pyc' not in name:
|
||||
# 模块名称需要上前缀
|
||||
moduleName = 'vnpy.trader.ctaStrategy.strategy.' + name.replace('.py', '')
|
||||
moduleName = 'vnpy.trader.app.ctaStrategy.strategy.' + name.replace('.py', '')
|
||||
|
||||
# 使用importlib动态载入模块
|
||||
try:
|
@ -15,7 +15,7 @@ import numpy as np
|
||||
|
||||
from vnpy.trader.vtObject import VtBarData
|
||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||
from vnpy.trader.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
|
||||
|
||||
########################################################################
|
||||
@ -240,7 +240,7 @@ class AtrRsiStrategy(CtaTemplate):
|
||||
if __name__ == '__main__':
|
||||
# 提供直接双击回测的功能
|
||||
# 导入PyQt4的包是为了保证matplotlib使用PyQt4而不是PySide,防止初始化出错
|
||||
from vnpy.trader.ctaStrategy.ctaBacktesting import *
|
||||
from vnpy.trader.app.ctaStrategy.ctaBacktesting import *
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
# 创建回测引擎
|
@ -8,7 +8,7 @@ from datetime import time
|
||||
|
||||
from vnpy.trader.vtObject import VtBarData
|
||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||
from vnpy.trader.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
|
||||
|
||||
########################################################################
|
@ -15,7 +15,7 @@ from __future__ import division
|
||||
|
||||
from vnpy.trader.vtObject import VtBarData
|
||||
from vnpy.trader.vtConstant import EMPTY_STRING, EMPTY_FLOAT
|
||||
from vnpy.trader.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
|
||||
|
||||
########################################################################
|
@ -17,7 +17,7 @@ import numpy as np
|
||||
|
||||
from vnpy.trader.vtObject import VtBarData
|
||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||
from vnpy.trader.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import CtaTemplate
|
||||
|
||||
|
||||
########################################################################
|
Before Width: | Height: | Size: 382 KiB After Width: | Height: | Size: 382 KiB |
@ -9,7 +9,7 @@ from vnpy.event import Event
|
||||
from vnpy.trader.vtEvent import *
|
||||
from vnpy.trader.uiBasicWidget import QtGui, QtCore, QtWidgets, BasicCell
|
||||
|
||||
from vnpy.trader.ctaStrategy.language import text
|
||||
from vnpy.trader.app.ctaStrategy.language import text
|
||||
|
||||
|
||||
########################################################################
|
9
vnpy/trader/app/dataRecorder/__init__.py
Normal file
9
vnpy/trader/app/dataRecorder/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from drEngine import DrEngine
|
||||
from uiDrWidget import DrEngineManager
|
||||
|
||||
appName = 'DataRecorder'
|
||||
appDisplayName = u'行情记录'
|
||||
appEngine = DrEngine
|
||||
appWidget = DrEngineManager
|
@ -19,8 +19,8 @@ from vnpy.trader.vtEvent import *
|
||||
from vnpy.trader.vtFunction import todayDate
|
||||
from vnpy.trader.vtObject import VtSubscribeReq, VtLogData, VtBarData, VtTickData
|
||||
|
||||
from vnpy.trader.dataRecorder.drBase import *
|
||||
from vnpy.trader.dataRecorder.language import text
|
||||
from vnpy.trader.app.dataRecorder.drBase import *
|
||||
from vnpy.trader.app.dataRecorder.language import text
|
||||
|
||||
|
||||
########################################################################
|
13
vnpy/trader/app/dataRecorder/language/__init__.py
Normal file
13
vnpy/trader/app/dataRecorder/language/__init__.py
Normal file
@ -0,0 +1,13 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from chinese import text
|
||||
|
||||
# 是否要使用英文
|
||||
from vnpy.trader.vtGlobal import globalSetting
|
||||
if globalSetting['language'] == 'english':
|
||||
from english import text
|
@ -11,7 +11,7 @@ from qtpy import QtWidgets, QtGui, QtCore
|
||||
from vnpy.event import Event
|
||||
from vnpy.trader.vtEvent import *
|
||||
|
||||
from vnpy.trader.dataRecorder.language import text
|
||||
from vnpy.trader.app.dataRecorder.language import text
|
||||
|
||||
|
||||
########################################################################
|
9
vnpy/trader/app/riskManager/__init__.py
Normal file
9
vnpy/trader/app/riskManager/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from rmEngine import RmEngine
|
||||
from uiRmWidget import RmEngineManager
|
||||
|
||||
appName = 'RiskManager'
|
||||
appDisplayName = u'风险管理'
|
||||
appEngine = RmEngine
|
||||
appWidget = RmEngineManager
|
13
vnpy/trader/app/riskManager/language/__init__.py
Normal file
13
vnpy/trader/app/riskManager/language/__init__.py
Normal file
@ -0,0 +1,13 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from chinese import text
|
||||
|
||||
# 是否要使用英文
|
||||
from vnpy.trader.vtGlobal import globalSetting
|
||||
if globalSetting['language'] == 'english':
|
||||
from english import text
|
@ -31,6 +31,9 @@ class RmEngine(object):
|
||||
"""Constructor"""
|
||||
self.mainEngine = mainEngine
|
||||
self.eventEngine = eventEngine
|
||||
|
||||
# 绑定自身到主引擎的风控引擎引用上
|
||||
mainEngine.rmEngine = self
|
||||
|
||||
# 是否启动风控
|
||||
self.active = False
|
@ -8,7 +8,7 @@
|
||||
from vnpy.event import Event
|
||||
|
||||
from vnpy.trader.uiBasicWidget import QtGui, QtWidgets, QtCore
|
||||
from vnpy.trader.riskManager.language import text
|
||||
from vnpy.trader.app.riskManager.language import text
|
||||
|
||||
|
||||
########################################################################
|
@ -1,23 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
SETTING_FILENAME = 'VT_setting.json'
|
||||
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
|
||||
# 打开配置文件,读取语言配置
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
@ -1,23 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
SETTING_FILENAME = 'VT_setting.json'
|
||||
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
|
||||
# 打开配置文件,读取语言配置
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
@ -1,33 +1 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
'''
|
||||
动态载入所有的Gateway
|
||||
'''
|
||||
|
||||
import os
|
||||
import importlib
|
||||
import traceback
|
||||
|
||||
# 用来保存Gateway类的字典
|
||||
GATEWAY_DICT = {}
|
||||
|
||||
# 获取目录路径
|
||||
path = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
# 遍历strategy目录下的文件
|
||||
for root, subdirs, files in os.walk(path):
|
||||
if path != root:
|
||||
continue
|
||||
|
||||
for foldername in subdirs:
|
||||
# 接口目录名中必须含有Gateway
|
||||
if 'Gateway' in foldername:
|
||||
# 模块名称需要上前缀
|
||||
moduleName = 'vnpy.trader.gateway.' + foldername
|
||||
|
||||
try:
|
||||
# 使用importlib动态载入模块,并保存到字典中
|
||||
module = importlib.import_module(moduleName)
|
||||
GATEWAY_DICT[module.gatewayName] = module
|
||||
except:
|
||||
traceback.print_exc()
|
@ -1,8 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnpy.trader import vtConstant
|
||||
from cshshlpGateway import CshshlpGateway as gateway
|
||||
from cshshlpGateway import CshshlpGateway
|
||||
|
||||
gatewayClass = CshshlpGateway
|
||||
gatewayName = 'CSHSHLP'
|
||||
gatewayDisplayName = u'中信期权'
|
||||
gatewayType = vtConstant.GATEWAYTYPE_EQUITY
|
||||
|
@ -1,10 +1,10 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnpy.trader import vtConstant
|
||||
from ctpGateway import CtpGateway as gateway
|
||||
from ctpGateway import CtpGateway
|
||||
|
||||
gatewayClass = CtpGateway
|
||||
gatewayName = 'CTP'
|
||||
gatewayDisplayName = gatewayName
|
||||
gatewayDisplayName = 'CTP'
|
||||
gatewayType = vtConstant.GATEWAYTYPE_FUTURES
|
||||
gatewayQryEnabled = True
|
||||
|
||||
|
@ -16,6 +16,7 @@ from datetime import datetime
|
||||
from vnpy.api.ctp import MdApi, TdApi, defineDict
|
||||
from vnpy.trader.vtGateway import *
|
||||
from vnpy.trader.gateway.ctpGateway.language import text
|
||||
from vnpy.trader.vtConstant import GATEWAYTYPE_FUTURES
|
||||
|
||||
|
||||
# 以下为一些VT类型和CTP类型的映射字典
|
||||
@ -88,7 +89,7 @@ class CtpGateway(VtGateway):
|
||||
self.mdConnected = False # 行情API连接状态,登录完成后为True
|
||||
self.tdConnected = False # 交易API连接状态
|
||||
|
||||
self.qryEnabled = False # 是否要启动循环查询
|
||||
self.qryEnabled = False # 循环查询
|
||||
|
||||
self.requireAuthentication = False
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnpy.trader import vtConstant
|
||||
from femasGateway import FemasGateway as gateway
|
||||
from femasGateway import FemasGateway
|
||||
|
||||
gatewayClass = FemasGateway
|
||||
gatewayName = 'FEMAS'
|
||||
gatewayDisplayName = u'飞马'
|
||||
gatewayType = vtConstant.GATEWAYTYPE_FUTURES
|
||||
|
@ -1,8 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnpy.trader import vtConstant
|
||||
from huobiGateway import HuobiGateway as gateway
|
||||
from huobiGateway import HuobiGateway
|
||||
|
||||
gatewayClass = HuobiGateway
|
||||
gatewayName = 'HUOBI'
|
||||
gatewayDisplayName = u'火币'
|
||||
gatewayType = vtConstant.GATEWAYTYPE_BTC
|
||||
|
@ -1,8 +1,9 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from vnpy.trader import vtConstant
|
||||
from ibGateway import IbGateway as gateway
|
||||
from ibGateway import IbGateway
|
||||
|
||||
gatewayClass = IbGateway
|
||||
gatewayName = 'IB'
|
||||
gatewayDisplayName = gatewayName
|
||||
gatewayType = vtConstant.GATEWAYTYPE_INTERNATIONAL
|
||||
|
@ -6,17 +6,7 @@ import os
|
||||
# 默认设置
|
||||
from chinese import text, constant
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
SETTING_FILENAME = 'VT_setting.json'
|
||||
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
|
||||
# 打开配置文件,读取语言配置
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'english':
|
||||
from english import text, constant
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
# 是否要使用英文
|
||||
from vnpy.trader.vtGlobal import globalSetting
|
||||
if globalSetting['language'] == 'english':
|
||||
from english import text, constant
|
@ -117,7 +117,7 @@ STRATEGY = u'策略'
|
||||
CTA_STRATEGY = u'CTA策略'
|
||||
|
||||
HELP = u'帮助'
|
||||
RESTORE = u'还原'
|
||||
RESTORE = u'还原窗口'
|
||||
ABOUT = u'关于'
|
||||
TEST = u'测试'
|
||||
CONNECT = u'连接'
|
||||
|
@ -117,7 +117,7 @@ STRATEGY = u'Strategy'
|
||||
CTA_STRATEGY = u'CTA Strategy'
|
||||
|
||||
HELP = u'Help'
|
||||
RESTORE = u'Restore'
|
||||
RESTORE = u'Restore Window'
|
||||
ABOUT = u'About'
|
||||
TEST = u'Test'
|
||||
CONNECT = u'Connect '
|
||||
|
@ -1,23 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
# 默认设置
|
||||
from chinese import text
|
||||
|
||||
# 获取目录上级路径
|
||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
SETTING_FILENAME = 'VT_setting.json'
|
||||
SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
|
||||
|
||||
# 打开配置文件,读取语言配置
|
||||
try:
|
||||
f = file(SETTING_FILENAME)
|
||||
setting = json.load(f)
|
||||
if setting['language'] == 'english':
|
||||
from english import text
|
||||
f.close()
|
||||
except:
|
||||
traceback.print_exc()
|
@ -3,6 +3,7 @@
|
||||
import json
|
||||
import csv
|
||||
import os
|
||||
import platform
|
||||
from collections import OrderedDict
|
||||
|
||||
from qtpy import QtWidgets, QtGui, QtCore
|
||||
@ -18,6 +19,12 @@ COLOR_RED = QtGui.QColor('red')
|
||||
COLOR_GREEN = QtGui.QColor('green')
|
||||
|
||||
|
||||
# 设置Windows底部任务栏图标
|
||||
if 'Windows' in platform.uname():
|
||||
import ctypes
|
||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader')
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def loadFont():
|
||||
"""载入字体设置"""
|
||||
@ -723,7 +730,9 @@ class TradingWidget(QtWidgets.QFrame):
|
||||
self.symbol = ''
|
||||
|
||||
# 添加交易接口
|
||||
self.gatewayList.extend(mainEngine.getAllGatewayNames())
|
||||
l = mainEngine.getAllGatewayDetails()
|
||||
gatewayNameList = [d['gatewayName'] for d in l]
|
||||
self.gatewayList.extend(gatewayNameList)
|
||||
|
||||
self.initUi()
|
||||
self.connectSignal()
|
||||
|
@ -2,28 +2,41 @@
|
||||
|
||||
import psutil
|
||||
|
||||
from vnpy.trader.gateway import GATEWAY_DICT
|
||||
from vnpy.trader.vtGlobal import globalSetting
|
||||
from vnpy.trader.uiBasicWidget import *
|
||||
from vnpy.trader.ctaStrategy.uiCtaWidget import CtaEngineManager
|
||||
from vnpy.trader.dataRecorder.uiDrWidget import DrEngineManager
|
||||
from vnpy.trader.riskManager.uiRmWidget import RmEngineManager
|
||||
#from vnpy.trader.ctaStrategy.uiCtaWidget import CtaEngineManager
|
||||
#from vnpy.trader.dataRecorder.uiDrWidget import DrEngineManager
|
||||
#from vnpy.trader.riskManager.uiRmWidget import RmEngineManager
|
||||
|
||||
|
||||
########################################################################
|
||||
class MainWindow(QtWidgets.QMainWindow):
|
||||
"""主窗口"""
|
||||
"""主窗口"""
|
||||
|
||||
signalStatusBar = QtCore.Signal(type(Event()))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __init__(self, mainEngine, eventEngine):
|
||||
"""Constructor"""
|
||||
# 实例化主窗口对象时,设置Qt的皮肤
|
||||
if globalSetting['darkStyle']:
|
||||
import qdarkstyle
|
||||
app = QtWidgets.QApplication.instance()
|
||||
app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))
|
||||
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
self.mainEngine = mainEngine
|
||||
self.eventEngine = eventEngine
|
||||
|
||||
l = self.mainEngine.getAllGatewayDetails()
|
||||
self.gatewayNameList = [d['gatewayName'] for d in l]
|
||||
|
||||
self.widgetDict = {} # 用来保存子窗口的字典
|
||||
|
||||
# 获取主引擎中的上层应用信息
|
||||
self.appDetailList = self.mainEngine.getAllAppDetails()
|
||||
|
||||
self.initUi()
|
||||
self.loadWindowSettings('custom')
|
||||
|
||||
@ -67,36 +80,33 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
menubar = self.menuBar()
|
||||
|
||||
# 设计为只显示存在的接口
|
||||
gatewayDetails = self.mainEngine.getAllGatewayDetails()
|
||||
|
||||
sysMenu = menubar.addMenu(vtText.SYSTEM)
|
||||
|
||||
for gatewayModule in GATEWAY_DICT.values():
|
||||
if gatewayModule.gatewayType == GATEWAYTYPE_FUTURES:
|
||||
self.addConnectAction(sysMenu, gatewayModule.gatewayName,
|
||||
gatewayModule.gatewayDisplayName)
|
||||
|
||||
for d in gatewayDetails:
|
||||
if d['gatewayType'] == GATEWAYTYPE_FUTURES:
|
||||
self.addConnectAction(sysMenu, d['gatewayName'], d['gatewayDisplayName'])
|
||||
sysMenu.addSeparator()
|
||||
for gatewayModule in GATEWAY_DICT.values():
|
||||
if gatewayModule.gatewayType == GATEWAYTYPE_EQUITY:
|
||||
self.addConnectAction(sysMenu, gatewayModule.gatewayName,
|
||||
gatewayModule.gatewayDisplayName)
|
||||
|
||||
sysMenu.addSeparator()
|
||||
for gatewayModule in GATEWAY_DICT.values():
|
||||
if gatewayModule.gatewayType == GATEWAYTYPE_INTERNATIONAL:
|
||||
self.addConnectAction(sysMenu, gatewayModule.gatewayName,
|
||||
gatewayModule.gatewayDisplayName)
|
||||
|
||||
for d in gatewayDetails:
|
||||
if d['gatewayType'] == GATEWAYTYPE_EQUITY:
|
||||
self.addConnectAction(sysMenu, d['gatewayName'], d['gatewayDisplayName'])
|
||||
sysMenu.addSeparator()
|
||||
for gatewayModule in GATEWAY_DICT.values():
|
||||
if gatewayModule.gatewayType == GATEWAYTYPE_BTC:
|
||||
self.addConnectAction(sysMenu, gatewayModule.gatewayName,
|
||||
gatewayModule.gatewayDisplayName)
|
||||
|
||||
|
||||
for d in gatewayDetails:
|
||||
if d['gatewayType'] == GATEWAYTYPE_INTERNATIONAL:
|
||||
self.addConnectAction(sysMenu, d['gatewayName'], d['gatewayDisplayName'])
|
||||
sysMenu.addSeparator()
|
||||
for gatewayModule in GATEWAY_DICT.values():
|
||||
if gatewayModule.gatewayType == GATEWAYTYPE_DATA:
|
||||
self.addConnectAction(sysMenu, gatewayModule.gatewayName,
|
||||
gatewayModule.gatewayDisplayName)
|
||||
|
||||
for d in gatewayDetails:
|
||||
if d['gatewayType'] == GATEWAYTYPE_BTC:
|
||||
self.addConnectAction(sysMenu, d['gatewayName'], d['gatewayDisplayName'])
|
||||
sysMenu.addSeparator()
|
||||
|
||||
for d in gatewayDetails:
|
||||
if d['gatewayType'] == GATEWAYTYPE_DATA:
|
||||
self.addConnectAction(sysMenu, d['gatewayName'], d['gatewayDisplayName'])
|
||||
|
||||
sysMenu.addSeparator()
|
||||
sysMenu.addAction(self.createAction(vtText.CONNECT_DATABASE, self.mainEngine.dbConnect))
|
||||
@ -104,19 +114,28 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
sysMenu.addAction(self.createAction(vtText.EXIT, self.close))
|
||||
|
||||
# 功能应用
|
||||
functionMenu = menubar.addMenu(vtText.APPLICATION)
|
||||
functionMenu.addAction(self.createAction(vtText.CONTRACT_SEARCH, self.openContract))
|
||||
functionMenu.addAction(self.createAction(vtText.DATA_RECORDER, self.openDr))
|
||||
functionMenu.addAction(self.createAction(vtText.RISK_MANAGER, self.openRm))
|
||||
#functionMenu = menubar.addMenu(vtText.APPLICATION)
|
||||
#functionMenu.addAction(self.createAction(vtText.DATA_RECORDER, self.openDr))
|
||||
#functionMenu.addAction(self.createAction(vtText.RISK_MANAGER, self.openRm))
|
||||
|
||||
appMenu = menubar.addMenu(vtText.APPLICATION)
|
||||
|
||||
for appDetail in self.appDetailList:
|
||||
function = self.createOpenAppFunction(appDetail)
|
||||
action = self.createAction(appDetail['appDisplayName'], function)
|
||||
appMenu.addAction(action)
|
||||
|
||||
# 算法相关
|
||||
strategyMenu = menubar.addMenu(vtText.STRATEGY)
|
||||
strategyMenu.addAction(self.createAction(vtText.CTA_STRATEGY, self.openCta))
|
||||
#strategyMenu = menubar.addMenu(vtText.STRATEGY)
|
||||
#strategyMenu.addAction(self.createAction(vtText.CTA_STRATEGY, self.openCta))
|
||||
|
||||
# 帮助
|
||||
helpMenu = menubar.addMenu(vtText.HELP)
|
||||
helpMenu.addAction(self.createAction(vtText.CONTRACT_SEARCH, self.openContract))
|
||||
helpMenu.addSeparator()
|
||||
helpMenu.addAction(self.createAction(vtText.RESTORE, self.restoreWindow))
|
||||
helpMenu.addAction(self.createAction(vtText.ABOUT, self.openAbout))
|
||||
helpMenu.addSeparator()
|
||||
helpMenu.addAction(self.createAction(vtText.TEST, self.test))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -152,12 +171,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
#----------------------------------------------------------------------
|
||||
def addConnectAction(self, menu, gatewayName, displayName=''):
|
||||
"""增加连接功能"""
|
||||
if gatewayName not in self.mainEngine.getAllGatewayNames():
|
||||
if gatewayName not in self.gatewayNameList:
|
||||
return
|
||||
|
||||
def connect():
|
||||
self.mainEngine.connect(gatewayName)
|
||||
|
||||
|
||||
if not displayName:
|
||||
displayName = gatewayName
|
||||
|
||||
@ -171,6 +190,20 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
action = QtWidgets.QAction(actionName, self)
|
||||
action.triggered.connect(function)
|
||||
return action
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def createOpenAppFunction(self, appDetail):
|
||||
"""创建打开应用UI的函数"""
|
||||
def openAppFunction():
|
||||
appName = appDetail['appName']
|
||||
try:
|
||||
self.widgetDict[appName].show()
|
||||
except KeyError:
|
||||
appEngine = self.mainEngine.appDict[appName]
|
||||
self.widgetDict[appName] = appDetail['appWidget'](appEngine, self.eventEngine)
|
||||
self.widgetDict[appName].show()
|
||||
|
||||
return openAppFunction
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def test(self):
|
||||
|
@ -11,9 +11,9 @@ from uiMainWindow import *
|
||||
from vnpy.event import EventEngine
|
||||
from vnpy.rpc import RpcClient
|
||||
|
||||
from vnpy.trader.ctaStrategy.ctaEngine import CtaEngine
|
||||
from vnpy.trader.dataRecorder.drEngine import DrEngine
|
||||
from vnpy.trader.riskManager.rmEngine import RmEngine
|
||||
from vnpy.trader.app.ctaStrategy.ctaEngine import CtaEngine
|
||||
from vnpy.trader.app.dataRecorder.drEngine import DrEngine
|
||||
from vnpy.trader.app.riskManager.rmEngine import RmEngine
|
||||
|
||||
|
||||
|
||||
|
@ -13,10 +13,10 @@ from vnpy.trader.vtEvent import *
|
||||
from vnpy.trader.vtGateway import *
|
||||
from vnpy.trader.language import text
|
||||
|
||||
from vnpy.trader.gateway import GATEWAY_DICT
|
||||
from vnpy.trader.ctaStrategy.ctaEngine import CtaEngine
|
||||
from vnpy.trader.dataRecorder.drEngine import DrEngine
|
||||
from vnpy.trader.riskManager.rmEngine import RmEngine
|
||||
#from vnpy.trader.gateway import GATEWAY_DICT
|
||||
#from vnpy.trader.ctaStrategy.ctaEngine import CtaEngine
|
||||
#from vnpy.trader.dataRecorder.drEngine import DrEngine
|
||||
from vnpy.trader.app import riskManager
|
||||
|
||||
|
||||
########################################################################
|
||||
@ -24,13 +24,13 @@ class MainEngine(object):
|
||||
"""主引擎"""
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __init__(self):
|
||||
def __init__(self, eventEngine):
|
||||
"""Constructor"""
|
||||
# 记录今日日期
|
||||
self.todayDate = datetime.now().strftime('%Y%m%d')
|
||||
|
||||
# 创建事件引擎
|
||||
self.eventEngine = EventEngine2()
|
||||
# 绑定事件引擎
|
||||
self.eventEngine = eventEngine
|
||||
self.eventEngine.start()
|
||||
|
||||
# 创建数据引擎
|
||||
@ -40,12 +40,18 @@ class MainEngine(object):
|
||||
self.dbClient = None # MongoDB客户端对象
|
||||
|
||||
# 调用一个个初始化函数
|
||||
self.initGateway()
|
||||
|
||||
# 扩展模块
|
||||
self.ctaEngine = CtaEngine(self, self.eventEngine)
|
||||
self.drEngine = DrEngine(self, self.eventEngine)
|
||||
self.rmEngine = RmEngine(self, self.eventEngine)
|
||||
#self.initGateway()
|
||||
|
||||
# 接口实例
|
||||
self.gatewayDict = OrderedDict()
|
||||
self.gatewayDetailList = []
|
||||
|
||||
# 应用模块实例
|
||||
self.appDict = OrderedDict()
|
||||
self.appDetailList = []
|
||||
|
||||
# 风控引擎实例(特殊独立对象)
|
||||
self.rmEngine = None
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def initGateway(self):
|
||||
@ -63,9 +69,41 @@ class MainEngine(object):
|
||||
print e
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def addGateway(self, gatewayClass, gatewayName=None):
|
||||
"""创建接口"""
|
||||
self.gatewayDict[gatewayName] = gatewayClass(self.eventEngine, gatewayName)
|
||||
def addGateway(self, gatewayModule):
|
||||
"""添加底层接口"""
|
||||
gatewayName = gatewayModule.gatewayName
|
||||
|
||||
# 创建接口实例
|
||||
self.gatewayDict[gatewayName] = gatewayModule.gatewayClass(self.eventEngine,
|
||||
gatewayName)
|
||||
|
||||
# 设置接口轮询
|
||||
if gatewayModule.gatewayQryEnabled:
|
||||
self.gatewayDict[gatewayName].setQryEnabled(gatewayModule.gatewayQryEnabled)
|
||||
|
||||
# 保存接口详细信息
|
||||
d = {
|
||||
'gatewayName': gatewayModule.gatewayName,
|
||||
'gatewayDisplayName': gatewayModule.gatewayDisplayName,
|
||||
'gatewayType': gatewayModule.gatewayType
|
||||
}
|
||||
self.gatewayDetailList.append(d)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def addApp(self, appModule):
|
||||
"""添加上层应用"""
|
||||
appName = appModule.appName
|
||||
|
||||
# 创建应用实例
|
||||
self.appDict[appName] = appModule.appEngine(self, self.eventEngine)
|
||||
|
||||
# 保存应用信息
|
||||
d = {
|
||||
'appName': appModule.appName,
|
||||
'appDisplayName': appModule.appDisplayName,
|
||||
'appWidget': appModule.appWidget
|
||||
}
|
||||
self.appDetailList.append(d)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getGateway(self, gatewayName):
|
||||
@ -98,8 +136,8 @@ class MainEngine(object):
|
||||
#----------------------------------------------------------------------
|
||||
def sendOrder(self, orderReq, gatewayName):
|
||||
"""对特定接口发单"""
|
||||
# 如果风控检查失败则不发单
|
||||
if not self.rmEngine.checkRisk(orderReq):
|
||||
# 如果创建了风控引擎,且风控检查失败则不发单
|
||||
if self.rmEngine and not self.rmEngine.checkRisk(orderReq):
|
||||
return ''
|
||||
|
||||
gateway = self.getGateway(gatewayName)
|
||||
@ -246,10 +284,14 @@ class MainEngine(object):
|
||||
return self.dataEngine.getAllWorkingOrders()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getAllGatewayNames(self):
|
||||
"""查询引擎中所有可用接口的名称"""
|
||||
return self.gatewayDict.keys()
|
||||
|
||||
def getAllGatewayDetails(self):
|
||||
"""查询引擎中所有底层接口的信息"""
|
||||
return self.gatewayDetailList
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getAllAppDetails(self):
|
||||
"""查询引擎中所有上层应用的信息"""
|
||||
return self.appDetailList
|
||||
|
||||
|
||||
########################################################################
|
||||
|
@ -33,4 +33,23 @@ def todayDate():
|
||||
"""获取当前本机电脑时间的日期"""
|
||||
return datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def loadIconPath():
|
||||
"""加载程序图标路径"""
|
||||
iconName = 'vnpy.ico'
|
||||
|
||||
# 首先尝试从当前目录加载图标
|
||||
path = os.getcwd()
|
||||
iconPath = os.path.join(path, iconName)
|
||||
if os.path.isfile(iconPath):
|
||||
return iconPath
|
||||
|
||||
# 如果失败则从vt根目录加载图标
|
||||
else:
|
||||
path = os.path.abspath(os.path.dirname(__file__))
|
||||
iconPath = os.path.join(path, iconName)
|
||||
return iconPath
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -20,6 +20,5 @@ try:
|
||||
f = file(settingFileName)
|
||||
globalSetting = json.load(f)
|
||||
except:
|
||||
print u'加载'
|
||||
traceback.print_exc()
|
||||
|
||||
|
@ -1,50 +1,66 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
# 重载sys模块,设置默认字符串编码方式为utf8
|
||||
import sys
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
|
||||
# Python内置模块
|
||||
import os
|
||||
import platform
|
||||
|
||||
# Python三方模块
|
||||
from qtpy import QtWidgets, QtGui
|
||||
|
||||
# vn.trader模块
|
||||
from vnpy.event import EventEngine2
|
||||
from vnpy.trader.vtGlobal import globalSetting
|
||||
from vnpy.trader.vtEngine import MainEngine
|
||||
from vnpy.trader.uiMainWindow import MainWindow, BASIC_FONT
|
||||
from vnpy.trader.vtFunction import loadIconPath
|
||||
|
||||
# 文件路径名
|
||||
path = os.path.abspath(os.path.dirname(__file__))
|
||||
ICON_FILENAME = 'vnpy.ico'
|
||||
ICON_FILENAME = os.path.join(path, ICON_FILENAME)
|
||||
# 加载底层接口
|
||||
from vnpy.trader.gateway import (ctpGateway,
|
||||
ibGateway,
|
||||
huobiGateway)
|
||||
|
||||
# 加载上层应用
|
||||
from vnpy.trader.app import (riskManager, dataRecorder,
|
||||
ctaStrategy)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def main():
|
||||
"""主程序入口"""
|
||||
# 重载sys模块,设置默认字符串编码方式为utf8
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
# 创建事件引擎
|
||||
ee = EventEngine2()
|
||||
|
||||
# 设置Windows底部任务栏图标
|
||||
if 'Windows' in platform.uname():
|
||||
import ctypes
|
||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('vn.trader')
|
||||
# 创建主引擎
|
||||
me = MainEngine(ee)
|
||||
|
||||
# 添加交易接口
|
||||
me.addGateway(ctpGateway)
|
||||
me.addGateway(ibGateway)
|
||||
me.addGateway(huobiGateway)
|
||||
|
||||
# 添加上层应用
|
||||
me.addApp(riskManager)
|
||||
me.addApp(dataRecorder)
|
||||
me.addApp(ctaStrategy)
|
||||
|
||||
# 初始化Qt应用对象
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
app.setWindowIcon(QtGui.QIcon(ICON_FILENAME))
|
||||
app.setWindowIcon(QtGui.QIcon(loadIconPath()))
|
||||
app.setFont(BASIC_FONT)
|
||||
|
||||
# 设置Qt的皮肤
|
||||
if globalSetting['darkStyle']:
|
||||
import qdarkstyle
|
||||
app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))
|
||||
|
||||
# 初始化主引擎和主窗口对象
|
||||
mainEngine = MainEngine()
|
||||
mainWindow = MainWindow(mainEngine, mainEngine.eventEngine)
|
||||
mainWindow.showMaximized()
|
||||
mw = MainWindow(me, ee)
|
||||
mw.showMaximized()
|
||||
|
||||
# 在主线程中启动Qt事件循环
|
||||
sys.exit(app.exec_())
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user