[Mod]简化大商所的Tick日期计算逻辑
This commit is contained in:
parent
8b1bc4e2ea
commit
f0c9500a0e
@ -247,10 +247,6 @@ class CtpMdApi(MdApi):
|
||||
self.brokerID = EMPTY_STRING # 经纪商代码
|
||||
self.address = EMPTY_STRING # 服务器地址
|
||||
|
||||
self.tradingDt = None # 交易日datetime对象
|
||||
self.tradingDate = EMPTY_STRING # 交易日期字符串
|
||||
self.tickTime = None # 最新行情time对象
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onFrontConnected(self):
|
||||
"""服务器连接"""
|
||||
@ -298,14 +294,6 @@ class CtpMdApi(MdApi):
|
||||
for subscribeReq in self.subscribedSymbols:
|
||||
self.subscribe(subscribeReq)
|
||||
|
||||
# 获取交易日
|
||||
#self.tradingDate = data['TradingDay']
|
||||
#self.tradingDt = datetime.strptime(self.tradingDate, '%Y%m%d')
|
||||
|
||||
# 登录时通过本地时间来获取当前的日期
|
||||
self.tradingDt = datetime.now()
|
||||
self.tradingDate = self.tradingDt.strftime('%Y%m%d')
|
||||
|
||||
# 否则,推送错误信息
|
||||
else:
|
||||
err = VtErrorData()
|
||||
@ -388,18 +376,7 @@ class CtpMdApi(MdApi):
|
||||
|
||||
# 大商所日期转换
|
||||
if tick.exchange is EXCHANGE_DCE:
|
||||
newTime = datetime.strptime(tick.time, '%H:%M:%S.%f').time() # 最新tick时间戳
|
||||
|
||||
# 如果新tick的时间小于夜盘分隔,且上一个tick的时间大于夜盘分隔,则意味着越过了12点
|
||||
if (self.tickTime and
|
||||
newTime < NIGHT_TRADING and
|
||||
self.tickTime > NIGHT_TRADING):
|
||||
self.tradingDt += timedelta(1) # 日期加1
|
||||
self.tradingDate = self.tradingDt.strftime('%Y%m%d') # 生成新的日期字符串
|
||||
|
||||
tick.date = self.tradingDate # 使用本地维护的日期
|
||||
|
||||
self.tickTime = newTime # 更新上一个tick时间
|
||||
tick.date = datetime.now().strftime('%Y%m%d')
|
||||
|
||||
self.gateway.onTick(tick)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user