This commit is contained in:
msincenselee 2018-01-30 23:15:32 +08:00
parent 669547e862
commit 7199b44ae1
3 changed files with 53 additions and 44 deletions

View File

View File

@ -1,65 +1,74 @@
# encoding: UTF-8 # encoding: UTF-8
# 重载sys模块设置默认字符串编码方式为utf8 # 重载sys模块设置默认字符串编码方式为utf8
import sys import sys
reload(sys) #reload(sys)
sys.setdefaultencoding('utf8') #sys.setdefaultencoding('utf8')
import sys
import os import os
# 将repostory的目录i作为根目录添加到系统环境中。 import ctypes
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..','..')) import platform
system = platform.system()
# 将repostory的目录作为根目录添加到系统环境中。
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..' , '..'))
sys.path.append(ROOT_PATH) sys.path.append(ROOT_PATH)
print sys.path
# vn.trader模块
from vnpy.event import EventEngine
from vnpy.trader.vtEngine import MainEngine from vnpy.trader.vtEngine import MainEngine
from vnpy.trader.uiQt import qApp from vnpy.trader.uiQt import createQApp
from vnpy.trader.uiMainWindow import MainWindow from vnpy.trader.uiMainWindow import *
# 加载底层接口 # 加载底层接口
from vnpy.trader.gateway import (ctpGateway, femasGateway, xspeedGateway, from vnpy.trader.gateway import ctpGateway
sgitGateway, oandaGateway, ibGateway, # 初始化的接口模块,以及其指定的名称,CTP是模块value是该模块下的多个连接配置文件,如 CTP_JR_connect.json 'CTP_Prod', 'CTP_JR', , 'CTP_JK', 'CTP_02'
shzdGateway, huobiGateway, okcoinGateway) init_gateway_names = {'CTP': ['CTP','CTP_YH01', 'CTP_YH02', 'CTP_YH03','CTP_JK']}
# 加载上层应用 from vnpy.trader.app import (ctaStrategy, riskManager, spreadTrading)
from vnpy.trader.app import (riskManager, dataRecorder,
ctaStrategy)
# 文件路径名
path = os.path.abspath(os.path.dirname(__file__))
ICON_FILENAME = 'vnpy.ico'
ICON_FILENAME = os.path.join(path, ICON_FILENAME)
#---------------------------------------------------------------------- from vnpy.trader.setup_logger import setup_logger
# ----------------------------------------------------------------------
def main(): def main():
"""主程序入口""" """主程序入口"""
logger = setup_logger(filename='logs/vnpy.log', debug=False)
# 创建Qt应用对象
qApp = createQApp()
# 创建事件引擎 # 创建事件引擎
ee = EventEngine() ee = EventEngine2()
# 创建主引擎 # 初始化主引擎和主窗口对象
me = MainEngine(ee) mainEngine = MainEngine(ee)
# 添加交易接口 mainEngine.logger = logger
me.addGateway(ctpGateway)
me.addGateway(femasGateway) # 添加Gatway
me.addGateway(xspeedGateway) for gw_name in init_gateway_names['CTP']:
me.addGateway(sgitGateway) print('add {0}'.format(gw_name))
me.addGateway(oandaGateway) mainEngine.addGateway(ctpGateway, gw_name)
me.addGateway(ibGateway)
me.addGateway(shzdGateway) # 添加应用
me.addGateway(huobiGateway) mainEngine.addApp(ctaStrategy)
me.addGateway(okcoinGateway) mainEngine.addApp(riskManager)
mainEngine.addApp(spreadTrading)
# 添加上层应用
me.addApp(riskManager) mainWindow = MainWindow(mainEngine, ee)
me.addApp(dataRecorder) mainWindow.showMaximized()
me.addApp(ctaStrategy)
# 创建主窗口
mw = MainWindow(me, ee)
mw.showMaximized()
# 在主线程中启动Qt事件循环 # 在主线程中启动Qt事件循环
sys.exit(qApp.exec_()) sys.exit(qApp.exec_())
if __name__ == '__main__': if __name__ == '__main__':
main() try:
main()
except Exception as ex:
print(str(ex))
traceback.print_exc()

0
examples/__init__.py Normal file
View File