[Add]价差交易算法改为运行时禁止修改参数
This commit is contained in:
parent
c6bd7a6d1a
commit
915a4bfcb0
@ -289,6 +289,33 @@ class SniperAlgo(StAlgoTemplate):
|
||||
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
|
||||
|
@ -142,6 +142,15 @@ class StBuyPriceSpinBox(QtWidgets.QDoubleSpinBox):
|
||||
"""设置价格"""
|
||||
self.algoEngine.setAlgoBuyPrice(self.spreadName, value)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def algoActiveChanged(self, active):
|
||||
"""算法运行状态改变"""
|
||||
# 只允许算法停止时修改运行模式
|
||||
if active:
|
||||
self.setEnabled(False)
|
||||
else:
|
||||
self.setEnabled(True)
|
||||
|
||||
|
||||
########################################################################
|
||||
class StSellPriceSpinBox(QtWidgets.QDoubleSpinBox):
|
||||
@ -166,6 +175,15 @@ class StSellPriceSpinBox(QtWidgets.QDoubleSpinBox):
|
||||
"""设置价格"""
|
||||
self.algoEngine.setAlgoSellPrice(self.spreadName, value)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def algoActiveChanged(self, active):
|
||||
"""算法运行状态改变"""
|
||||
# 只允许算法停止时修改运行模式
|
||||
if active:
|
||||
self.setEnabled(False)
|
||||
else:
|
||||
self.setEnabled(True)
|
||||
|
||||
|
||||
########################################################################
|
||||
class StShortPriceSpinBox(QtWidgets.QDoubleSpinBox):
|
||||
@ -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,6 +273,15 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user