Ejemplo n.º 1
0
    def testTwitterFeed(self):
        events = {"on_tweet": False, "start": datetime.datetime.now()}
        disp = dispatcher.Dispatcher()

        def on_tweet(data):
            events["on_tweet"] = True
            disp.stop()

        def on_idle():
            # Stop after 5 minutes.
            if (datetime.datetime.now() - events["start"]).seconds > 60 * 5:
                disp.stop()

        # Create a twitter feed to track BitCoin related events.
        consumer_key = os.getenv("TWITTER_CONSUMER_KEY")
        consumer_secret = os.getenv("TWITTER_CONSUMER_SECRET")
        access_token = os.getenv("TWITTER_ACCESS_TOKEN")
        access_token_secret = os.getenv("TWITTER_ACCESS_TOKEN_SECRET")
        track = ["bitcoin", "btc"]
        follow = []
        languages = ["en"]
        twitterFeed = twitterfeed.TwitterFeed(consumer_key, consumer_secret,
                                              access_token,
                                              access_token_secret, track,
                                              follow, languages)

        disp.addSubject(twitterFeed)
        twitterFeed.subscribe(on_tweet)
        disp.getIdleEvent().subscribe(on_idle)
        disp.run()

        # Check that we received both events.
        self.assertTrue(events["on_tweet"])
Ejemplo n.º 2
0
def main():
    # Go to http://dev.twitter.com and create an app.
    # The consumer key and secret will be generated for you after that.
    consumer_key="gIRVUzcuPWdWo4pbAfaRqt0xM"
    consumer_secret="1xJj33TrSQsKBt6Szh9PJz4AORvpwB69QWs4Ry8joRpu71a5tO"

    # After the step above, you will be redirected to your app's page.
    # Create an access token under the the "Your access token" section
    access_token="2164180933-9VW0NbvTzeQ6hw7CdQYwVe1Sy4J6JYfpTdMxSAf"
    access_token_secret="MXrstxWpW9fduwp4KaYr0L2fO79hbgVyiLaQlhQ9cwU3V"

    # Create a twitter feed to track BitCoin related events.
    track = ["bitcoin", "btc", "mtgox"]
    follow = []
    languages = ["en"]
    twitterFeed = twitterfeed.TwitterFeed(consumer_key, consumer_secret, access_token, access_token_secret, track, follow, languages)

    # Create a client responsible for all the interaction with MtGox
    mtgoxClient = client.Client("USD", None, None)
    mtgoxClient.setEnableReconnection(False)

    # Create a real-time feed that will build bars from live trades.
    feed = barfeed.LiveTradeFeed(mtgoxClient)

    # Create a backtesting broker.
    brk = broker.BacktestingBroker(200, feed)

    # Run the strategy with the feed and the broker.
    strat = Strategy("BTC", feed, brk, mtgoxClient, twitterFeed)
    strat.run()
Ejemplo n.º 3
0
def main():
    # Go to http://dev.twitter.com and create an app.
    # The consumer key and secret will be generated for you after that.
    consumer_key = "<YOUR-CONSUMER-KEY-HERE>"
    consumer_secret = "<YOUR-CONSUMER-SECRET-HERE>"

    # After the step above, you will be redirected to your app's page.
    # Create an access token under the the "Your access token" section
    access_token = "<YOUR-ACCESS-TOKEN-HERE>"
    access_token_secret = "<YOUR-ACCESS-TOKEN-SECRET-HERE>"

    # Create a twitter feed to track BitCoin related events.
    track = ["bitcoin", "btc", "mtgox", "bitstamp", "xapo"]
    follow = []
    languages = ["en"]
    twitterFeed = twitterfeed.TwitterFeed(consumer_key, consumer_secret,
                                          access_token, access_token_secret,
                                          track, follow, languages)

    cli = client.Client()
    barFeed = barfeed.LiveTradeFeed(cli)
    brk = broker.PaperTradingBroker(1000, barFeed)
    strat = Strategy(cli, barFeed, brk, twitterFeed)

    # It is VERY important to add these to the event dispatch loop before running the strategy.
    strat.getDispatcher().addSubject(cli)
    strat.getDispatcher().addSubject(twitterFeed)

    strat.run()
Ejemplo n.º 4
0
def main():
    # Go to http://dev.twitter.com and create an app.
    # The consumer key and secret will be generated for you after that.
    consumer_key = "<YOUR-CONSUMER-KEY-HERE>"
    consumer_secret = "<YOUR-CONSUMER-SECRET-HERE>"

    # After the step above, you will be redirected to your app's page.
    # Create an access token under the the "Your access token" section
    access_token = "<YOUR-ACCESS-TOKEN-HERE>"
    access_token_secret = "<YOUR-ACCESS-TOKEN-SECRET-HERE>"

    # Create a twitter feed to track BitCoin related events.
    track = ["bitcoin", "btc", "mtgox"]
    follow = []
    languages = ["en"]
    twitterFeed = twitterfeed.TwitterFeed(consumer_key, consumer_secret,
                                          access_token, access_token_secret,
                                          track, follow, languages)

    # Create a client responsible for all the interaction with MtGox
    mtgoxClient = client.Client("USD", None, None)
    mtgoxClient.setEnableReconnection(False)

    # Create a real-time feed that will build bars from live trades.
    feed = barfeed.LiveTradeFeed(mtgoxClient)

    # Create a backtesting broker.
    brk = broker.BacktestingBroker(200, feed)

    # Run the strategy with the feed and the broker.
    strat = Strategy("BTC", feed, brk, mtgoxClient, twitterFeed)
    strat.run()