From 9fdfb253f0c56c1d424fc86ea394b31f82d502ad Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 2 Feb 2018 09:58:31 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=E5=A2=9E=E5=8A=A0=E6=97=A0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=AF=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E8=BE=93=E5=87=BA=EF=BC=8CClose=20#?= =?UTF-8?q?702?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/CtaTrading/runCtaTrading.py | 15 +++++++++++++-- examples/DataRecording/runDataRecording.py | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/CtaTrading/runCtaTrading.py b/examples/CtaTrading/runCtaTrading.py index 7f315e08..5d3e51ae 100644 --- a/examples/CtaTrading/runCtaTrading.py +++ b/examples/CtaTrading/runCtaTrading.py @@ -9,13 +9,23 @@ from time import sleep from datetime import datetime, time from vnpy.event import EventEngine2 -from vnpy.trader.vtEvent import EVENT_LOG +from vnpy.trader.vtEvent import EVENT_LOG, EVENT_ERROR from vnpy.trader.vtEngine import MainEngine, LogEngine from vnpy.trader.gateway import ctpGateway from vnpy.trader.app import ctaStrategy from vnpy.trader.app.ctaStrategy.ctaBase import EVENT_CTA_LOG - + + +#---------------------------------------------------------------------- +def processErrorEvent(event): + """ + 处理错误事件 + 错误信息在每次登陆后,会将当日所有已产生的均推送一遍,所以不适合写入日志 + """ + error = event.dict_['data'] + print u'错误代码:%s,错误信息:%s' %(error.errorID, error.errorMsg) + #---------------------------------------------------------------------- def runChildProcess(): """子进程运行函数""" @@ -39,6 +49,7 @@ def runChildProcess(): ee.register(EVENT_LOG, le.processLogEvent) ee.register(EVENT_CTA_LOG, le.processLogEvent) + ee.register(EVENT_ERROR, processErrorEvent) le.info(u'注册日志事件监听') me.connect('CTP') diff --git a/examples/DataRecording/runDataRecording.py b/examples/DataRecording/runDataRecording.py index 86e6c1e9..1276330c 100644 --- a/examples/DataRecording/runDataRecording.py +++ b/examples/DataRecording/runDataRecording.py @@ -5,11 +5,18 @@ from time import sleep from datetime import datetime, time from vnpy.event import EventEngine2 -from vnpy.trader.vtEvent import EVENT_LOG +from vnpy.trader.vtEvent import EVENT_LOG, EVENT_ERROR from vnpy.trader.vtEngine import MainEngine, LogEngine from vnpy.trader.gateway import ctpGateway from vnpy.trader.app import dataRecorder + +#---------------------------------------------------------------------- +def processErrorEvent(event): + """处理错误事件""" + error = event.dict_['data'] + print u'错误代码:%s,错误信息:%s' %(error.errorID, error.errorMsg) + #---------------------------------------------------------------------- def runChildProcess(): """子进程运行函数""" @@ -30,6 +37,7 @@ def runChildProcess(): le.info(u'主引擎创建成功') ee.register(EVENT_LOG, le.processLogEvent) + ee.register(EVENT_ERROR, processErrorEvent) le.info(u'注册日志事件监听') me.connect('CTP')