Stock Market Lamp Real

Stock Market Lamp Real

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.

List of materials

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.

Yeelight bulb

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.

Python Code Bulb Control

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', ])

Python Code Stock Market

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=( +
    stock_data.index = stock_data.index + timedelta(days=1)
    ytd = stock_data.iloc[0].Close
    tdy = stock_data.iloc[1].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.

gadgets home-decor finance python stock-market

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Stock Market Betting Software Development | Stock Market Betting Solutions

Stock Market Betting Software Development - Mobiweb is expert Stock Market Betting Software development company, skilled in developing fantasy stock marketing apps and software.

Python Decorators | Decorators in Python | How to Use it and Why

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...

3 Basic Steps of Stock Market Analysis in Python

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

Python Tricks Every Developer Should Know

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.

How to Remove all Duplicate Files on your Drive via Python

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.