def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000) self.activeSymbolDict = {} # Tick对象字典 self.tickSymbolSet = set() # K线合成器字典 self.bgDict = {} # 配置字典 self.settingDict = OrderedDict() # 负责执行数据库插入的单独线程相关 self.active = False # 工作状态 self.queue = Queue() # 队列 self.thread = Thread(target=self.run) # 线程 # 载入设置,订阅行情 self.loadSetting() # 启动数据插入线程 self.start() # 注册事件监听 self.registerEvent()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000) self.activeSymbolDict = {} # Tick对象字典 self.tickSymbolSet = set() # K线合成器字典 self.bgDict = {} # 配置字典 self.settingDict = OrderedDict() self.WXuser=None self.WXcorpid=None self.WXcorpsecret=None self.WXaccesstoken=None # 载入设置,订阅行情 self.loadSetting() # 注册事件监听 self.registerEvent() self.sendWXdata ( self.WXaccesstoken, self.WXuser, "开始微信通知...", self.WXagentid )
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000) self.activeSymbolDict = {} # Tick对象字典 self.tickDict = {} # K线对象字典 self.barDict = {} # 配置字典 self.settingDict = OrderedDict() # 负责执行数据库插入的单独线程相关 self.active = False # 工作状态 self.queue = Queue() # 队列 self.thread = Thread(target=self.run) # 线程 # 载入设置,订阅行情 self.loadSetting() # 启动数据插入线程 self.start() # 注册事件监听 self.registerEvent()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000) self.activeSymbolDict = {} # Tick对象字典 self.tickSymbolSet = set() # K线合成器字典 self.bgDict = {} # 配置字典 self.settingDict = OrderedDict() self.WXuser = None self.WXcorpid = None self.WXcorpsecret = None self.WXaccesstoken = None # 载入设置,订阅行情 self.loadSetting() # 注册事件监听 self.registerEvent() self.sendWXdata(self.WXaccesstoken, self.WXuser, "开始微信通知...", self.WXagentid)
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000) self.activeSymbolDict = {} # Tick对象字典 self.tickDict = {} # K线对象字典 self.barDict = {} # Renko K线对象字典 self.renkoDict = {} # 负责执行数据库插入的单独线程相关 self.active = False # 工作状态 self.queue = Queue() # 队列 self.thread = Thread(target=self.run) # 线程 self.logger = None self.createLogger() # 载入设置,订阅行情 self.loadSetting()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 保存策略实例的字典 # key为策略名称,value为策略实例,注意策略名称不允许重复 self.strategyDict = {} # 保存策略设置的字典 # key为策略名称,value为策略设置,注意策略名称不允许重复 self.settingDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 持仓缓存字典 # key为vtSymbol,value为PositionBuffer对象 self.posBufferDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # tick缓存 self.tickDict = {} # 未能订阅的symbols self.pendingSubcribeSymbols = {} # 注册事件监听 self.registerEvent() self.logger = None self.createLogger()
def __init__(self, mainEngine, eventEngine, settingFileName='ARB_setting.json', onLine=False): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine #self.pool = multiprocessing.Pool(processes=4) self.onLineCompare = onLine path = os.path.abspath(os.path.dirname(__file__)) self.settingFileName = os.path.join(path, settingFileName) # 创建回测引擎 # 当前日期 self.today = todayDate() # 保存策略实例的字典 # key为策略名称,value为策略实例,注意策略名称不允许重复 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为symbol,value为position对象 self.posDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 持仓缓存字典 # key为vtSymbol,value为PositionBuffer对象 self.posBufferDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册事件监听 self.registerEvent()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 保存策略实例的字典 # key为策略名称,value为策略实例,注意策略名称不允许重复 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 保存策略名称和委托号列表的字典 # key为name,value为保存orderID(限价+本地停止)的集合 self.strategyOrderDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # RQData数据服务 self.rq = None # RQData能获取的合约代码列表 self.rqSymbolSet = set() # 初始化RQData服务 self.initRqData() # 注册日式事件类型 self.mainEngine.registerLogEvent(EVENT_CTA_LOG) # 注册事件监听 self.registerEvent()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine self.dbClient = sqlalchemy.create_engine( str(r"mssql+pymssql://sa:qwert!@#$%@10.3.135.33:1433/COMMODITY"), deprecate_large_types=True) # 当前日期 self.today = todayDate() self.rollingContract = [] # 有持仓换月list self.rollingFlag = [] # 无持仓换月 # 保存策略实例的字典 # key为策略名称,value为策略实例,注意策略名称不允许重复 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 保存策略名称和委托号列表的字典 # key为name,value为保存orderID(限价+本地停止)的集合 self.strategyOrderDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册日式事件类型 self.mainEngine.registerLogEvent(EVENT_CTA_LOG) #--------------------- self.posBufferDict = {} # 注册事件监听 self.registerEvent()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() self.minute_temp = 0 # 保存策略实例的字典 # key为策略名称,value为策略实例,注意策略名称不允许重复 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 保存策略名称和委托号列表的字典 # key为name,value为保存orderID(限价+本地停止)的集合 self.strategyOrderDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册日式事件类型 self.mainEngine.registerLogEvent(EVENT_CTA_LOG) # 注册事件监听 self.registerEvent() self.path = os.path.join(os.getcwd(), u"reports" ) if not os.path.isdir(self.path): os.makedirs(self.path) # 上期所昨持仓缓存 self.ydPositionDict = {}
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() self.symbol = "" ##策略折行的产品,比如 ru0000 rb0000 self.mainSymbol = "" ##主力合约 self.secSymbol = "" #次主力合约 self.account = None ##账户 self.capitalUseRat = 0.5 ##资金使用率 默认0.5 self.maxVolume = 50 ##每次开仓最大手数 self.riskRate = 0.02 #单笔风险敞口 # 保存策略实例的字典 # key为合约号+实例名,保证1个合约1个策略1个实例,value为策略实例 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 保存策略名称和委托号列表的字典 # key为symbol合约,value为保存orderID(限价+本地停止)的集合 self.strategyOrderDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册日式事件类型 #self.mainEngine.registerLogEvent(EVENT_ZZSD_LOG) # 注册事件监听 self.registerEvent()
def __init__(self, omEngine, eventEngine): """Constructor""" self.omEngine = omEngine self.mainEngine = omEngine.mainEngine self.eventEngine = eventEngine self.portfolio = None self.today = todayDate() self.strategyDict = {} # name: strategy self.symbolStrategyDict = {} # vtSymbol:strategy list self.orderStrategyDict = {} # vtOrderID: strategy self.registerEvent() print('Strategy Engine run')
def __init__(self, mainEngine, eventEngine): """Constructor""" print "%s.%s.%s" % (__name__, self.__class__.__name__, get_current_function_name()) self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 保存策略实例的字典 # key为策略名称,value为策略实例,注意策略名称不允许重复 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 # 持仓缓存字典 # key为vtSymbol,value为PositionBuffer对象 self.posBufferDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册事件监听 self.registerEvent()
def __init__(self, mainRoutine, eventChannel): """Constructor""" super(TraderAccount, self).__init__() self._mainRoutine = mainRoutine self._eventChannel = eventChannel # 当前日期 self.today = todayDate() # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册日式事件类型 self._mainRoutine.registerLogEvent(EVENT_LOG) # 注册事件监听 self.registerEvent()
def handleDayBar(self, bar): contact_ = bar.vtSymbol today = todayDate() todayStr = today.strftime("%Y%m%d") d = {'TradingDay': todayStr} barData = self.mainEngine.dbQuery(MINUTE_60_DB_NAME, contact_, d, 'TradingDay') day_bar = None for bar in barData: # 尚未创建对象 if not day_bar: day_bar = VtBarData() day_bar.vtSymbol = bar['vtSymbol'] day_bar.symbol = bar['symbol'] day_bar.exchange = bar['exchange'] day_bar.open = bar['open'] day_bar.high = bar['high'] day_bar.low = bar['low'] # 累加老K线 else: day_bar.high = max(day_bar.high, bar['high']) day_bar.low = min(day_bar.low, bar['low']) # 通用部分 day_bar.close = bar['close'] day_bar.datetime = bar['datetime'] day_bar.TradingDay = bar['TradingDay'] day_bar.openInterest = bar['openInterest'] day_bar.volume += int(bar['volume']) if day_bar: day_bar.datetime = datetime(today.year, today.month, today.day) day_bar.date = day_bar.datetime.strftime('%Y%m%d') day_bar.time = day_bar.datetime.strftime('%H:%M:%S.%f') self.mainEngine.dbInsert(DAY_DB_NAME, contact_, day_bar.__dict__)
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() # 主力合约代码映射字典,key为具体的合约代码(如IF1604),value为主力合约代码(如IF0000) self.activeSymbolDict = {} # Tick对象字典 self.tickSymbolSet = set() # K线合成器字典 self.bgDict = {} # 配置字典 self.settingDict = OrderedDict() # 负责执行数据库插入的单独线程相关 self.active = False # 工作状态 self.queue = Queue() # 队列 self.thread = Thread(target=self.run) # 线程 # 收盘相关 self.marketCloseTime = None # 收盘时间 self.timerCount = 0 # 定时器计数 self.lastTimerTime = None # 上一次记录时间 # 载入设置,订阅行情 self.loadSetting() # 启动数据插入线程 self.start() # 注册事件监听 self.registerEvent()
def __init__(self, mainEngine, eventEngine): """Constructor""" self.mainEngine = mainEngine self.eventEngine = eventEngine # 当前日期 self.today = todayDate() self.symbolList = [] ##策略折行的产品,比如 ru0000 rb0000 self.symbolInfoList = {} ##产品信息 包括maxVolume self.mainSymbolList = [] ##主力合约 self.account = None ##账户 self.capitalUseRat = 0.5 ##资金使用率 默认0.5 self.riskRate = 0.02 #单笔风险敞口 self.isUpperOrLowerLimit = {} # 保存策略实例的字典 # key为合约号+策略名,保证1个合约1个策略1个实例,value为策略实例 self.strategyDict = {} # 保存vtSymbol和策略实例映射的字典(用于推送tick数据) # 由于可能多个strategy交易同一个vtSymbol,因此key为vtSymbol # value为包含所有相关strategy对象的list self.tickStrategyDict = {} # 保存vtOrderID和strategy对象映射的字典(用于推送order和trade数据) # key为vtOrderID,value为strategy对象 self.orderStrategyDict = {} self.lastOpenTrade = {} ##最后一次开仓记录 key symbol self.traderDict = {} ##交易记录 key为vtOrderID # 本地停止单编号计数 self.stopOrderCount = 0 # stopOrderID = STOPORDERPREFIX + str(stopOrderCount) # 本地停止单字典 # key为stopOrderID,value为stopOrder对象 self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 ##用来记录停止单对应发送的委托 self.orderToStopOrder = {} ## key为order,交易id,value为stoporder # 保存策略名称和委托号列表的字典 # key为symbol合约+策略名,value为保存orderID(限价+本地停止)的集合 self.strategyOrderDict = {} # 成交号集合,用来过滤已经收到过的成交推送 self.tradeSet = set() # 引擎类型为实盘 self.engineType = ENGINETYPE_TRADING # 注册日式事件类型 #self.mainEngine.registerLogEvent(EVENT_ZZSD_LOG) # 注册事件监听 self.registerEvent()
def runOneSymbolDown(): runDown = DownServerData() day = todayDate() - timedelta(days=1) #day = todayDate() runDown.downloadOneSymbol('rb1805', day)
def runDataDown(): runDown = DownServerData() day = todayDate() - timedelta(days=1) runDown.downloadTickDataOneDay(day)