def testSafeMin(self): self.assertEqual(utils.safe_min(None, 0), 0) self.assertEqual(utils.safe_min(0, None), 0) self.assertEqual(utils.safe_min(None, None), None) self.assertEqual(utils.safe_min(0, 0), 0) self.assertEqual(utils.safe_min(1, 0), 0) self.assertEqual(utils.safe_min(0, 1), 0) self.assertEqual(utils.safe_min(-1, 1), -1) self.assertEqual(utils.safe_min(1, -1), -1) self.assertEqual(utils.safe_min(-1, -2), -2) self.assertEqual(utils.safe_min(-2, -1), -2)
def peekDateTime(self): ret = None for instrument, bars in self.__bars.items(): nextPos = self.__nextPos[instrument] if nextPos < len(bars): ret = utils.safe_min(ret, bars[nextPos].getDateTime()) return ret
def __dispatch(self): smallestDateTime = None eof = True eventsDispatched = False # Scan for the lowest datetime. for subject in self.__subjects: if not subject.eof(): eof = False smallestDateTime = utils.safe_min(smallestDateTime, subject.peekDateTime()) elif os.getenv('PYALGOTRADE_NEVER_STOP'): logger.info('Subject %s is reaching eof...', subject) logger.info(('Dispatcher is killing main process ' 'since PYALGOTRADE_NEVER_STOP is set')) os.kill(os.getpid(), signal.SIGTERM) # Dispatch realtime subjects and those subjects with the lowest datetime. if not eof: self.__currDateTime = smallestDateTime for subject in self.__subjects: if self.__dispatchSubject(subject, smallestDateTime): eventsDispatched = True return eof, eventsDispatched
def peekDateTime(self): ret = None for instrument, bars in self.__bars.iteritems(): nextPos = self.__nextPos[instrument] if nextPos < len(bars): ret = utils.safe_min(ret, bars[nextPos].getDateTime()) return ret
def peekDateTime(self): ret = None for instrument, bars in self.__bars.iteritems(): nextIdx = self.__nextBarIdx[instrument] if nextIdx < len(bars): ret = utils.safe_min(ret, bars[nextIdx].getDateTime()) return ret
def peekDateTime(self): ret = None for instrument, ticks in six.iteritems(self.__ticks): nextPos = self.__nextPos[instrument] if nextPos < len(ticks): ret = utils.safe_min(ret, ticks[nextPos].getDateTime()) return ret
def mindate(index,_nextPos,bars,insts,div): start = div[index][0] end = div[index][1] ret = None for i in range(start,end): ins = insts[i] nextPos = _nextPos[ins] if nextPos < len(bars[ins]): ret = utils.safe_min(ret, bars[ins][nextPos].getDateTime()) return ret
def __dispatch(self): smallestDateTime = None eof = True eventsDispatched = False # Scan for the lowest datetime. for subject in self.__subjects: if not subject.eof(): eof = False smallestDateTime = utils.safe_min(smallestDateTime, subject.peekDateTime()) # Dispatch realtime subjects and those subjects with the lowest datetime. if not eof: for subject in self.__subjects: if self.__dispatchSubject(subject, smallestDateTime): eventsDispatched = True return eof, eventsDispatched
def peekDateTime(self): if len(self.__div) == 0: ret = None for instrument, bars in self.__bars.iteritems(): nextPos = self.__nextPos[instrument] if nextPos < len(bars): ret = utils.safe_min(ret, bars[nextPos].getDateTime()) else: ret = [] if len(self.__div) == 1: ret.append(mindate(0,self.__nextPos,self.__bars,self.__insts,self.__div)) else: ret = self.__pl.handleCombineRet(mindate,self.__nextPos,self.__bars,self.__insts,self.__div) ret = min(ret, key=lambda x:uutils.TimeUtils.dt2stamp(x) if x is not None else sys.maxint) return ret
def __dispatch(self): smallestDateTime = None eof = True eventsDispatched = False # Scan for the lowest datetime. for subject in self.__subjects: if not subject.eof(): eof = False smallestDateTime = utils.safe_min(smallestDateTime, subject.peekDateTime()) # Dispatch realtime subjects and those subjects with the lowest datetime. if not eof: self.__currDateTime = smallestDateTime for subject in self.__subjects: if self.__dispatchSubject(subject, smallestDateTime): eventsDispatched = True return eof, eventsDispatched
def __dispatch(self): smallestDateTime = None # eof = True eventsDispatched = False # Scan for the lowest datetime. for subject in self.__subjects: if not subject.eof(): eof = False smallestDateTime = utils.safe_min(smallestDateTime, subject.peekDateTime()) #一次只返回多个事件源中最老的事件,这是为了保证处理的顺序没有问题。比如过2分钟采取查看,有两个事件源有事件,一个发生在第1分钟,一个1分半 #那么会先取第一分钟发生的事件吐出去 # Dispatch realtime subjects and those subjects with the lowest datetime. if not eof: self.__currDateTime = smallestDateTime for subject in self.__subjects: if self.__dispatchSubject(subject, smallestDateTime): eventsDispatched = True return eof, eventsDispatched