[Add]价差交易算法改为运行时禁止修改参数

This commit is contained in:
vn.py 2018-01-26 11:16:37 +08:00
parent c6bd7a6d1a
commit 915a4bfcb0
2 changed files with 92 additions and 23 deletions

View File

@ -288,6 +288,33 @@ class SniperAlgo(StAlgoTemplate):
if self.hedgeCount > self.hedgeInterval:
self.cancelAllPassiveLegOrders()
self.hedgeCount = 0
#----------------------------------------------------------------------
def checkPrice(self):
"""检查价格"""
# 做多检查
if self.mode != self.MODE_SHORTONLY:
if self.buyPrice >= self.sellPrice:
self.writeLog(u'启动失败允许多头交易时BuyPrice必须小于SellPrice')
return False
# 做空检查
if self.mode != self.MODE_LONGONLY:
if self.shortPrice <= self.coverPrice:
self.writeLog(u'启动失败允许空头交易时ShortPrice必须大于CoverPrice')
return False
# 多空检查
if self.mode == self.MODE_LONGSHORT:
if self.buyPrice >= self.coverPrice:
self.writeLog(u'启动失败允许双向交易时BuyPrice必须小于CoverPrice')
return False
if self.shortPrice <= self.sellPrice:
self.writeLog(u'启动失败允许双向交易时ShortPrice必须大于SellPrice')
return False
return True
#----------------------------------------------------------------------
def start(self):
@ -296,27 +323,9 @@ class SniperAlgo(StAlgoTemplate):
if self.active:
return self.active
# 做多检查
if self.mode != self.MODE_SHORTONLY:
if self.buyPrice >= self.sellPrice:
self.writeLog(u'启动失败允许多头交易时BuyPrice必须小于SellPrice')
return self.active
# 做空检查
if self.mode != self.MODE_LONGONLY:
if self.shortPrice <= self.coverPrice:
self.writeLog(u'启动失败允许空头交易时ShortPrice必须大于CoverPrice')
return self.active
# 多空检查
if self.mode == self.MODE_LONGSHORT:
if self.buyPrice >= self.coverPrice:
self.writeLog(u'启动失败允许双向交易时BuyPrice必须小于CoverPrice')
return self.active
if self.shortPrice <= self.sellPrice:
self.writeLog(u'启动失败允许双向交易时ShortPrice必须大于SellPrice')
return self.active
# 检查价格安全性
if not self.checkPrice():
return False
# 启动算法
self.quoteCount = 0

View File

@ -141,7 +141,16 @@ class StBuyPriceSpinBox(QtWidgets.QDoubleSpinBox):
def setPrice(self, value):
"""设置价格"""
self.algoEngine.setAlgoBuyPrice(self.spreadName, value)
#----------------------------------------------------------------------
def algoActiveChanged(self, active):
"""算法运行状态改变"""
# 只允许算法停止时修改运行模式
if active:
self.setEnabled(False)
else:
self.setEnabled(True)
########################################################################
class StSellPriceSpinBox(QtWidgets.QDoubleSpinBox):
@ -165,6 +174,15 @@ class StSellPriceSpinBox(QtWidgets.QDoubleSpinBox):
def setPrice(self, value):
"""设置价格"""
self.algoEngine.setAlgoSellPrice(self.spreadName, value)
#----------------------------------------------------------------------
def algoActiveChanged(self, active):
"""算法运行状态改变"""
# 只允许算法停止时修改运行模式
if active:
self.setEnabled(False)
else:
self.setEnabled(True)
########################################################################
@ -190,6 +208,15 @@ class StShortPriceSpinBox(QtWidgets.QDoubleSpinBox):
"""设置价格"""
self.algoEngine.setAlgoShortPrice(self.spreadName, value)
#----------------------------------------------------------------------
def algoActiveChanged(self, active):
"""算法运行状态改变"""
# 只允许算法停止时修改运行模式
if active:
self.setEnabled(False)
else:
self.setEnabled(True)
########################################################################
class StCoverPriceSpinBox(QtWidgets.QDoubleSpinBox):
@ -214,6 +241,15 @@ class StCoverPriceSpinBox(QtWidgets.QDoubleSpinBox):
"""设置价格"""
self.algoEngine.setAlgoCoverPrice(self.spreadName, value)
#----------------------------------------------------------------------
def algoActiveChanged(self, active):
"""算法运行状态改变"""
# 只允许算法停止时修改运行模式
if active:
self.setEnabled(False)
else:
self.setEnabled(True)
########################################################################
class StMaxPosSizeSpinBox(QtWidgets.QSpinBox):
@ -237,7 +273,16 @@ class StMaxPosSizeSpinBox(QtWidgets.QSpinBox):
"""设置价格"""
self.algoEngine.setAlgoMaxPosSize(self.spreadName, size)
#----------------------------------------------------------------------
def algoActiveChanged(self, active):
"""算法运行状态改变"""
# 只允许算法停止时修改运行模式
if active:
self.setEnabled(False)
else:
self.setEnabled(True)
########################################################################
class StMaxOrderSizeSpinBox(QtWidgets.QSpinBox):
""""""
@ -260,6 +305,15 @@ class StMaxOrderSizeSpinBox(QtWidgets.QSpinBox):
"""设置价格"""
self.algoEngine.setAlgoMaxOrderSize(self.spreadName, size)
#----------------------------------------------------------------------
def algoActiveChanged(self, active):
"""算法运行状态改变"""
# 只允许算法停止时修改运行模式
if active:
self.setEnabled(False)
else:
self.setEnabled(True)
########################################################################
class StModeComboBox(QtWidgets.QComboBox):
@ -422,6 +476,12 @@ class StAlgoManager(QtWidgets.QTableWidget):
self.setCellWidget(row, 8, comboMode)
self.setCellWidget(row, 9, buttonActive)
buttonActive.signalActive.connect(spinBuyPrice.algoActiveChanged)
buttonActive.signalActive.connect(spinSellPrice.algoActiveChanged)
buttonActive.signalActive.connect(spinShortPrice.algoActiveChanged)
buttonActive.signalActive.connect(spinCoverPrice.algoActiveChanged)
buttonActive.signalActive.connect(spinMaxOrderSize.algoActiveChanged)
buttonActive.signalActive.connect(spinMaxPosSize.algoActiveChanged)
buttonActive.signalActive.connect(comboMode.algoActiveChanged)
self.buttonActiveDict[d['spreadName']] = buttonActive