IB 1. 修复时间格式, 增加毫秒 2. IB外汇没有时间的问题
This commit is contained in:
parent
163fc39f15
commit
8d73c80919
@ -13,7 +13,7 @@ ibpy的gateway接入
|
||||
|
||||
import os
|
||||
import json
|
||||
from time import sleep, strftime, localtime
|
||||
from datetime import datetime
|
||||
from copy import copy
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
@ -193,6 +193,7 @@ class IbGateway(VtGateway):
|
||||
tick.exchange = subscribeReq.exchange
|
||||
tick.vtSymbol = '.'.join([tick.symbol, tick.exchange])
|
||||
tick.gatewayName = self.gatewayName
|
||||
tick.__setattr__('m_secType', productClassMap.get(subscribeReq.productClass, ''))
|
||||
self.tickDict[self.tickerId] = tick
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -281,6 +282,13 @@ class IbWrapper(EWrapper):
|
||||
tick = self.tickDict[tickerId]
|
||||
key = tickFieldMap[field]
|
||||
tick.__setattr__(key, price)
|
||||
|
||||
# 外汇单独设置时间, tickString 没有返回外汇时间
|
||||
if tick.m_secType == 'CASH':
|
||||
dt_obj = datetime.now()
|
||||
tick.time = dt_obj.strftime('%H:%M:%S.%f')
|
||||
tick.date = dt_obj.strftime('%Y%m%d')
|
||||
|
||||
# 行情数据更新
|
||||
newtick = copy(tick)
|
||||
self.gateway.onTick(newtick)
|
||||
@ -293,7 +301,17 @@ class IbWrapper(EWrapper):
|
||||
if field in tickFieldMap:
|
||||
tick = self.tickDict[tickerId]
|
||||
key = tickFieldMap[field]
|
||||
tick.__setattr__(key, size)
|
||||
tick.__setattr__(key, size)
|
||||
|
||||
# 外汇单独设置时间, tickString 没有返回外汇时间
|
||||
if tick.m_secType == 'CASH':
|
||||
dt_obj = datetime.now()
|
||||
tick.time = dt_obj.strftime('%H:%M:%S.%f')
|
||||
tick.date = dt_obj.strftime('%Y%m%d')
|
||||
|
||||
# 行情数据更新
|
||||
newtick = copy(tick)
|
||||
self.gateway.onTick(newtick)
|
||||
else:
|
||||
print field
|
||||
|
||||
@ -310,12 +328,12 @@ class IbWrapper(EWrapper):
|
||||
#----------------------------------------------------------------------
|
||||
def tickString(self, tickerId, tickType, value):
|
||||
"""行情推送,特殊字段相关"""
|
||||
if tickType == 45:
|
||||
lt = localtime(int(value))
|
||||
if tickType == 45:
|
||||
dt_obj = datetime.utcfromtimestamp(int(value))
|
||||
|
||||
tick = self.tickDict[tickerId]
|
||||
tick.time = strftime('%H:%M:%S', lt)
|
||||
tick.date = strftime('%Y%m%d')
|
||||
tick.time = dt_obj.strftime('%H:%M:%S.%f')
|
||||
tick.date = dt_obj.strftime('%Y%m%d')
|
||||
|
||||
# 这里使用copy的目的是为了保证推送到事件系统中的对象
|
||||
# 不会被当前的API线程修改,否则可能出现多线程数据同步错误
|
||||
@ -439,8 +457,8 @@ class IbWrapper(EWrapper):
|
||||
contract.exchange = contractDetails.m_summary.m_exchange
|
||||
|
||||
contract.vtSymbol = '.'.join([contract.symbol, contract.exchange])
|
||||
contract.name = contractDetails.m_marketName.decode('UTF-8')
|
||||
|
||||
contract.name = contractDetails.m_summary.m_localSymbol.decode('UTF-8')
|
||||
|
||||
# 合约类型
|
||||
if contractDetails.m_summary.m_secType == 'STK':
|
||||
contract.productClass = PRODUCT_EQUITY
|
||||
@ -545,14 +563,15 @@ class IbWrapper(EWrapper):
|
||||
#----------------------------------------------------------------------
|
||||
def currentTime(self, time):
|
||||
""" generated source for method currentTime """
|
||||
t = strftime('%H:%M:%S', localtime(time))
|
||||
|
||||
dt_obj = datetime.utcfromtimestamp(time)
|
||||
t = dt_obj.strftime("%Y-%m-%d %H:%M:%S.%f")
|
||||
|
||||
self.connectionStatus = True
|
||||
self.gateway.connected = True
|
||||
|
||||
log = VtLogData()
|
||||
log.gatewayName = self.gatewayName
|
||||
log.logContent = (u'IB接口连接成功,当前服务器时间%s' %t)
|
||||
log.logContent = (u'IB接口连接成功,当前服务器时间 %s' %t)
|
||||
self.gateway.onLog(log)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user