修改部分功能

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编译文件 # Python编译文件
*.pyc *.pyc
*.pyd
# WingIDE文件 # WingIDE文件
*.wpr *.wpr

View File

@ -14,6 +14,7 @@ from ctaSetting import STRATEGY_CLASS
from eventEngine import * from eventEngine import *
from vtConstant import * from vtConstant import *
from vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData from vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData
from vtFunction import todayDate
######################################################################## ########################################################################
@ -29,7 +30,7 @@ class CtaEngine(object):
self.eventEngine = eventEngine self.eventEngine = eventEngine
# 当前日期 # 当前日期
self.today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) self.today = todayDate()
# 保存策略实例的字典 # 保存策略实例的字典
# key为策略名称value为策略实例注意策略名称不允许重复 # key为策略名称value为策略实例注意策略名称不允许重复
@ -429,5 +430,7 @@ class CtaEngine(object):
"""触发策略状态变化事件通常用于通知GUI更新""" """触发策略状态变化事件通常用于通知GUI更新"""
event = Event(EVENT_CTA_STRATEGY+name) event = Event(EVENT_CTA_STRATEGY+name)
self.eventEngine.put(event) self.eventEngine.put(event)

View File

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

View File

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

View File

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