vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 19
声望: 1

vnpy版本1.9.2
onTick触发时,程序开始和结束的时候,都记录本地时间,并writeCtaLog出来

def onTick(self, tick):
    self.writeCtaLog(u'本地时间: %s' %(datetime,datetime.now())
    tickstarttime = datetime.datetime.now()
    策略主体
    tickendtime = datetime.datetime.now()
    passtime = str(tickendtime - tickstarttime)
    self.writeCtaLog(u'onTick程序运行时长: %s' %(passtime))

一、发现两个现象
有时候打印出来的Log时间差大于onTick程序实际的运行时间,有时候Log时间差又小于onTick程序实际的运行时间,如下:
1、onTick程序运行时间0.001s,Log记录的时间差有0.007s (即23,598 - 23,591)

2019-12-23 13:43:23,591  INFO: CTA_STRATEGY p2005 LongStrategy:本地时间: 2019-12-23 13:43:23.588000
2019-12-23 13:43:23,592  INFO: CTA_STRATEGY p2005 LongStrategy:pos     ****  :0
2019-12-23 13:43:23,592  INFO: CTA_STRATEGY p2005 LongStrategy:self.auto[self.vtSymbol]  :on
2019-12-23 13:43:23,594  INFO: CTA_STRATEGY p2005 LongStrategy:askprice askvolume:6014.0 595
2019-12-23 13:43:23,595  INFO: CTA_STRATEGY p2005 LongStrategy:bidprice bidvolume:6012.0 525
2019-12-23 13:43:23,595  INFO: CTA_STRATEGY p2005 LongStrategy:拒单数 撤单数:0 0
2019-12-23 13:43:23,595  INFO: CTA_STRATEGY p2005 LongStrategy:仓位:0
2019-12-23 13:43:23,596  INFO: CTA_STRATEGY p2005 LongStrategy:self.lastTick.lastVolume:0
2019-12-23 13:43:23,596  INFO: CTA_STRATEGY p2005 LongStrategy:self.lastTick.volume:2501110
2019-12-23 13:43:23,596  INFO: CTA_STRATEGY p2005 LongStrategy:self.limitVolume[self.vtSymbol]:200
2019-12-23 13:43:23,596  INFO: CTA_STRATEGY p2005 LongStrategy:order.price:6000.0
2019-12-23 13:43:23,598  INFO: CTA_STRATEGY p2005 LongStrategy:onTick程序运行时长  :0:00:00.001000

2、onTick程序运行时间0.005s,Log记录的时间只有0.004s (即07,096 - 07,092),
且记录的起始时间比程序本身的时间要晚0.020s,即第一条程序时间13:51:07.072000,Log时间13:51:07,092

2019-12-23 13:51:07,092  INFO: CTA_STRATEGY p2005 LongStrategy:本地时间: 2019-12-23 13:51:07.072000
2019-12-23 13:51:07,092  INFO: CTA_STRATEGY p2005 LongStrategy:pos     ****  :0
2019-12-23 13:51:07,094  INFO: CTA_STRATEGY p2005 LongStrategy:self.auto[self.vtSymbol]  :on
2019-12-23 13:51:07,094  INFO: CTA_STRATEGY p2005 LongStrategy:askprice askvolume:6024.0 415
2019-12-23 13:51:07,094  INFO: CTA_STRATEGY p2005 LongStrategy:bidprice bidvolume:6022.0 660
2019-12-23 13:51:07,095  INFO: CTA_STRATEGY p2005 LongStrategy:拒单数 撤单数:0 0
2019-12-23 13:51:07,095  INFO: CTA_STRATEGY p2005 LongStrategy:仓位:0
2019-12-23 13:51:07,095  INFO: CTA_STRATEGY p2005 LongStrategy:self.lastTick.lastVolume:0
2019-12-23 13:51:07,095  INFO: CTA_STRATEGY p2005 LongStrategy:self.lastTick.volume:2561906
2019-12-23 13:51:07,095  INFO: CTA_STRATEGY p2005 LongStrategy:self.limitVolume[self.vtSymbol]:200
2019-12-23 13:51:07,095  INFO: CTA_STRATEGY p2005 LongStrategy:order.price:6000.0
2019-12-23 13:51:07,096  INFO: CTA_STRATEGY p2005 LongStrategy:onTick程序运行时长  :0:00:00.005000

二、问题
1、writeCtaLog函数记录的时候和程序主体运行是什么样的关系?Log时间差一会大,一会小,感觉是相互独立的
2、如果onTick中运用了较多的writeCtaLog函数来记录,譬如20个策略,每个策略onTick中写出30个writeCtaLog函数,这样在效率上会影响onTick程序的运行么?
3、假如writeCtaLog函数较多会影响onTick程序的效率,怎么提高效率呢,Log的信息改用pandas输出?还是说用多进程multiprocessing包?

非常感谢!

Administrator
avatar
加入于:
帖子: 4228
声望: 241
  1. LOG是本地时间,TICK是服务时间,并不同步
  2. 会的,但是影响很小
  3. 没什么办法,只要写log就一定有IO开销
© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3