[Mod]修改CTA策略引擎的委托函数,添加自动转换委托功能

This commit is contained in:
vn.py 2017-09-20 10:59:46 +08:00
parent 276c0e02fb
commit 92c446c5b7

View File

@ -91,6 +91,7 @@ class CtaEngine(object):
req = VtOrderReq() req = VtOrderReq()
req.symbol = contract.symbol req.symbol = contract.symbol
req.exchange = contract.exchange req.exchange = contract.exchange
req.vtSymbol = contract.vtSymbol
req.price = self.roundToPriceTick(contract.priceTick, price) req.price = self.roundToPriceTick(contract.priceTick, price)
req.volume = volume req.volume = volume
@ -116,14 +117,23 @@ class CtaEngine(object):
elif orderType == CTAORDER_COVER: elif orderType == CTAORDER_COVER:
req.direction = DIRECTION_LONG req.direction = DIRECTION_LONG
req.offset = OFFSET_CLOSE req.offset = OFFSET_CLOSE
# 委托转换
reqList = self.mainEngine.convertOrderReq(req)
orderIDList = []
vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName) # 发单 if not reqList:
self.orderStrategyDict[vtOrderID] = strategy # 保存vtOrderID和策略的映射关系 return orderIDList
for convertedReq in reqList:
vtOrderID = self.mainEngine.sendOrder(convertedReq, contract.gatewayName) # 发单
self.orderStrategyDict[vtOrderID] = strategy # 保存vtOrderID和策略的映射关系
orderIDList.append(vtOrderID)
self.writeCtaLog(u'策略%s发送委托,%s%s%s@%s' self.writeCtaLog(u'策略%s发送委托,%s%s%s@%s'
%(strategy.name, vtSymbol, req.direction, volume, price)) %(strategy.name, vtSymbol, req.direction, volume, price))
return vtOrderID return orderIDList
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def cancelOrder(self, vtOrderID): def cancelOrder(self, vtOrderID):