[Mod]BarManager改名为BarGenerator,close #607
This commit is contained in:
parent
1abb73c7ab
commit
527d4bf779
@ -16,8 +16,7 @@ from vnpy.trader.uiQt import createQApp
|
|||||||
from vnpy.trader.uiMainWindow import MainWindow
|
from vnpy.trader.uiMainWindow import MainWindow
|
||||||
|
|
||||||
# 加载底层接口
|
# 加载底层接口
|
||||||
from vnpy.trader.gateway import (ctpGateway, oandaGateway, ibGateway,
|
from vnpy.trader.gateway import (ctpGateway, oandaGateway, ibGateway)
|
||||||
tkproGateway)
|
|
||||||
|
|
||||||
if system == 'Windows':
|
if system == 'Windows':
|
||||||
from vnpy.trader.gateway import (femasGateway, xspeedGateway,
|
from vnpy.trader.gateway import (femasGateway, xspeedGateway,
|
||||||
@ -44,7 +43,6 @@ def main():
|
|||||||
|
|
||||||
# 添加交易接口
|
# 添加交易接口
|
||||||
me.addGateway(ctpGateway)
|
me.addGateway(ctpGateway)
|
||||||
me.addGateway(tkproGateway)
|
|
||||||
me.addGateway(oandaGateway)
|
me.addGateway(oandaGateway)
|
||||||
me.addGateway(ibGateway)
|
me.addGateway(ibGateway)
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ class TargetPosTemplate(CtaTemplate):
|
|||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class BarManager(object):
|
class BarGenerator(object):
|
||||||
"""
|
"""
|
||||||
K线合成器,支持:
|
K线合成器,支持:
|
||||||
1. 基于Tick合成1分钟K线
|
1. 基于Tick合成1分钟K线
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
from vnpy.trader.vtObject import VtBarData
|
from vnpy.trader.vtObject import VtBarData
|
||||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
||||||
BarManager,
|
BarGenerator,
|
||||||
ArrayManager)
|
ArrayManager)
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ class AtrRsiStrategy(CtaTemplate):
|
|||||||
super(AtrRsiStrategy, self).__init__(ctaEngine, setting)
|
super(AtrRsiStrategy, self).__init__(ctaEngine, setting)
|
||||||
|
|
||||||
# 创建K线合成器对象
|
# 创建K线合成器对象
|
||||||
self.bm = BarManager(self.onBar)
|
self.bg = BarGenerator(self.onBar)
|
||||||
self.am = ArrayManager()
|
self.am = ArrayManager()
|
||||||
|
|
||||||
# 注意策略类中的可变对象属性(通常是list和dict等),在策略初始化时需要重新创建,
|
# 注意策略类中的可变对象属性(通常是list和dict等),在策略初始化时需要重新创建,
|
||||||
@ -112,7 +112,7 @@ class AtrRsiStrategy(CtaTemplate):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onTick(self, tick):
|
def onTick(self, tick):
|
||||||
"""收到行情TICK推送(必须由用户继承实现)"""
|
"""收到行情TICK推送(必须由用户继承实现)"""
|
||||||
self.bm.updateTick(tick)
|
self.bg.updateTick(tick)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onBar(self, bar):
|
def onBar(self, bar):
|
||||||
|
@ -21,7 +21,7 @@ from __future__ import division
|
|||||||
from vnpy.trader.vtObject import VtBarData
|
from vnpy.trader.vtObject import VtBarData
|
||||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
||||||
BarManager,
|
BarGenerator,
|
||||||
ArrayManager)
|
ArrayManager)
|
||||||
|
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ class BollChannelStrategy(CtaTemplate):
|
|||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(BollChannelStrategy, self).__init__(ctaEngine, setting)
|
super(BollChannelStrategy, self).__init__(ctaEngine, setting)
|
||||||
|
|
||||||
self.bm = BarManager(self.onBar, 15, self.onXminBar) # 创建K线合成器对象
|
self.bg = BarGenerator(self.onBar, 15, self.onXminBar) # 创建K线合成器对象
|
||||||
self.bm30 = BarManager(self.onBar, 30, self.on30minBar)
|
self.bg30 = BarGenerator(self.onBar, 30, self.on30minBar)
|
||||||
self.am = ArrayManager()
|
self.am = ArrayManager()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -123,12 +123,12 @@ class BollChannelStrategy(CtaTemplate):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onTick(self, tick):
|
def onTick(self, tick):
|
||||||
"""收到行情TICK推送(必须由用户继承实现)"""
|
"""收到行情TICK推送(必须由用户继承实现)"""
|
||||||
self.bm.updateTick(tick)
|
self.bg.updateTick(tick)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onBar(self, bar):
|
def onBar(self, bar):
|
||||||
"""收到Bar推送(必须由用户继承实现)"""
|
"""收到Bar推送(必须由用户继承实现)"""
|
||||||
self.bm.updateBar(bar)
|
self.bg.updateBar(bar)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onXminBar(self, bar):
|
def onXminBar(self, bar):
|
||||||
|
@ -15,7 +15,7 @@ from __future__ import division
|
|||||||
|
|
||||||
from vnpy.trader.vtConstant import EMPTY_STRING, EMPTY_FLOAT
|
from vnpy.trader.vtConstant import EMPTY_STRING, EMPTY_FLOAT
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
||||||
BarManager,
|
BarGenerator,
|
||||||
ArrayManager)
|
ArrayManager)
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class DoubleMaStrategy(CtaTemplate):
|
|||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(DoubleMaStrategy, self).__init__(ctaEngine, setting)
|
super(DoubleMaStrategy, self).__init__(ctaEngine, setting)
|
||||||
|
|
||||||
self.bm = BarManager(self.onBar)
|
self.bg = BarGenerator(self.onBar)
|
||||||
self.am = ArrayManager()
|
self.am = ArrayManager()
|
||||||
|
|
||||||
# 注意策略类中的可变对象属性(通常是list和dict等),在策略初始化时需要重新创建,
|
# 注意策略类中的可变对象属性(通常是list和dict等),在策略初始化时需要重新创建,
|
||||||
@ -96,7 +96,7 @@ class DoubleMaStrategy(CtaTemplate):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onTick(self, tick):
|
def onTick(self, tick):
|
||||||
"""收到行情TICK推送(必须由用户继承实现)"""
|
"""收到行情TICK推送(必须由用户继承实现)"""
|
||||||
self.bm.updateTick(tick)
|
self.bg.updateTick(tick)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onBar(self, bar):
|
def onBar(self, bar):
|
||||||
|
@ -8,7 +8,7 @@ from datetime import time
|
|||||||
|
|
||||||
from vnpy.trader.vtObject import VtBarData
|
from vnpy.trader.vtObject import VtBarData
|
||||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import CtaTemplate, BarManager
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import CtaTemplate, BarGenerator
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -64,7 +64,7 @@ class DualThrustStrategy(CtaTemplate):
|
|||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(DualThrustStrategy, self).__init__(ctaEngine, setting)
|
super(DualThrustStrategy, self).__init__(ctaEngine, setting)
|
||||||
|
|
||||||
self.bm = BarManager(self.onBar)
|
self.bg = BarGenerator(self.onBar)
|
||||||
self.barList = []
|
self.barList = []
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -94,7 +94,7 @@ class DualThrustStrategy(CtaTemplate):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onTick(self, tick):
|
def onTick(self, tick):
|
||||||
"""收到行情TICK推送(必须由用户继承实现)"""
|
"""收到行情TICK推送(必须由用户继承实现)"""
|
||||||
self.bm.updateTick(tick)
|
self.bg.updateTick(tick)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onBar(self, bar):
|
def onBar(self, bar):
|
||||||
|
@ -15,7 +15,7 @@ from __future__ import division
|
|||||||
from vnpy.trader.vtObject import VtBarData
|
from vnpy.trader.vtObject import VtBarData
|
||||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
||||||
BarManager,
|
BarGenerator,
|
||||||
ArrayManager)
|
ArrayManager)
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class KkStrategy(CtaTemplate):
|
|||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
super(KkStrategy, self).__init__(ctaEngine, setting)
|
super(KkStrategy, self).__init__(ctaEngine, setting)
|
||||||
|
|
||||||
self.bm = BarManager(self.onBar, 5, self.onFiveBar) # 创建K线合成器对象
|
self.bg = BarGenerator(self.onBar, 5, self.onFiveBar) # 创建K线合成器对象
|
||||||
self.am = ArrayManager()
|
self.am = ArrayManager()
|
||||||
|
|
||||||
self.buyOrderIDList = []
|
self.buyOrderIDList = []
|
||||||
@ -101,12 +101,12 @@ class KkStrategy(CtaTemplate):
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onTick(self, tick):
|
def onTick(self, tick):
|
||||||
"""收到行情TICK推送(必须由用户继承实现)"""
|
"""收到行情TICK推送(必须由用户继承实现)"""
|
||||||
self.bm.updateTick(tick)
|
self.bg.updateTick(tick)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onBar(self, bar):
|
def onBar(self, bar):
|
||||||
"""收到Bar推送(必须由用户继承实现)"""
|
"""收到Bar推送(必须由用户继承实现)"""
|
||||||
self.bm.updateBar(bar)
|
self.bg.updateBar(bar)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onFiveBar(self, bar):
|
def onFiveBar(self, bar):
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
from vnpy.trader.vtObject import VtBarData
|
from vnpy.trader.vtObject import VtBarData
|
||||||
from vnpy.trader.vtConstant import EMPTY_STRING
|
from vnpy.trader.vtConstant import EMPTY_STRING
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import (CtaTemplate,
|
||||||
BarManager,
|
BarGenerator,
|
||||||
ArrayManager)
|
ArrayManager)
|
||||||
|
|
||||||
|
|
||||||
@ -67,10 +67,10 @@ class MultiTimeframeStrategy(CtaTemplate):
|
|||||||
self.rsiShort = 50 - self.rsiSignal
|
self.rsiShort = 50 - self.rsiSignal
|
||||||
|
|
||||||
# 创建K线合成器对象
|
# 创建K线合成器对象
|
||||||
self.bm5 = BarManager(self.onBar, 5, self.on5MinBar)
|
self.bg5 = BarGenerator(self.onBar, 5, self.on5MinBar)
|
||||||
self.am5 = ArrayManager()
|
self.am5 = ArrayManager()
|
||||||
|
|
||||||
self.bm15 = BarManager(self.onBar, 15, self.on15MinBar)
|
self.bg15 = BarGenerator(self.onBar, 15, self.on15MinBar)
|
||||||
self.am15 = ArrayManager()
|
self.am15 = ArrayManager()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
@ -101,16 +101,16 @@ class MultiTimeframeStrategy(CtaTemplate):
|
|||||||
def onTick(self, tick):
|
def onTick(self, tick):
|
||||||
"""收到行情TICK推送(必须由用户继承实现)"""
|
"""收到行情TICK推送(必须由用户继承实现)"""
|
||||||
# 只需要要在一个BM中合成1分钟K线
|
# 只需要要在一个BM中合成1分钟K线
|
||||||
self.bm5.updateTick(tick)
|
self.bg5.updateTick(tick)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onBar(self, bar):
|
def onBar(self, bar):
|
||||||
"""收到Bar推送(必须由用户继承实现)"""
|
"""收到Bar推送(必须由用户继承实现)"""
|
||||||
# 基于15分钟判断趋势过滤,因此先更新
|
# 基于15分钟判断趋势过滤,因此先更新
|
||||||
self.bm15.updateBar(bar)
|
self.bg15.updateBar(bar)
|
||||||
|
|
||||||
# 基于5分钟判断
|
# 基于5分钟判断
|
||||||
self.bm5.updateBar(bar)
|
self.bg5.updateBar(bar)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def on5MinBar(self, bar):
|
def on5MinBar(self, bar):
|
||||||
|
@ -19,7 +19,7 @@ from vnpy.event import Event
|
|||||||
from vnpy.trader.vtEvent import *
|
from vnpy.trader.vtEvent import *
|
||||||
from vnpy.trader.vtFunction import todayDate, getJsonPath
|
from vnpy.trader.vtFunction import todayDate, getJsonPath
|
||||||
from vnpy.trader.vtObject import VtSubscribeReq, VtLogData, VtBarData, VtTickData
|
from vnpy.trader.vtObject import VtSubscribeReq, VtLogData, VtBarData, VtTickData
|
||||||
from vnpy.trader.app.ctaStrategy.ctaTemplate import BarManager
|
from vnpy.trader.app.ctaStrategy.ctaTemplate import BarGenerator
|
||||||
|
|
||||||
from .drBase import *
|
from .drBase import *
|
||||||
from .language import text
|
from .language import text
|
||||||
@ -48,7 +48,7 @@ class DrEngine(object):
|
|||||||
self.tickSymbolSet = set()
|
self.tickSymbolSet = set()
|
||||||
|
|
||||||
# K线合成器字典
|
# K线合成器字典
|
||||||
self.bmDict = {}
|
self.bgDict = {}
|
||||||
|
|
||||||
# 配置字典
|
# 配置字典
|
||||||
self.settingDict = OrderedDict()
|
self.settingDict = OrderedDict()
|
||||||
@ -153,7 +153,7 @@ class DrEngine(object):
|
|||||||
d['bar'] = True
|
d['bar'] = True
|
||||||
|
|
||||||
# 创建BarManager对象
|
# 创建BarManager对象
|
||||||
self.bmDict[vtSymbol] = BarManager(self.onBar)
|
self.bgDict[vtSymbol] = BarGenerator(self.onBar)
|
||||||
|
|
||||||
# 主力合约记录配置
|
# 主力合约记录配置
|
||||||
if 'active' in drSetting:
|
if 'active' in drSetting:
|
||||||
@ -177,7 +177,7 @@ class DrEngine(object):
|
|||||||
|
|
||||||
self.onTick(tick)
|
self.onTick(tick)
|
||||||
|
|
||||||
bm = self.bmDict.get(vtSymbol, None)
|
bm = self.bgDict.get(vtSymbol, None)
|
||||||
if bm:
|
if bm:
|
||||||
bm.updateTick(tick)
|
bm.updateTick(tick)
|
||||||
|
|
||||||
|
@ -7,4 +7,4 @@ appName = 'RtdService'
|
|||||||
appDisplayName = u'RTD服务'
|
appDisplayName = u'RTD服务'
|
||||||
appEngine = RtdEngine
|
appEngine = RtdEngine
|
||||||
appWidget = RtdManager
|
appWidget = RtdManager
|
||||||
appIco = 'rtd.ico'
|
appIco = 'rtd.ico'
|
Loading…
Reference in New Issue
Block a user