Ejemplo 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])
Ejemplo n.º 2
0
    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
Ejemplo 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)
Ejemplo n.º 4
0
    def __init__(self, maxLen):
        super(BaseFeed, self).__init__()

        maxLen = dataseries.get_checked_max_len(maxLen)

        self.__ds = {}
        self.__event = observer.Event()
        self.__maxLen = maxLen
Ejemplo n.º 5
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])
Ejemplo n.º 6
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.__initializationOk = None
     self.__enableReconnection = True
     self.__stopped = False
     self.__orderBookUpdateEvent = observer.Event()
Ejemplo 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)

        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)
Ejemplo 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])
Ejemplo n.º 9
0
 def __init__(self, datetimes, priority=None):
     super(RealtimeFeed, self).__init__()
     self.__datetimes = datetimes
     self.__event = observer.Event()
     self.__priority = priority
Ejemplo n.º 10
0
 def __init__(self):
     self.__subjects = []
     self.__stop = False
     self.__startEvent = observer.Event()
     self.__idleEvent = observer.Event()
     self.__currDateTime = None
Ejemplo n.º 11
0
 def __init__(self):
     super(ReturnsAnalyzerBase, self).__init__()
     self.__event = observer.Event()
     self.__portfolioReturns = None
Ejemplo n.º 12
0
 def __init__(self):
     super(Broker, self).__init__()
     self.__orderEvent = observer.Event()