I was listening to a radio program the other day where the host and his guest were talking about how President Donald Trump’s tweets could sink or spike a company’s stock price. They said that it takes about four seconds after Trump tweets about a company to see the effect on the company’s stock price. That got me thinking: what if we could listen for specific tweets from specific users or specific topics and recipients, and then act on the detected tweet depending on whether it has positive or negative sentiment.
For example, if President Trump tweets congratulations to a company for adding jobs in the U.S., the tweet listener can send a buy signal to an automated stock trading system for that company’s stock. Conversely, a negative tweet will generate a sell signal for a stock before the price takes a dive.
Bluemix + Node-RED = working app
To create a prototype for my Tweet listener, I used Bluemix. I’ve built and hosted multiple apps with Bluemix and it’s very easy to use. I also know that Node-RED provides a quick way to put together the required services and logic — I can just use its visual editor with nodes that provide functionality for getting tweet streams and sentiment analysis.
It took me all of 30 minutes to put together the simple Node-RED flow:
How the app listens and analyzes
I set up the Twitter node to search for tweets with “@realDonaldTrump” and “job” strings (but the search string and Twitter account can be customized to any valid twitter handle and string). You need a valid Twitter account and log-in to access the Twitter API for the tweet stream with the Twitter node.
For this early version of the prototype, I just dumped the positive, neutral, and negative tweets, plus the counts for the positive and negative tweets, into the debug panel using the debug node. You can replace these nodes with nodes that trigger an OpenWhisk event, send an email, leverage Watson on Node-RED services, or invoke a REST call into a stock trading system … but I’ll save those options for the next iteration.
I’m going to keep plugging away on the prototype and hope to show you a much-improved version in the next iteration. I’d love to hear any feedback, and I’d also like to know how you are using Node-RED, OpenWhisk, Watson, and developerWorks Open projects to create innovative apps. Leave me a comment or drop me a line!