vnpy/examples/VnTrader/run.py

71 lines
1.7 KiB
Python
Raw Normal View History

# encoding: UTF-8
# 重载sys模块设置默认字符串编码方式为utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
# 判断操作系统
import platform
system = platform.system()
# vn.trader模块
2017-06-04 15:07:15 +00:00
from vnpy.event import EventEngine
from vnpy.trader.vtEngine import MainEngine
from vnpy.trader.uiQt import createQApp
from vnpy.trader.uiMainWindow import MainWindow
# 加载底层接口
2017-12-21 07:18:18 +00:00
from vnpy.trader.gateway import (ctpGateway, oandaGateway,
2018-01-31 14:03:27 +00:00
ibGateway)
if system == 'Windows':
2017-10-18 14:49:58 +00:00
from vnpy.trader.gateway import (femasGateway, xspeedGateway,
futuGateway, secGateway)
# 加载上层应用
from vnpy.trader.app import (riskManager, ctaStrategy, spreadTrading)
#----------------------------------------------------------------------
def main():
"""主程序入口"""
# 创建Qt应用对象
qApp = createQApp()
# 创建事件引擎
2017-06-05 08:22:16 +00:00
ee = EventEngine()
# 创建主引擎
me = MainEngine(ee)
# 添加交易接口
me.addGateway(ctpGateway)
me.addGateway(oandaGateway)
me.addGateway(ibGateway)
if system == 'Windows':
me.addGateway(femasGateway)
me.addGateway(xspeedGateway)
me.addGateway(secGateway)
2017-10-18 14:49:58 +00:00
me.addGateway(futuGateway)
2017-08-31 09:55:42 +00:00
if system == 'Linux':
me.addGateway(xtpGateway)
# 添加上层应用
me.addApp(riskManager)
me.addApp(ctaStrategy)
me.addApp(spreadTrading)
# 创建主窗口
mw = MainWindow(me, ee)
mw.showMaximized()
# 在主线程中启动Qt事件循环
sys.exit(qApp.exec_())
if __name__ == '__main__':
main()