Stock Prices Tracker

To build the stock price tracker with Python we will track the price of Apple. When the price is below a pre-defined threshold, the script will send us an email to our Gmail account letting us know about the price drop.

This is particularly useful in case we have fixed a target price for a stock and we want to be informed once the prices reaches down that level. I will put the code below in one piece. The reason for this is that the code is rather simple. We will use financialmodelingprep in order to request real-time quote prices of the stock that we want to track.

Building the Send EmailFunction The send email function is where we configure the code to send us an email. We will use the library smtplib in order to achieve this. Using Smtplib we will:

Create a SMTP connection Define our message, subject and recipient And send the email The code below follows the smtplib documentation to create a connection and start the server. Since it is a bit technical, I will not cover the details in this post. You can have a look at the documentation for additional information.

What is important is to pass your Gmail account and Gmail password within the object server.login(‘your gmail’ , ‘your password’). In the code, my Gmail password is stored in the password variable.

Within server.sendmail, we pass the recipient of the email and the message (i.e. msg).

Built With

Share this project:

Updates