From b9e89657d9da34f9911a697bf6192cbc514970cb Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Wed, 3 Aug 2016 21:54:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CTA=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E7=AD=96=E7=95=A5=E5=AF=B9=E4=BA=8E=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83=E7=9A=84=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctaAlgo/ctaBacktesting.py | 3 +++ vn.trader/ctaAlgo/ctaBase.py | 3 +++ vn.trader/ctaAlgo/ctaEngine.py | 3 +++ vn.trader/ctaAlgo/ctaTemplate.py | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/vn.trader/ctaAlgo/ctaBacktesting.py b/vn.trader/ctaAlgo/ctaBacktesting.py index 61295317..d82b6636 100644 --- a/vn.trader/ctaAlgo/ctaBacktesting.py +++ b/vn.trader/ctaAlgo/ctaBacktesting.py @@ -42,6 +42,9 @@ class BacktestingEngine(object): self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 + # 引擎类型为回测 + self.engineType = ENGINETYPE_BACKTESTING + # 回测相关 self.strategy = None # 回测策略 self.mode = self.BAR_MODE # 回测模式,默认为K线 diff --git a/vn.trader/ctaAlgo/ctaBase.py b/vn.trader/ctaAlgo/ctaBase.py index f0fffbca..8060b6a3 100644 --- a/vn.trader/ctaAlgo/ctaBase.py +++ b/vn.trader/ctaAlgo/ctaBase.py @@ -33,6 +33,9 @@ TICK_DB_NAME = 'VnTrader_Tick_Db' DAILY_DB_NAME = 'VnTrader_Daily_Db' MINUTE_DB_NAME = 'VnTrader_1Min_Db' +# 引擎类型,用于区分当前策略的运行环境 +ENGINETYPE_BACKTESTING = 'backtesting' # 回测 +ENGINETYPE_TRADING = 'trading' # 实盘 # CTA引擎中涉及的数据类定义 from vtConstant import EMPTY_UNICODE, EMPTY_STRING, EMPTY_FLOAT, EMPTY_INT diff --git a/vn.trader/ctaAlgo/ctaEngine.py b/vn.trader/ctaAlgo/ctaEngine.py index e4649580..17f2c020 100644 --- a/vn.trader/ctaAlgo/ctaEngine.py +++ b/vn.trader/ctaAlgo/ctaEngine.py @@ -70,6 +70,9 @@ class CtaEngine(object): # key为vtSymbol,value为PositionBuffer对象 self.posBufferDict = {} + # 引擎类型为实盘 + self.engineType = ENGINETYPE_TRADING + # 注册事件监听 self.registerEvent() diff --git a/vn.trader/ctaAlgo/ctaTemplate.py b/vn.trader/ctaAlgo/ctaTemplate.py index e98a6f83..2e4f57d4 100644 --- a/vn.trader/ctaAlgo/ctaTemplate.py +++ b/vn.trader/ctaAlgo/ctaTemplate.py @@ -165,4 +165,9 @@ class CtaTemplate(object): def putEvent(self): """发出策略状态变化事件""" self.ctaEngine.putStrategyEvent(self.name) + + #---------------------------------------------------------------------- + def getEngineType(self): + """查询当前运行的环境""" + return self.ctaEngine.engineType