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

0
examples/__init__.py Normal file
View File