From 05a58c24ba9dfbe238ae5e60a414bcf96430d3d6 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 2 Dec 2017 22:38:12 +0800 Subject: [PATCH] [Fix]Close #603 #619 --- vnpy/trader/app/ctaStrategy/strategy/strategyAtrRsi.py | 10 +++++++++- .../app/ctaStrategy/strategy/strategyBollChannel.py | 8 ++++++++ .../app/ctaStrategy/strategy/strategyDoubleMa.py | 3 +++ .../app/ctaStrategy/strategy/strategyDualThrust.py | 5 ++++- .../app/ctaStrategy/strategy/strategyKingKeltner.py | 10 +++++++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyAtrRsi.py b/vnpy/trader/app/ctaStrategy/strategy/strategyAtrRsi.py index cca7fcbf..9060c850 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyAtrRsi.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyAtrRsi.py @@ -61,6 +61,11 @@ class AtrRsiStrategy(CtaTemplate): 'rsiValue', 'rsiBuy', 'rsiSell'] + + # 同步列表,保存了需要保存到数据库的变量名称 + syncList = ['pos', + 'intraTradeHigh', + 'intraTradeLow'] #---------------------------------------------------------------------- def __init__(self, ctaEngine, setting): @@ -154,7 +159,7 @@ class AtrRsiStrategy(CtaTemplate): # 计算多头移动止损 longStop = self.intraTradeHigh * (1-self.trailingPercent/100) - # 发出本地止损委托,并且把委托号记录下来,用于后续撤单 + # 发出本地止损委托 self.sell(longStop, abs(self.pos), stop=True) # 持有空头仓位 @@ -165,6 +170,9 @@ class AtrRsiStrategy(CtaTemplate): shortStop = self.intraTradeLow * (1+self.trailingPercent/100) self.cover(shortStop, abs(self.pos), stop=True) + # 同步数据到数据库 + self.saveSyncData() + # 发出状态更新事件 self.putEvent() diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyBollChannel.py b/vnpy/trader/app/ctaStrategy/strategy/strategyBollChannel.py index 73305599..5f60b99d 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyBollChannel.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyBollChannel.py @@ -76,6 +76,11 @@ class BollChannelStrategy(CtaTemplate): 'intraTradeLow', 'longStop', 'shortStop'] + + # 同步列表,保存了需要保存到数据库的变量名称 + syncList = ['pos', + 'intraTradeHigh', + 'intraTradeLow'] #---------------------------------------------------------------------- def __init__(self, ctaEngine, setting): @@ -172,6 +177,9 @@ class BollChannelStrategy(CtaTemplate): self.shortStop = self.intraTradeLow + self.atrValue * self.slMultiplier self.cover(self.shortStop, abs(self.pos), True) + + # 同步数据到数据库 + self.saveSyncData() # 发出状态更新事件 self.putEvent() diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyDoubleMa.py b/vnpy/trader/app/ctaStrategy/strategy/strategyDoubleMa.py index 7b9b9ff3..e1080629 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyDoubleMa.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyDoubleMa.py @@ -53,6 +53,9 @@ class DoubleMaStrategy(CtaTemplate): 'fastMa1', 'slowMa0', 'slowMa1'] + + # 同步列表,保存了需要保存到数据库的变量名称 + syncList = ['pos'] #---------------------------------------------------------------------- def __init__(self, ctaEngine, setting): diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyDualThrust.py b/vnpy/trader/app/ctaStrategy/strategy/strategyDualThrust.py index e3809a0f..9dec0c6f 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyDualThrust.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyDualThrust.py @@ -54,7 +54,10 @@ class DualThrustStrategy(CtaTemplate): 'range', 'longEntry', 'shortEntry', - 'exitTime'] + 'exitTime'] + + # 同步列表,保存了需要保存到数据库的变量名称 + syncList = ['pos'] #---------------------------------------------------------------------- def __init__(self, ctaEngine, setting): diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyKingKeltner.py b/vnpy/trader/app/ctaStrategy/strategy/strategyKingKeltner.py index 702b5e3c..3e1ed71b 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyKingKeltner.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyKingKeltner.py @@ -55,7 +55,12 @@ class KkStrategy(CtaTemplate): 'trading', 'pos', 'kkUp', - 'kkDown'] + 'kkDown'] + + # 同步列表,保存了需要保存到数据库的变量名称 + syncList = ['pos', + 'intraTradeHigh', + 'intraTradeLow'] #---------------------------------------------------------------------- def __init__(self, ctaEngine, setting): @@ -146,6 +151,9 @@ class KkStrategy(CtaTemplate): abs(self.pos), True) self.orderList.extend(l) + # 同步数据到数据库 + self.saveSyncData() + # 发出状态更新事件 self.putEvent()