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')