修改部分功能

This commit is contained in:
vnpy 2016-05-05 21:52:11 +08:00
parent f755611607
commit 8b57222897
5 changed files with 20 additions and 17 deletions

1
.gitignore vendored
View File

@ -14,7 +14,6 @@ Release/
# Python编译文件
*.pyc
*.pyd
# WingIDE文件
*.wpr

View File

@ -14,6 +14,7 @@ from ctaSetting import STRATEGY_CLASS
from eventEngine import *
from vtConstant import *
from vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData
from vtFunction import todayDate
########################################################################
@ -29,7 +30,7 @@ class CtaEngine(object):
self.eventEngine = eventEngine
# 当前日期
self.today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
self.today = todayDate()
# 保存策略实例的字典
# key为策略名称value为策略实例注意策略名称不允许重复
@ -431,3 +432,5 @@ class CtaEngine(object):
self.eventEngine.put(event)

View File

@ -15,6 +15,7 @@ from datetime import datetime, timedelta
from eventEngine import *
from vtGateway import VtSubscribeReq, VtLogData
from drBase import *
from vtFunction import todayDate
########################################################################
@ -31,7 +32,7 @@ class DrEngine(object):
self.eventEngine = eventEngine
# 当前日期
self.today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
self.today = todayDate()
# 主力合约代码映射字典key为具体的合约代码如IF1604value为主力合约代码如IF0000
self.activeSymbolDict = {}

View File

@ -68,6 +68,7 @@ productClassMap[PRODUCT_EQUITY] = 'STK'
productClassMap[PRODUCT_FUTURES] = 'FUT'
productClassMap[PRODUCT_OPTION] = 'OPT'
productClassMap[PRODUCT_FOREX] = 'CASH'
productClassMapReverse = {v:k for k,v in productClassMap.items()}
# 期权类型映射
optionTypeMap = {}
@ -184,6 +185,7 @@ class IbGateway(VtGateway):
contract.m_strike = subscribeReq.strikePrice
contract.m_right = optionTypeMap.get(subscribeReq.optionType, '')
# 考虑设计为针对期货用代码_到期日的方式来代替单纯的代码
if contract.m_secType == 'FUT' and not subscribeReq.expiry:
# 期货 如果没有设置过期时间, 默认设置为下个月
dt_obj = datetime.now()
@ -469,30 +471,22 @@ class IbWrapper(EWrapper):
contract.name = contractDetails.m_summary.m_localSymbol.decode('UTF-8')
# 合约类型
if contractDetails.m_summary.m_secType == 'STK':
contract.productClass = PRODUCT_EQUITY
elif contractDetails.m_summary.m_secType == 'CASH':
contract.productClass = PRODUCT_FOREX
elif contractDetails.m_summary.m_secType == 'FUT':
contract.productClass = PRODUCT_FUTURES
elif contractDetails.m_summary.m_secType == 'OPT':
contract.productClass = PRODUCT_OPTION
else:
contract.productClass = PRODUCT_UNKNOWN
contract.productClass = productClassMapReverse.get(contractDetails.m_summary.m_secType,
PRODUCT_UNKNOWN)
# 推送
self.gateway.onContract(contract)
#----------------------------------------------------------------------
def bondContractDetails(self, reqId, contractDetails):
""" generated source for method bondContractDetails """
pass
#----------------------------------------------------------------------
def contractDetailsEnd(self, reqId):
""" 获取合约结束 """
log = VtLogData()
log.gatewayName = self.gatewayName
log.logContent = u'交易合约信息获取完成'
self.gateway.onLog(log)
# 因为IB的合约获取是一个个合约进行的并不会用于触发其他操作因此无需发出日志
pass
#----------------------------------------------------------------------
def execDetails(self, reqId, contract, execution):

View File

@ -6,6 +6,7 @@
import decimal
import json
from datetime import datetime
MAX_NUMBER = 10000000000000
MAX_DECIMAL = 4
@ -40,4 +41,9 @@ def loadMongoSetting():
return host, port
#----------------------------------------------------------------------
def todayDate():
"""获取当前本机电脑时间的日期"""
return datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)