[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

@ -289,6 +289,33 @@ class SniperAlgo(StAlgoTemplate):
self.cancelAllPassiveLegOrders() self.cancelAllPassiveLegOrders()
self.hedgeCount = 0 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): def start(self):
"""启动""" """启动"""
@ -296,27 +323,9 @@ class SniperAlgo(StAlgoTemplate):
if self.active: if self.active:
return self.active return self.active
# 做多检查 # 检查价格安全性
if self.mode != self.MODE_SHORTONLY: if not self.checkPrice():
if self.buyPrice >= self.sellPrice: return False
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
# 启动算法 # 启动算法
self.quoteCount = 0 self.quoteCount = 0

View File

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