Send Stock Data to Your Phone with Python!

Learn how to harness the power of Python to win in the stock market…

Shashank Vemuri
Towards Data Science

--

Image by 3D Animation Production Company from Pixabay

With the stock market rapidly changing on a day-to-day basis and many budding investors using mobile applications such as Robinhood to trade, it is imperative to constantly stay updated, or risk being left behind. That’s precisely why I created this quick ~150 line Python program that can send me live stock data directly to my phone for easy access. Now that the need for such a program is clear, let’s jump into the code!

Import the dependencies and set the parameters

First off, we must import the dependencies we will be using in the code and set the parameters we need for the program to execute properly. In case any of the modules are not downloaded on your machine, you can easily open up your terminal or command prompt and use pip to install the package. The stock_list variable must be set to a list of stocks as shown above. The start and end dates can be changed but must remain in DateTime format!

The function to send messages directly to your phone!

In order for the code to work, we must update the email variable with our email and the password variable with the password for that respective email. For the sms_gateway variable, you can head on over to this link, enter your phone number, and then copy the SMS Gateway Address response. An example SMS Gateway Address would be 1234567890@tmomail.net. You can also change the Subject of the text as needed but I have left it as Stock Data.

Disclaimer: You must set “Allow less secure apps” to ON in your Gmail account settings! This Allows Python to access your Gmail account to send the SMS text message. Please follow this tutorial if you are confused!

Now that we have set up our sendMessage function, we can move on to actually getting our data!

The function to collect data on the stocks and send the message!

The code above consists of the getData function which calculates the different metrics for each stock and then calls back the sendMessage function to send an SMS message to your phone.

In this particular example, the metrics were calculated using the modules TaLib, NumPy, and nltk. They include the current price of the stock, its current news sentiment, its beta value, and its Relative Strength Index (RSI) value. This, of course, can be changed to your preference depending on what data you want to receive.

The final two lines of the program call upon the getData function which in turn calls upon the sendMessage function we created a short while back.

And that is it for this program, if you have any questions about any part of the code or the calculations for any of the metrics, please do not hesitate to reach out. All the code for the entire program is down in the GitHub gist below!

All the code!

Please remember to set “Allow less secure apps” to ON in your Gmail account settings for the program to work! I hope this code will prove useful to you in the future and thank you so much for reading!

Disclaimer: The material in this article is purely educational and should not be taken as professional investment advice. Invest at your own discretion.

--

--

Hey! I’m Shashank Vemuri, a software engineer, stock trader, and entrepreneur.