{"id":13440178,"url":"https://github.com/maxbbraun/trump2cash","last_synced_at":"2025-09-27T07:31:01.621Z","repository":{"id":42136445,"uuid":"79692191","full_name":"maxbbraun/trump2cash","owner":"maxbbraun","description":"A stock trading bot powered by Trump tweets","archived":true,"fork":false,"pushed_at":"2023-05-23T00:51:23.000Z","size":645,"stargazers_count":6271,"open_issues_count":36,"forks_count":858,"subscribers_count":286,"default_branch":"master","last_synced_at":"2024-09-26T22:01:58.550Z","etag":null,"topics":["bot","trading","trump","twitter"],"latest_commit_sha":null,"homepage":"https://trump2cash.biz","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxbbraun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-01-22T03:54:56.000Z","updated_at":"2024-09-26T02:44:12.000Z","dependencies_parsed_at":"2022-08-12T07:31:18.712Z","dependency_job_id":"996bcf94-65ed-4f0e-ac70-7772fdf53902","html_url":"https://github.com/maxbbraun/trump2cash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbbraun%2Ftrump2cash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbbraun%2Ftrump2cash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbbraun%2Ftrump2cash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbbraun%2Ftrump2cash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxbbraun","download_url":"https://codeload.github.com/maxbbraun/trump2cash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234410006,"owners_count":18828117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","trading","trump","twitter"],"created_at":"2024-07-31T03:01:20.449Z","updated_at":"2025-09-27T07:31:01.298Z","avatar_url":"https://github.com/maxbbraun.png","language":"Python","funding_links":[],"categories":["Python","Strategies \u0026 Research","Politics","Blog Articles, Papers, Case Studies","Fun"],"sub_categories":["Event Drive","AI","Sentiment Analysis","RFID"],"readme":"# Trump2Cash\n\nThis bot watches [Donald Trump's tweets](https://twitter.com/realDonaldTrump)\nand waits for him to mention any publicly traded companies. When he does, it\nuses sentiment analysis to determine whether his opinions are positive or\nnegative toward those companies. The bot then automatically executes trades on\nthe relevant stocks according to the expected market reaction. It also tweets\nout a summary of its findings in real time at\n[@Trump2Cash](https://twitter.com/Trump2Cash).\n\n*You can read more about the background story [here](https://trump2cash.biz).*\n\n[![Trump2Cash](https://cdn-images-1.medium.com/max/1400/1*VbnhlLnZz0KvWO0QsM5Ihw.png)](https://trump2cash.biz)\n\nThe code is written in Python and is meant to run on a\n[Google Compute Engine](https://cloud.google.com/compute/) instance. It uses the\n[Twitter Streaming APIs](https://dev.twitter.com/streaming/overview) to get\nnotified whenever Trump tweets. The entity detection and sentiment analysis is\ndone using Google's\n[Cloud Natural Language API](https://cloud.google.com/natural-language/) and the\n[Wikidata Query Service](https://query.wikidata.org/) provides the company data.\nThe [TradeKing API](https://developers.tradeking.com/) does the stock trading.\n\nThe [`main`](main.py) module defines a callback where incoming tweets are\nhandled and starts streaming Trump's feed:\n\n```python\ndef twitter_callback(tweet):\n    companies = analysis.find_companies(tweet)\n    if companies:\n        trading.make_trades(companies)\n        twitter.tweet(companies, tweet)\n\nif __name__ == '__main__':\n    twitter.start_streaming(twitter_callback)\n```\n\nThe core algorithms are implemented in the [`analysis`](analysis.py) and\n[`trading`](trading.py) modules. The former finds mentions of companies in the\ntext of the tweet, figures out what their ticker symbol is, and assigns a\nsentiment score to them. The latter chooses a trading strategy, which is either\nbuy now and sell at close or sell short now and buy to cover at close. The\n[`twitter`](twitter.py) module deals with streaming and tweeting out the\nsummary.\n\nFollow these steps to run the code yourself:\n\n### 1. Create VM instance\n\nCheck out the [quickstart](https://cloud.google.com/compute/docs/quickstart-linux)\nto create a Cloud Platform project and a Linux VM instance with Compute Engine,\nthen SSH into it for the steps below. Pick a predefined\n[machine type](https://cloud.google.com/compute/docs/machine-types) matching\nyour preferred price and performance.\n\n#### Container\n\nAlternatively, you can use the [`Dockerfile`](Dockerfile) to build a\n[Docker container](https://www.docker.com/what-container) and\n[run it on Compute Engine](https://cloud.google.com/compute/docs/containers/deploying-containers)\nor other platforms.\n\n```shell\ndocker build -t trump2cash .\ndocker tag trump2cash gcr.io/\u003cYOUR_GCP_PROJECT_NAME\u003e/trump2cash\ndocker push gcr.io/\u003cYOUR_GCP_PROJECT_NAME\u003e/trump2cash:latest\n```\n\n### 2. Set up auth\n\nThe authentication keys for the different APIs are read from shell environment\nvariables. Each service has different steps to obtain them.\n\n#### Twitter\n\nLog in to your [Twitter](https://twitter.com/) account and\n[create a new application](https://apps.twitter.com/app/new). Under the *Keys\nand Access Tokens* tab for [your app](https://apps.twitter.com/) you'll find\nthe *Consumer Key* and *Consumer Secret*. Export both to environment variables:\n\n```shell\nexport TWITTER_CONSUMER_KEY=\"\u003cYOUR_CONSUMER_KEY\u003e\"\nexport TWITTER_CONSUMER_SECRET=\"\u003cYOUR_CONSUMER_SECRET\u003e\"\n```\n\nIf you want the tweets to come from the same account that owns the application,\nsimply use the *Access Token* and *Access Token Secret* on the same page. If\nyou want to tweet from a different account, follow the\n[steps to obtain an access token](https://dev.twitter.com/oauth/overview). Then\nexport both to environment variables:\n\n```shell\nexport TWITTER_ACCESS_TOKEN=\"\u003cYOUR_ACCESS_TOKEN\u003e\"\nexport TWITTER_ACCESS_TOKEN_SECRET=\"\u003cYOUR_ACCESS_TOKEN_SECRET\u003e\"\n```\n\n#### Google\n\nFollow the\n[Google Application Default Credentials instructions](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork)\nto create, download, and export a service account key.\n\n```shell\nexport GOOGLE_APPLICATION_CREDENTIALS=\"/path/to/credentials-file.json\"\n```\n\nYou also need to [enable the Cloud Natural Language API](https://cloud.google.com/natural-language/docs/getting-started#set_up_your_project)\nfor your Google Cloud Platform project.\n\n#### TradeKing\n\nLog in to your [TradeKing](https://www.tradeking.com/) account and\n[create a new application](https://developers.tradeking.com/applications/CreateApplication).\nBehind the *Details* button for\n[your application](https://developers.tradeking.com/Applications) you'll find\nthe *Consumer Key*, *Consumer Secret*, *OAuth (Access) Token*, and *Oauth (Access)\nToken Secret*. Export them all to environment variables:\n\n```shell\nexport TRADEKING_CONSUMER_KEY=\"\u003cYOUR_CONSUMER_KEY\u003e\"\nexport TRADEKING_CONSUMER_SECRET=\"\u003cYOUR_CONSUMER_SECRET\u003e\"\nexport TRADEKING_ACCESS_TOKEN=\"\u003cYOUR_ACCESS_TOKEN\u003e\"\nexport TRADEKING_ACCESS_TOKEN_SECRET=\"\u003cYOUR_ACCESS_TOKEN_SECRET\u003e\"\n```\n\nAlso export your TradeKing account number, which you'll find under\n*[My Accounts](https://investor.tradeking.com/Modules/Dashboard/dashboard.php)*:\n\n```shell\nexport TRADEKING_ACCOUNT_NUMBER=\"\u003cYOUR_ACCOUNT_NUMBER\u003e\"\n```\n\n### 3. Install dependencies\n\nThere are a few library dependencies, which you can install using\n[pip](https://pip.pypa.io/en/stable/quickstart/):\n\n```shell\npip install -r requirements.txt\n```\n\n### 4. Run the tests\n\nVerify that everything is working as intended by running the tests with\n[pytest](https://doc.pytest.org/en/latest/getting-started.html) using this\ncommand:\n\n```shell\nexport USE_REAL_MONEY=NO \u0026\u0026 pytest *.py -vv\n```\n\n### 5. Run the benchmark\n\nThe [benchmark report](benchmark.md) shows how the current implementation of the\nanalysis and trading algorithms would have performed against historical data.\nYou can run it again to benchmark any changes you may have made. You'll need a [Polygon](https://polygon.io) account:\n\n```shell\nexport POLYGON_API_KEY=\"\u003cYOUR_POLYGON_API_KEY\u003e\"\npython benchmark.py \u003e benchmark.md\n```\n\n### 6. Start the bot\n\nEnable real orders that use your money:\n\n```shell\nexport USE_REAL_MONEY=YES\n```\n\nHave the code start running in the background with this command:\n\n```shell\nnohup python main.py \u0026\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbbraun%2Ftrump2cash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxbbraun%2Ftrump2cash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbbraun%2Ftrump2cash/lists"}