We use a free Finnhub.io API to be able to pull real-time stock quotes, so you’ll need to head over to Finnhub.io and sign up for a free account, it literally takes a minute, just asks for your name, email and choose a password that’s all! (We are NOT affiliated or sponsored by Finnhub!).
I’m using a headless install of Raspberry Pi OS (Raspbian) but you can install the full version with desktop and follow the same steps in the video. I just prefer headless since I rarely ever need a desktop GUI in my projects.
Once you have your OS up and running and connected to WIFI, in a terminal window run:
you need to make sure you enable I2C and set your date/time & time zone. The Python script uses your current date & time to know when to turn off the NeoPixel’s. Watch the video for the initial steps here to do that using raspi-config.
Next installing the script, I tried to make this as easy as possible so you can create a directory and change into it, then run the line below to pull down the zip file with everything you need.
You can also grab all of these files on GitHub: https://github.com/DesignBuildDestroy/dbd_stocks_led/
Once downloaded unzip the contents
Then run setup.sh bash script which will pull down all the Python required libraries
Next we need to edit the stocks_led.py script to enter our Finnhub API key and our Stock Symbols. See the video for more details there. Edit the following lines in the stocks_led.py file and replace with your Finnhub API key along with your list of stock symbols
# Enter your free FinnHub API key here in quotes FH_API_KEY = 'YOUR_FINNHUB_API_KEY' # Add or change the stock symbols to your prference stocks_list = ['AMZN', 'GOOGL', 'AAPL', 'FB', 'NFLX', 'TSLA','SPY','ROKU']
And finally, since this device is meant to run without a monitor attached or any user intervention, we’ll want the Python script to run on startup of the device so if it’s ever unplugged and moved it won’t be a hassle to turn it back on.
To do this open crontab:
Past in this line:
@reboot /bin/sleep 120; sudo /usr/bin/python3 /home/pi/stock_led/stocks_led.py
You can play with the sleep 120 value, shorten it if you can, but I gave it a 2 minute wait time to be sure the Wifi connects otherwise the script will crash. Also make sure the path to the stocks_led.py is correct for the directory you unzipped to.