Trump Tweet Bot
- Michael Wrede
- Jul 11, 2020
- 2 min read
Updated: Feb 5, 2021
I first heard of this idea from a Planet Money episode. Here is that episode. The idea is simple: create a trump trading bot that reads Trump's tweets and makes a trade if he mentions a company. I was obsessed with this idea and did all types of research and even found the guy who did its original source code: Max Braun. I looked at the code and was baffled. I had little experience with code and couldn't understand how Max had made this Bot. It made no sense to me and so I knew that if I myself wanted to implement it, I had to build my own code.
I spent hours researching, building code and there were so many ups and downs. It took more than 4 months of much trial and error and it's a process that illustrates why coding and projects can be so difficult to make and stay focused on. I had to learn python and the Twitter API to grab the information I needed. I've spent hours and hours trying to get the code to work and now it does, but there are many flaws and things I need to still work on. I want to share with you more about the specifics of the code and also what still needs works.
Code Details:
The code runs on my local computer and checks to see if the market is open. If it is, it will call the Twitter API every minute and see if the tweet has changed. If it has, it will analyze the new tweet and see if the new tweet mentions a company. If it does, then the price is grabbed from Yahoo Finance at that moment and stored. It also makes sure to grab the sentiment and log that as well. Two hours later, the "sell price" is grabbed and then logged. At the end of the day, it's stored in excel for me to upload and use. So while my trade bot doesn't actively trade (I'm a poor college student), it does in practice. This GIF will give you an idea of how it works.

Challenges:
1) The Code Runs only on Local Host
The code works but only on my local computer and thus can't run without me. I want to make it so my computer can talk to my code and so that it runs continuously. This would require a server and a deeper understanding of the internet which I don't have, but look forward to maybe learning.
2) Can't Find Companies that Well (Bad Text Analysis)
So when Trump makes a tweet and says Home, my code will buy Home Depot, which is not right at all. I have made sure some keywords like "the", "company" don't trigger a True statement for the company found. Still, this means my code has a serious flaw and I haven't completely figured out to get a better match when it comes to finding the company. I need to do more Text analysis research.
Next Steps:
I hope to get my tweet bot fully up and running and at least just working with me, and then see if I can move it to a server and get that working. I hope it will work, but wish me luck.
Yorumlar