2017-05-02 13:46:12 +00:00
|
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# 重载sys模块,设置默认字符串编码方式为utf8
|
2018-04-13 07:49:43 +00:00
|
|
|
|
try:
|
|
|
|
|
reload # Python 2
|
|
|
|
|
except NameError: # Python 3
|
|
|
|
|
from importlib import reload
|
2018-08-06 06:16:30 +00:00
|
|
|
|
|
2017-05-02 13:46:12 +00:00
|
|
|
|
import sys
|
2017-05-31 16:10:07 +00:00
|
|
|
|
reload(sys)
|
2018-08-06 06:16:30 +00:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
sys.setdefaultencoding('utf8')
|
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
2017-05-31 16:10:07 +00:00
|
|
|
|
|
2017-07-15 10:00:28 +00:00
|
|
|
|
# 判断操作系统
|
|
|
|
|
import platform
|
|
|
|
|
system = platform.system()
|
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# vn.trader模块
|
2017-06-04 15:07:15 +00:00
|
|
|
|
from vnpy.event import EventEngine
|
2017-05-08 09:45:50 +00:00
|
|
|
|
from vnpy.trader.vtEngine import MainEngine
|
2017-07-25 05:37:52 +00:00
|
|
|
|
from vnpy.trader.uiQt import createQApp
|
2017-06-01 07:53:51 +00:00
|
|
|
|
from vnpy.trader.uiMainWindow import MainWindow
|
2017-05-31 16:10:07 +00:00
|
|
|
|
|
|
|
|
|
# 加载底层接口
|
2018-12-26 04:30:02 +00:00
|
|
|
|
from vnpy.trader.gateway import (ctpGateway, ibGateway, huobiGateway)
|
2017-07-15 10:00:28 +00:00
|
|
|
|
|
2018-04-13 07:49:43 +00:00
|
|
|
|
if system == 'Linux':
|
|
|
|
|
from vnpy.trader.gateway import xtpGateway
|
|
|
|
|
elif system == 'Windows':
|
|
|
|
|
from vnpy.trader.gateway import (femasGateway, xspeedGateway,
|
2018-05-27 15:58:19 +00:00
|
|
|
|
secGateway)
|
2017-05-02 13:46:12 +00:00
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# 加载上层应用
|
2018-06-09 10:54:41 +00:00
|
|
|
|
from vnpy.trader.app import (riskManager, ctaStrategy,
|
2018-12-02 05:24:04 +00:00
|
|
|
|
spreadTrading, algoTrading,
|
|
|
|
|
tradeCopy)
|
2017-05-02 13:46:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def main():
|
|
|
|
|
"""主程序入口"""
|
2017-07-25 05:37:52 +00:00
|
|
|
|
# 创建Qt应用对象
|
|
|
|
|
qApp = createQApp()
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# 创建事件引擎
|
2017-06-05 08:22:16 +00:00
|
|
|
|
ee = EventEngine()
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# 创建主引擎
|
|
|
|
|
me = MainEngine(ee)
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# 添加交易接口
|
2017-07-09 13:05:23 +00:00
|
|
|
|
me.addGateway(ctpGateway)
|
|
|
|
|
me.addGateway(ibGateway)
|
2018-12-26 04:30:02 +00:00
|
|
|
|
me.addGateway(huobiGateway)
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-07-15 10:00:28 +00:00
|
|
|
|
if system == 'Windows':
|
|
|
|
|
me.addGateway(femasGateway)
|
|
|
|
|
me.addGateway(xspeedGateway)
|
2017-10-23 02:07:43 +00:00
|
|
|
|
me.addGateway(secGateway)
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-08-31 09:55:42 +00:00
|
|
|
|
if system == 'Linux':
|
|
|
|
|
me.addGateway(xtpGateway)
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-05-31 16:10:07 +00:00
|
|
|
|
# 添加上层应用
|
|
|
|
|
me.addApp(riskManager)
|
|
|
|
|
me.addApp(ctaStrategy)
|
2017-06-12 09:14:34 +00:00
|
|
|
|
me.addApp(spreadTrading)
|
2018-06-09 10:54:41 +00:00
|
|
|
|
me.addApp(algoTrading)
|
2018-12-02 05:24:04 +00:00
|
|
|
|
me.addApp(tradeCopy)
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-06-01 07:53:51 +00:00
|
|
|
|
# 创建主窗口
|
2017-05-31 16:10:07 +00:00
|
|
|
|
mw = MainWindow(me, ee)
|
|
|
|
|
mw.showMaximized()
|
2018-04-13 07:49:43 +00:00
|
|
|
|
|
2017-05-02 13:46:12 +00:00
|
|
|
|
# 在主线程中启动Qt事件循环
|
2017-06-01 07:53:51 +00:00
|
|
|
|
sys.exit(qApp.exec_())
|
2017-05-31 16:10:07 +00:00
|
|
|
|
|
|
|
|
|
|
2017-05-02 13:46:12 +00:00
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|