From 6798a2234fe3f91db138d5923d008d17e4fd01e7 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 8 Feb 2018 12:35:28 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E4=BF=AE=E6=94=B9WebTrader=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8E=A8=E9=80=81=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/WebTrader/run.py | 6 +++++- vnpy/trader/app/ctaStrategy/ctaEngine.py | 7 ++++++- vnpy/trader/app/ctaStrategy/ctaTemplate.py | 2 +- .../trader/app/ctaStrategy/strategy/strategyMultiSignal.py | 7 +++++++ .../app/ctaStrategy/strategy/strategyMultiTimeframe.py | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/WebTrader/run.py b/examples/WebTrader/run.py index ed582095..9d6e7ff5 100644 --- a/examples/WebTrader/run.py +++ b/examples/WebTrader/run.py @@ -596,7 +596,11 @@ api.add_resource(CtaStrategyVar, '/ctastrategy/var') def handleEvent(event): """处理事件""" eventType = event.type_ - eventData = event.dict_['data'].__dict__ + eventData = event.dict_['data'] + + if not isinstance(eventData, dict): + eventData = eventData.__dict__ + socketio.emit(eventType, eventData) #print eventData diff --git a/vnpy/trader/app/ctaStrategy/ctaEngine.py b/vnpy/trader/app/ctaStrategy/ctaEngine.py index 7c1e4584..6802b313 100644 --- a/vnpy/trader/app/ctaStrategy/ctaEngine.py +++ b/vnpy/trader/app/ctaStrategy/ctaEngine.py @@ -266,6 +266,9 @@ class CtaEngine(object): def processTickEvent(self, event): """处理行情推送""" tick = event.dict_['data'] + + tick = copy(tick) + # 收到tick行情后,先处理本地停止单(检查是否要立即发出) self.processStopOrder(tick) @@ -571,8 +574,10 @@ class CtaEngine(object): event.dict_['data'] = d self.eventEngine.put(event) + d2 = {k:str(v) for k,v in d.items()} + d2['name'] = name event2 = Event(EVENT_CTA_STRATEGY) - event2.dict_['data'] = d + event2.dict_['data'] = d2 self.eventEngine.put(event2) #---------------------------------------------------------------------- diff --git a/vnpy/trader/app/ctaStrategy/ctaTemplate.py b/vnpy/trader/app/ctaStrategy/ctaTemplate.py index ef1acea2..9efdde8e 100644 --- a/vnpy/trader/app/ctaStrategy/ctaTemplate.py +++ b/vnpy/trader/app/ctaStrategy/ctaTemplate.py @@ -340,7 +340,7 @@ class BarGenerator(object): """ K线合成器,支持: 1. 基于Tick合成1分钟K线 - 2. 基于1分钟K线合成X分钟K线(X可以是2、3、5、10、15、30、60) + 2. 基于1分钟K线合成X分钟K线(X可以是2、3、5、10、15、30 ) """ #---------------------------------------------------------------------- diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyMultiSignal.py b/vnpy/trader/app/ctaStrategy/strategy/strategyMultiSignal.py index 1e062ff7..40786655 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyMultiSignal.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyMultiSignal.py @@ -216,6 +216,8 @@ class MultiSignalStrategy(TargetPosTemplate): self.cciSignal.onTick(tick) self.maSignal.onTick(tick) + self.calculateTargetPos() + #---------------------------------------------------------------------- def onBar(self, bar): """收到Bar推送(必须由用户继承实现)""" @@ -225,6 +227,11 @@ class MultiSignalStrategy(TargetPosTemplate): self.cciSignal.onBar(bar) self.maSignal.onBar(bar) + self.calculateTargetPos() + + #---------------------------------------------------------------------- + def calculateTargetPos(self): + """计算目标仓位""" self.signalPos['rsi'] = self.rsiSignal.getSignalPos() self.signalPos['cci'] = self.cciSignal.getSignalPos() self.signalPos['ma'] = self.maSignal.getSignalPos() diff --git a/vnpy/trader/app/ctaStrategy/strategy/strategyMultiTimeframe.py b/vnpy/trader/app/ctaStrategy/strategy/strategyMultiTimeframe.py index d81f7684..5d9127f0 100644 --- a/vnpy/trader/app/ctaStrategy/strategy/strategyMultiTimeframe.py +++ b/vnpy/trader/app/ctaStrategy/strategy/strategyMultiTimeframe.py @@ -100,7 +100,7 @@ class MultiTimeframeStrategy(CtaTemplate): #---------------------------------------------------------------------- def onTick(self, tick): """收到行情TICK推送(必须由用户继承实现)""" - # 只需要要在一个BM中合成1分钟K线 + # 只需要要在一个BarGenerator中合成1分钟K线 self.bg5.updateTick(tick) #----------------------------------------------------------------------