def testEmitOrder(self): handlersData = [] def handler3(): handlersData.append(3) def handler1(): handlersData.append(1) def handler2(): handlersData.append(2) event = observer.Event() event.subscribe(handler1) event.subscribe(handler2) event.subscribe(handler3) event.emit() self.assertTrue(handlersData == [1, 2, 3]) handlersData = [] event = observer.Event() event.subscribe(handler3) event.subscribe(handler2) event.subscribe(handler1) event.emit() self.assertTrue(handlersData == [3, 2, 1])
def __init__(self, consumerKey, consumerSecret, accessToken, accessTokenSecret, track=[], follow=[], languages=[]): assert isinstance(track, list), "track must be a list" assert isinstance(follow, list), "follow must be a list" assert isinstance(languages, list), "languages must be a list" super(TwitterFeed, self).__init__() self.__event = observer.Event() self.__queue = Queue.Queue() self.__thread = None self.__running = False listener = Listener(self.__queue) auth = tweepy.OAuthHandler(consumerKey, consumerSecret) auth.set_access_token(accessToken, accessTokenSecret) self.__stream = tweepy.Stream(auth, listener) self.__track = track self.__follow = follow self.__languages = languages
def __init__(self, maxLen=None): super(SequenceDataSeries, self).__init__() maxLen = get_checked_max_len(maxLen) self.__newValueEvent = observer.Event() self.__values = collections.ListDeque(maxLen) self.__dateTimes = collections.ListDeque(maxLen)
def __init__(self, maxLen): super(BaseFeed, self).__init__() maxLen = dataseries.get_checked_max_len(maxLen) self.__ds = {} self.__event = observer.Event() self.__maxLen = maxLen
def testDuplicateHandlers(self): def handler1(): handlersData.append(1) handlersData = [] event = observer.Event() event.subscribe(handler1) event.subscribe(handler1) event.emit() self.assertTrue(handlersData == [1])
def __init__(self, maxLen=None): super(LiveTradeFeed, self).__init__(bar.Frequency.TRADE, maxLen) self.__barDicts = [] self.registerInstrument(common.btc_symbol) self.__prevTradeDateTime = None self.__thread = None self.__initializationOk = None self.__enableReconnection = True self.__stopped = False self.__orderBookUpdateEvent = observer.Event()
def __init__(self, barFeed, broker): self.__barFeed = barFeed self.__broker = broker self.__activePositions = set() self.__orderToPosition = {} self.__barsProcessedEvent = observer.Event() self.__analyzers = [] self.__namedAnalyzers = {} self.__resampledBarFeeds = [] self.__dispatcher = dispatcher.Dispatcher() self.__broker.getOrderUpdatedEvent().subscribe(self.__onOrderEvent) self.__barFeed.getNewValuesEvent().subscribe(self.__onBars) self.__dispatcher.getStartEvent().subscribe(self.onStart) self.__dispatcher.getIdleEvent().subscribe(self.__onIdle) # It is important to dispatch broker events before feed events, specially if we're backtesting. self.__dispatcher.addSubject(self.__broker) self.__dispatcher.addSubject(self.__barFeed) # Initialize logging. self.__logger = logger.getLogger(BaseStrategy.LOGGER_NAME)
def testReentrancy(self): handlersData = [] event = observer.Event() def handler2(): handlersData.append(2) def handler1(): handlersData.append(1) event.subscribe(handler2) event.subscribe(handler1) event.subscribe(handler1) event.emit() self.assertTrue(handlersData == [1]) event.emit() self.assertTrue(handlersData == [1, 1, 2]) event.unsubscribe(handler1) event.emit() self.assertTrue(handlersData == [1, 1, 2, 2]) event.unsubscribe(handler2) event.emit() self.assertTrue(handlersData == [1, 1, 2, 2])
def __init__(self, datetimes, priority=None): super(RealtimeFeed, self).__init__() self.__datetimes = datetimes self.__event = observer.Event() self.__priority = priority
def __init__(self): self.__subjects = [] self.__stop = False self.__startEvent = observer.Event() self.__idleEvent = observer.Event() self.__currDateTime = None
def __init__(self): super(ReturnsAnalyzerBase, self).__init__() self.__event = observer.Event() self.__portfolioReturns = None
def __init__(self): super(Broker, self).__init__() self.__orderEvent = observer.Event()