Iâm working on some new projects involving getting stock price data from the web, which will be tracked and displayed via my Raspberry Pi. I wanted to share the setup on how to do this using Python.
This short Instructable will show you how install a stock querying library to get (mostly) realtime stock prices using Yahoo Finance API. Thereâs no GitHub involved!
You can also use this stock price-gathering engine on any Linux server.
Step 1: Setup your Raspberry Pi
If you havenât done so already, youâll want to do a basic configuration of your Raspberry Pi. Youâll need internet access for this software installation.
If you are just getting started, my Ultimate Raspberry Pi Configuration Guide will get up and running.
I prefer using ssh and am using Terminal on a Mac, but as long as you have internet connection, youâll be fine.
We will be using the command line for this tutorial on a Raspberry Pi.
Step 2: Run updates and upgrades
Whenever you add new libraries to your Raspberry Pi, you want to update and upgrade your software packages. Weâll start with this step.
Type in
sudo apt-get update
then
sudo apt-get upgrade
choose Y to continue when asked
Youâll see the usual scroll of Linux and will have to wait several minutes. Get up and do some stretching after each of these commands.
Step 3: Install pip
pip is a package manager and installer for Python. We want to have this installed to get the appropriate Yahoo python stock libraries loaded onto the Pi.
Type in:
sudo apt-get install python-pip
choose Y to continue when asked
This will take a few minutes.
Step 4: Install ystockquote
ystockquote is a Python module that will let you easily gather stock quotes from Yahoo. It does this reasonably quickly, a lot more so than BeautifulSoup, which would be another way to get stock data.
Type in:
sudo pip install ystockquote
Step 5: Write the Python Script
We will create a new directory and a Python script to get the stock data. Type in:
mkdir stockquote
cd stockquote
nano stockquote.py
This will bring up the nano editor.
Type in this following 4-line Python script
import ystockquote
tickerSymbol = âADSKâ
allInfo = ystockquote.get_all(tickerSymbol)
print tickerSymbol + â Price = â + allInfo[âpriceâ]
cntrl-X, Y will save the .py file.
Step 6: Run It, Done!
For more detail:Getting Stock Prices on Raspberry Pi (using Python)