2017-09-02 15:16:58 +00:00
|
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
|
|
# 重载sys模块,设置默认字符串编码方式为utf8
|
|
|
|
|
import sys
|
|
|
|
|
reload(sys)
|
|
|
|
|
sys.setdefaultencoding('utf8')
|
|
|
|
|
|
2017-09-03 06:51:17 +00:00
|
|
|
|
from time import sleep
|
2017-09-02 15:16:58 +00:00
|
|
|
|
|
|
|
|
|
# vn.trader模块
|
|
|
|
|
from vnpy.event import EventEngine2
|
2017-09-03 06:51:17 +00:00
|
|
|
|
from vnpy.trader.vtEngine import MainEngine, LogEngine
|
2017-09-02 15:16:58 +00:00
|
|
|
|
|
|
|
|
|
# 加载底层接口
|
|
|
|
|
from vnpy.trader.gateway import ctpGateway
|
|
|
|
|
|
|
|
|
|
# 加载上层应用
|
2017-09-03 06:51:17 +00:00
|
|
|
|
from vnpy.trader.app import ctaStrategy, rpcService
|
2017-09-02 15:16:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
def main():
|
|
|
|
|
"""主程序入口"""
|
2017-09-03 06:51:17 +00:00
|
|
|
|
le = LogEngine()
|
|
|
|
|
le.setLogLevel(le.LEVEL_INFO)
|
|
|
|
|
le.addConsoleHandler()
|
|
|
|
|
le.addFileHandler()
|
|
|
|
|
|
|
|
|
|
le.info(u'服务器进程启动')
|
|
|
|
|
|
2017-09-02 15:16:58 +00:00
|
|
|
|
# 创建事件引擎
|
|
|
|
|
ee = EventEngine2()
|
2017-09-03 06:51:17 +00:00
|
|
|
|
le.info(u'事件引擎创建成功')
|
2017-09-02 15:16:58 +00:00
|
|
|
|
|
|
|
|
|
# 创建主引擎
|
|
|
|
|
me = MainEngine(ee)
|
|
|
|
|
|
|
|
|
|
# 添加交易接口
|
|
|
|
|
me.addGateway(ctpGateway)
|
|
|
|
|
|
|
|
|
|
# 添加上层应用
|
2017-09-03 06:51:17 +00:00
|
|
|
|
me.addApp(ctaStrategy)
|
|
|
|
|
me.addApp(rpcService)
|
|
|
|
|
|
|
|
|
|
le.info(u'主引擎创建成功')
|
2017-09-02 15:16:58 +00:00
|
|
|
|
|
|
|
|
|
# 阻塞运行
|
2017-09-03 06:51:17 +00:00
|
|
|
|
le.info(u'服务器启动成功')
|
|
|
|
|
while 1:
|
|
|
|
|
sleep(1)
|
2017-09-02 15:16:58 +00:00
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|