修改策略显示模块,增加“强行初始化”。

This commit is contained in:
msincenselee 2016-08-04 15:13:40 +08:00
parent 00701b0f5e
commit 414e319529
2 changed files with 42 additions and 4 deletions

View File

@ -177,6 +177,33 @@ class CtaEngine(object):
else:
self.writeCtaLog(u'委托单({0}不存在'.format(vtOrderID))
# ----------------------------------------------------------------------
def cancelOrders(self, symbol, offset=EMPTY_STRING):
"""撤销所有单"""
# Symbol参数:指定合约的撤单;
# OFFSET参数:指定Offset的撤单,缺省不填写时,为所有
l = self.mainEngine.getAllWorkingOrders()
self.writeCtaLog(u'撤销所有订单,数量:{0}'.format(len(l)))
for order in l:
if offset == EMPTY_STRING:
offsetCond = True
else:
offsetCond = order.offset == offset
if order.symbol == symbol and offsetCond:
req = VtCancelOrderReq()
req.symbol = order.symbol
req.exchange = order.exchange
req.frontID = order.frontID
req.sessionID = order.sessionID
req.orderID = order.orderID
self.writeCtaLog(u'撤单:{0}/{1},{2}{3}'
.format(order.symbol, order.orderID, order.offset, order.totalVolume-order.tradedVolume))
self.mainEngine.cancelOrder(req, order.gatewayName)
# ----------------------------------------------------------------------
def sendStopOrder(self, vtSymbol, orderType, price, volume, strategy):
"""发停止单(本地实现)"""
@ -302,6 +329,8 @@ class CtaEngine(object):
# 1.获取事件的Order数据
order = event.dict_['data']
# order.vtOrderID 在gateway中已经格式化为 gatewayName.vtOrderID
# 2.判断order是否在映射字典中
if order.vtOrderID in self.orderStrategyDict:
# 3.提取对应的策略
@ -478,13 +507,13 @@ class CtaEngine(object):
self.writeCtaLog(u'%s的交易合约%s无法找到' %(name, strategy.vtSymbol))
#----------------------------------------------------------------------
def initStrategy(self, name):
def initStrategy(self, name, force = False):
"""初始化策略"""
if name in self.strategyDict:
strategy = self.strategyDict[name]
if not strategy.inited:
strategy.onInit()
if not strategy.inited or force == True:
strategy.onInit(force=force)
strategy.inited = True
else:
self.writeCtaLog(u'请勿重复初始化策略实例:%s' %name)

View File

@ -88,14 +88,18 @@ class CtaStrategyManager(QtGui.QGroupBox):
buttonInit = QtGui.QPushButton(u'初始化')
buttonStart = QtGui.QPushButton(u'启动')
buttonStop = QtGui.QPushButton(u'停止')
buttonInitForce = QtGui.QPushButton(u'强制初始化')
buttonInit.clicked.connect(self.init)
buttonStart.clicked.connect(self.start)
buttonStop.clicked.connect(self.stop)
buttonInitForce.clicked.connect(self.initForce)
hbox1 = QtGui.QHBoxLayout()
hbox1.addWidget(buttonInit)
hbox1.addWidget(buttonStart)
hbox1.addWidget(buttonStop)
hbox1.addWidget(buttonInitForce)
hbox1.addStretch()
hbox2 = QtGui.QHBoxLayout()
@ -132,7 +136,12 @@ class CtaStrategyManager(QtGui.QGroupBox):
def init(self):
"""初始化策略"""
self.ctaEngine.initStrategy(self.name)
def initForce(self):
"""强制初始化策略"""
self.ctaEngine.initStrategy(self.name,force = True)
#----------------------------------------------------------------------
def start(self):
"""启动策略"""