The implementation of API for Stock updates using Python
Application Programming Interface (API) is one of the most essential software intermediaries in Data Science. Solving business problems that involve a lot of data brings API as an important one to get data from a company data to create an application. One of the business cases in using API is making a notification for traders or investors as a piece of information for knowing the latest update of the equity. FB or meta as their brand new name company is one of the most influential companies at the moment.
Meta in the stock market in the US has a good influence on the investor's eyes. The stock of Meta is dramatically increased that attracting many investors to invest in Meta yearly. Therefore, We will create an application for giving the latest update information for investors about the daily change of this stock and sentiment-related news that influences the price. We will use a few APIs from Twillio for sending a message to investors, News API to send the latest news that influences the stocks price, and Alphavantage API to get the stock update price information.
Owing to the needs of Twilio API, AlphaVantages API, and News API data, we will use each API key to pull the data. You can access each data on the website and get the API key. We will use the Requests library to get the data and access them in JSON format as follows:
as you can see, we are importing all the libraries needed and creating endpoints for each API. You can get all these parameters names based on the documentation of the API. We also create a constant variable for Twilio SID and authorized token. This variable is important to connect the Twilio API to our phone number. You can get the JSON format by implementing requests library and see in your browser by installing JSON format extension in your browser. This is an example of pulling the data from the API.
Then, our dictionary shows that we need Time Series (Daily) key for getting daily update stock price as follows. We create yesterday's data and closing data price for knowing the closing price for each day.
To get a better sense of knowing the increase or decrease of the stocks, we need to know the difference between yesterday's data and the day before yesterday's data as follows:
Last but not least, we can connect our phone number to Twilio and integrate the latest update of Meta Stock price and send it to specific verified numbers that we already verified on the Twilio site. You can check the API documentation about verifying the numbers. You can see the final output and code as follows:
Based on the information getting from the News API said that there is a 2% decrease in FB stock and some news that supports why the decrease happen. That’s all about implementing API to make notifications by integrating a few APIs. I hope you like this article. You can check the full version of the code on Github.