Skip to content

Commit

Permalink
修改部分功能
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxy123 committed May 5, 2016
1 parent f755611 commit 8b57222
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Release/

# Python编译文件
*.pyc
*.pyd

# WingIDE文件
*.wpr
Expand Down
5 changes: 4 additions & 1 deletion vn.trader/ctaAlgo/ctaEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from eventEngine import *
from vtConstant import *
from vtGateway import VtSubscribeReq, VtOrderReq, VtCancelOrderReq, VtLogData
from vtFunction import todayDate


########################################################################
Expand All @@ -29,7 +30,7 @@ def __init__(self, mainEngine, eventEngine):
self.eventEngine = eventEngine

# 当前日期
self.today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
self.today = todayDate()

# 保存策略实例的字典
# key为策略名称,value为策略实例,注意策略名称不允许重复
Expand Down Expand Up @@ -429,5 +430,7 @@ def putStrategyEvent(self, name):
"""触发策略状态变化事件(通常用于通知GUI更新)"""
event = Event(EVENT_CTA_STRATEGY+name)
self.eventEngine.put(event)




3 changes: 2 additions & 1 deletion vn.trader/dataRecorder/drEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from eventEngine import *
from vtGateway import VtSubscribeReq, VtLogData
from drBase import *
from vtFunction import todayDate


########################################################################
Expand All @@ -31,7 +32,7 @@ def __init__(self, mainEngine, eventEngine):
self.eventEngine = eventEngine

# 当前日期
self.today = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
self.today = todayDate()

# 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000)
self.activeSymbolDict = {}
Expand Down
22 changes: 8 additions & 14 deletions vn.trader/ibGateway/ibGateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
productClassMap[PRODUCT_FUTURES] = 'FUT'
productClassMap[PRODUCT_OPTION] = 'OPT'
productClassMap[PRODUCT_FOREX] = 'CASH'
productClassMapReverse = {v:k for k,v in productClassMap.items()}

# 期权类型映射
optionTypeMap = {}
Expand Down Expand Up @@ -184,6 +185,7 @@ def subscribe(self, subscribeReq):
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()
Expand Down Expand Up @@ -469,30 +471,22 @@ def contractDetails(self, reqId, contractDetails):
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):
Expand Down
6 changes: 6 additions & 0 deletions vn.trader/vtFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import decimal
import json
from datetime import datetime

MAX_NUMBER = 10000000000000
MAX_DECIMAL = 4
Expand Down Expand Up @@ -40,4 +41,9 @@ def loadMongoSetting():

return host, port

#----------------------------------------------------------------------
def todayDate():
"""获取当前本机电脑时间的日期"""
return datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)


0 comments on commit 8b57222

Please sign in to comment.