From 53b8aa058e87f8542fc22a70c15b39a1320eb417 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 11 Jan 2018 16:02:59 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=E6=96=B0=E5=A2=9E=E6=97=A0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E7=9A=84JaqsService=E6=9C=8D=E5=8A=A1=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/JaqsService/run.py | 36 +++++++++++++------------ examples/JaqsService/runUI.py | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 examples/JaqsService/runUI.py diff --git a/examples/JaqsService/run.py b/examples/JaqsService/run.py index caedbcbe..cf954f24 100644 --- a/examples/JaqsService/run.py +++ b/examples/JaqsService/run.py @@ -5,13 +5,11 @@ import sys reload(sys) sys.setdefaultencoding('utf8') -# 判断操作系统 -import platform -system = platform.system() +from time import sleep # vn.trader模块 from vnpy.event import EventEngine -from vnpy.trader.vtEngine import MainEngine +from vnpy.trader.vtEngine import MainEngine, LogEngine from vnpy.trader.uiQt import createQApp from vnpy.trader.uiMainWindow import MainWindow @@ -20,31 +18,35 @@ from vnpy.trader.gateway import ctpGateway # 加载上层应用 from vnpy.trader.app import jaqsService +from vnpy.trader.app.jaqsService.jsEngine import EVENT_JS_LOG #---------------------------------------------------------------------- def main(): """主程序入口""" - # 创建Qt应用对象 - qApp = createQApp() + le = LogEngine() + le.setLogLevel(le.LEVEL_INFO) + le.addConsoleHandler() + le.addFileHandler() + + le.info(u'启动JAQS服务进程') - # 创建事件引擎 ee = EventEngine() + le.info(u'事件引擎创建成功') - # 创建主引擎 me = MainEngine(ee) - - # 添加交易接口 me.addGateway(ctpGateway) - - # 添加上层应用 me.addApp(jaqsService) + le.info(u'主引擎创建成功') - # 创建主窗口 - mw = MainWindow(me, ee) - mw.showMaximized() + ee.register(EVENT_LOG, le.processLogEvent) + ee.register(EVENT_JS_LOG, le.processLogEvent) + le.info(u'注册日志事件监听') - # 在主线程中启动Qt事件循环 - sys.exit(qApp.exec_()) + me.connect('CTP') + le.info(u'连接CTP接口') + + while True: + sleep(1) if __name__ == '__main__': diff --git a/examples/JaqsService/runUI.py b/examples/JaqsService/runUI.py new file mode 100644 index 00000000..caedbcbe --- /dev/null +++ b/examples/JaqsService/runUI.py @@ -0,0 +1,51 @@ +# encoding: UTF-8 + +# 重载sys模块,设置默认字符串编码方式为utf8 +import sys +reload(sys) +sys.setdefaultencoding('utf8') + +# 判断操作系统 +import platform +system = platform.system() + +# vn.trader模块 +from vnpy.event import EventEngine +from vnpy.trader.vtEngine import MainEngine +from vnpy.trader.uiQt import createQApp +from vnpy.trader.uiMainWindow import MainWindow + +# 加载底层接口 +from vnpy.trader.gateway import ctpGateway + +# 加载上层应用 +from vnpy.trader.app import jaqsService + +#---------------------------------------------------------------------- +def main(): + """主程序入口""" + # 创建Qt应用对象 + qApp = createQApp() + + # 创建事件引擎 + ee = EventEngine() + + # 创建主引擎 + me = MainEngine(ee) + + # 添加交易接口 + me.addGateway(ctpGateway) + + # 添加上层应用 + me.addApp(jaqsService) + + # 创建主窗口 + mw = MainWindow(me, ee) + mw.showMaximized() + + # 在主线程中启动Qt事件循环 + sys.exit(qApp.exec_()) + + +if __name__ == '__main__': + main()