How to track your own portfolio in real-time using Python. Needless to say that the stock market has been volatile during this pandemic.
Needless to say that the stock market has been volatile during this pandemic. As most of us are stuck at home, I decide it to build a cool colored lamp to reflect my stock market portfolio in real-time. That way, when the stock market opens, my lamp switches on and its color reflect my opening market position and gets updated during the day. It is a cool gadget that I have not seen (yet) to buy, so why not build your own. I'm not a fan of day-trading, and for many reasons that I will discuss another day I strongly believe that most people shouldn't day-trade too. So the lamp is more a fun accessory than an anxiety creator.
Here is what you need to build your Stock Market Lamp Real-Time Tracker. If you already own a color bulb, you can check if there is a library or API to send commands via http. In this case we are using a Yeelight which has a Python library for it.
Light bulb globe
Basically, you will have a Wi-fi smart lamp and its color changing from your Python code. The globe is an enclosure to make it look nice.
Create a new python project. Install the main two libraries we will be using:
pip install yeelight investpy
Install the yeelight mobile app and configure the bulb. In the app, turn the LAN Control on. Get the IP address of the bulb on Bulb -> Settings (top right icon) -> Device Info. Check if the bulb is working.
from yeelight import Bulb, BulbException BULB_IP = '192.168.X.XXX' bulb = Bulb(BULB_IP) bulb.get_properties(requested_properties=['power', ])
Next you can create a function to determine your stock's PnL
def daily_pnl(stock): stock_data = investpy.get_stock_historical_data(stock, 'united states', from_date=(date.today() + timedelta(days=-1)).strftime("%d/%m/%Y"), to_date=date.today().strftime("%d/%m/%Y")) stock_data.index = stock_data.index + timedelta(days=1) ytd = stock_data.iloc.Close tdy = stock_data.iloc.Close return ((tdy-ytd)/ytd)*100
Simply passing a stock such as 'AAPL' should return the profit or loss from the day before.
Finally, all you have to do is to convert a PnL range to a RGB color.
Stock Market Betting Software Development - Mobiweb is expert Stock Market Betting Software development company, skilled in developing fantasy stock marketing apps and software.
In this Python Programming Tutorial for Beginners video I am going to show you How to use decorators in Python. Decorators wrap a function and modify its beh...
In this article you will learn: the easiest way to get the stock data in Python; what are trading indicators and how to calculate them; how to plot the stock data with OHLC chart
In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.
Today you're going to learn how to use Python programming in a way that can ultimately save a lot of space on your drive by removing all the duplicates. We gonna use Python OS remove( ) method to remove the duplicates on our drive. Well, that's simple you just call remove ( ) with a parameter of the name of the file you wanna remove done.