Esempio n. 1
0
    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])
Esempio n. 2
0
    def __init__(self,
                 consumerKey: str,
                 consumerSecret: str,
                 accessToken: str,
                 accessTokenSecret,
                 track: list = None,
                 follow: list = None,
                 languages: list = None):
        track = track or []
        follow = follow or []
        languages = languages or []
        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
Esempio n. 3
0
    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)
Esempio n. 4
0
    def testDuplicateHandlers(self):
        def handler1():
            handlersData.append(1)

        handlersData = []
        event = observer.Event()
        event.subscribe(handler1)
        event.subscribe(handler1)
        event.emit()
        self.assertTrue(handlersData == [1])
Esempio n. 5
0
 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.__wsClientConnected = False
     self.__enableReconnection = True
     self.__stopped = False
     self.__orderBookUpdateEvent = observer.Event()
Esempio n. 6
0
    def testUnsuscribeAndResuscribeWhileEmiting(self):
        handlersData = []
        event = observer.Event()

        def handler1():
            handlersData.append(1)
            event.unsubscribe(handler1)
            event.subscribe(handler1)

        event.subscribe(handler1)
        event.emit()
        self.assertTrue(handlersData == [1])

        event.emit()
        self.assertTrue(handlersData == [1, 1])
Esempio n. 7
0
    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)

        # onStart will be called once all subjects are started.
        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)
Esempio n. 8
0
    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])
Esempio n. 9
0
 def __init__(self):
     super(ReturnsAnalyzerBase, self).__init__()
     self.__event = observer.Event()
     self.__portfolioReturns = None
Esempio n. 10
0
    def __init__(self, maxLen):
        super(BaseFeed, self).__init__()

        self.__ds = {}
        self.__event = observer.Event()
        self.__maxLen = dataseries.get_checked_max_len(maxLen)
Esempio n. 11
0
 def __init__(self, datetimes, priority=None):
     super(RealtimeFeed, self).__init__()
     self.__datetimes = datetimes
     self.__event = observer.Event()
     self.__priority = priority
Esempio n. 12
0
 def __init__(self):
     super(Broker, self).__init__()
     self.__orderEvent = observer.Event()
Esempio n. 13
0
 def __init__(self):
     self.__subjects = []
     self.__stop = False
     self.__startEvent = observer.Event()
     self.__idleEvent = observer.Event()
     self.__currDateTime = None