GitHub - maxbbraun/trump2cash: A stock trading bot powered by Trump tweets Skip to content Sign up Why GitHub? Features → Mobile → Actions → Codespaces → Packages → Security → Code review → Project management → Integrations → GitHub Sponsors → Customer stories → Security → Team Enterprise Explore Explore GitHub → Learn & contribute Topics → Collections → Trending → Learning Lab → Open source guides → Connect with others The ReadME Project → Events → Community forum → GitHub Education → GitHub Stars program → Marketplace Pricing Plans → Compare plans → Contact Sales → Nonprofit → Education → In this repository All GitHub ↵ Jump to ↵ No suggested jump to results In this repository All GitHub ↵ Jump to ↵ In this user All GitHub ↵ Jump to ↵ In this repository All GitHub ↵ Jump to ↵ Sign in Sign up {{ message }} maxbbraun / trump2cash Watch 290 Star 5.9k Fork 836 A stock trading bot powered by Trump tweets trump2cash.biz MIT License 5.9k stars 836 forks Star Watch Code Issues 24 Pull requests 7 Actions Projects 0 Security Insights More Code Issues Pull requests Actions Projects Security Insights master 2 branches 0 tags Go to file Code Clone HTTPS GitHub CLI Use Git or checkout with SVN using the web URL. Work fast with our official CLI. Learn more. Open with GitHub Desktop Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio If nothing happens, download the GitHub extension for Visual Studio and try again. Go back Latest commit maxbbraun Downgrade google-cloud-logging version … 1d6642f Feb 6, 2021 Downgrade google-cloud-logging version ERROR: google-cloud-error-reporting 1.1.0 has requirement google-cloud-logging<2.1,>=1.14.0, but you'll have google-cloud-logging 2.2.0 which is incompatible. 1d6642f Git stats 197 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .gitignore Ignore Visual Studio Code settings Sep 22, 2018 Dockerfile Migrate to Python 3 Feb 10, 2019 LICENSE Add MIT license Jun 4, 2020 README.md Remove shell symbol for easier copying Feb 7, 2021 analysis.py Use single quote style consistently Feb 7, 2021 analysis_tests.py Use single quote style consistently Feb 7, 2021 benchmark.md Remove shell symbol for easier copying Feb 7, 2021 benchmark.py Remove shell symbol for easier copying Feb 7, 2021 logs.py Use single quote style consistently Feb 7, 2021 logs_tests.py Use single quote style consistently Feb 7, 2021 main.py Use single quote style consistently Feb 7, 2021 requirements.txt Downgrade google-cloud-logging version Feb 7, 2021 trading.py Use single quote style consistently Feb 7, 2021 trading_tests.py Use single quote style consistently Feb 7, 2021 twitter.py Use single quote style consistently Feb 7, 2021 twitter_tests.py Use single quote style consistently Feb 7, 2021 View code README.md Trump2Cash This bot watches Donald Trump's tweets and waits for him to mention any publicly traded companies. When he does, it uses sentiment analysis to determine whether his opinions are positive or negative toward those companies. The bot then automatically executes trades on the relevant stocks according to the expected market reaction. It also tweets out a summary of its findings in real time at @Trump2Cash. You can read more about the background story here. The code is written in Python and is meant to run on a Google Compute Engine instance. It uses the Twitter Streaming APIs to get notified whenever Trump tweets. The entity detection and sentiment analysis is done using Google's Cloud Natural Language API and the Wikidata Query Service provides the company data. The TradeKing API does the stock trading. The main module defines a callback where incoming tweets are handled and starts streaming Trump's feed: def twitter_callback(tweet): companies = analysis.find_companies(tweet) if companies: trading.make_trades(companies) twitter.tweet(companies, tweet) if __name__ == '__main__': twitter.start_streaming(twitter_callback) The core algorithms are implemented in the analysis and trading modules. The former finds mentions of companies in the text of the tweet, figures out what their ticker symbol is, and assigns a sentiment score to them. The latter chooses a trading strategy, which is either buy now and sell at close or sell short now and buy to cover at close. The twitter module deals with streaming and tweeting out the summary. Follow these steps to run the code yourself: 1. Create VM instance Check out the quickstart to create a Cloud Platform project and a Linux VM instance with Compute Engine, then SSH into it for the steps below. Pick a predefined machine type matching your preferred price and performance. Container Alternatively, you can use the Dockerfile to build a Docker container and run it on Compute Engine or other platforms. docker build -t trump2cash . docker tag trump2cash gcr.io//trump2cash docker push gcr.io//trump2cash:latest 2. Set up auth The authentication keys for the different APIs are read from shell environment variables. Each service has different steps to obtain them. Twitter Log in to your Twitter account and create a new application. Under the Keys and Access Tokens tab for your app you'll find the Consumer Key and Consumer Secret. Export both to environment variables: export TWITTER_CONSUMER_KEY="" export TWITTER_CONSUMER_SECRET="" If you want the tweets to come from the same account that owns the application, simply use the Access Token and Access Token Secret on the same page. If you want to tweet from a different account, follow the steps to obtain an access token. Then export both to environment variables: export TWITTER_ACCESS_TOKEN="" export TWITTER_ACCESS_TOKEN_SECRET="" Google Follow the Google Application Default Credentials instructions to create, download, and export a service account key. export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials-file.json" You also need to enable the Cloud Natural Language API for your Google Cloud Platform project. TradeKing Log in to your TradeKing account and create a new application. Behind the Details button for your application you'll find the Consumer Key, Consumer Secret, OAuth (Access) Token, and Oauth (Access) Token Secret. Export them all to environment variables: export TRADEKING_CONSUMER_KEY="" export TRADEKING_CONSUMER_SECRET="" export TRADEKING_ACCESS_TOKEN="" export TRADEKING_ACCESS_TOKEN_SECRET="" Also export your TradeKing account number, which you'll find under My Accounts: export TRADEKING_ACCOUNT_NUMBER="" 3. Install dependencies There are a few library dependencies, which you can install using pip: pip install -r requirements.txt 4. Run the tests Verify that everything is working as intended by running the tests with pytest using this command: export USE_REAL_MONEY=NO && pytest *.py -vv 5. Run the benchmark The benchmark report shows how the current implementation of the analysis and trading algorithms would have performed against historical data. You can run it again to benchmark any changes you may have made. You'll need a Polygon account: export POLYGON_API_KEY="" python benchmark.py > benchmark.md 6. Start the bot Enable real orders that use your money: export USE_REAL_MONEY=YES Have the code start running in the background with this command: nohup python main.py & About A stock trading bot powered by Trump tweets trump2cash.biz Topics bot trump twitter trading Resources Readme License MIT License Releases No releases published Packages 0 No packages published Languages Python 99.8% Dockerfile 0.2% © 2021 GitHub, Inc. Terms Privacy Security Status Docs Contact GitHub Pricing API Training Blog About You can’t perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.