President Donald Trump tweeted on Monday that the chaos in airports over the weekend was Delta Airlines' fault—along with protesters and "the tears of Senator [Chuck] Schumer."
He sent those tweets a little after 7 a.m. By 9:30 a.m., Delta Airlines' stock was down 1.6 percent.
Meanwhile, an algorithm was raking in money from those tweets.
T3, an advertising company in Austin, Texas, built the "Trump and Dump Bot" to analyze Trump's tweets and play the stock market when he says something bad about a company. They donate the money they make to the American Society for the Prevention of Cruelty to Animals.
Here's how the bot works, according to T3 president Ben Gaddis.
First, Trump tweets, and the bot checks to see if Trump is tweeting about a publicly-traded company.
The bot does a "sentiment analysis" of the tweet, looking for words like "big problems" and "caused by."
Then it gives the tweet a sentiment ranking. For Trump's tweet about imposing a border tax on Toyota's plant in Mexico, the ranking was 17.9 percent—very low, according to Gaddis.
If the sentiment ranking is low enough, the bot heads to E-Trade as fast as possible and borrows stock in the company Trump is tweeting about. This all happens in less than a second.
The bot then sells its newly-acquired stock before the company's shares tank. Then, when the stock is down, it buys back those shares at a cheaper price. When Delta Airlines stock dropped, the "Trump and Dump Bot" made a 4.47 percent profit.
Still confused? Here's a video T3 made to explain it.
T3 is currently the only company talking about using a bot in this way, but Gaddis thinks other companies are doing or trying to do something similar.
Gaddis doesn't think profiting off a company's run-in with President Trump is bad—especially when the profits are donated.
"President Trump tweets something negative, we save a puppy," Gaddis said. "That's something I think everybody can get behind."