โ† Back to Dashboard

๐Ÿ“ˆ Pi Stock Ticker

A production-ready Raspberry Pi portfolio tracker that displays live stock and cryptocurrency prices on a Waveshare 2.7-inch e-ink display and provides a full web configuration dashboard.


Features

Category Details
Display Waveshare 2.7" e-ink, 176ร—264, 4-level greyscale
Assets Stocks (yfinance), Crypto (CoinGecko), Forex/ETFs
Portfolio Buy-in price, quantity, current value, P&L in $ and %
Pages All assets ยท Crypto only ยท Stocks only ยท Summary
Web UI Responsive dashboard, dark/light theme, live preview
Alerts Telegram notifications on configurable P&L thresholds
Data SQLite + price history, in-memory cache
Service systemd, auto-start on boot, watchdog restart

Architecture

pi-stock-ticker/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ main.py              โ† FastAPI app, startup/shutdown
โ”‚   โ”œโ”€โ”€ config.py            โ† Pydantic settings (.env driven)
โ”‚   โ”œโ”€โ”€ database.py          โ† SQLAlchemy + SQLite (WAL mode)
โ”‚   โ”œโ”€โ”€ models.py            โ† Asset, Setting, PriceHistory ORM
โ”‚   โ”œโ”€โ”€ price_fetcher.py     โ† CoinGecko + yfinance + cache
โ”‚   โ”œโ”€โ”€ portfolio.py         โ† P&L calculation, price update
โ”‚   โ”œโ”€โ”€ scheduler.py         โ† APScheduler jobs
โ”‚   โ”œโ”€โ”€ eink_renderer.py     โ† Pillow-based image renderer
โ”‚   โ”œโ”€โ”€ display_controller.pyโ† Waveshare wrapper + mock mode
โ”‚   โ”œโ”€โ”€ telegram_bot.py      โ† Optional price alerts
โ”‚   โ””โ”€โ”€ routes/
โ”‚       โ”œโ”€โ”€ assets.py        โ† CRUD /api/assets/*
โ”‚       โ”œโ”€โ”€ settings.py      โ† /api/settings/
โ”‚       โ””โ”€โ”€ display.py       โ† /api/display/preview*, /refresh
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ index.html           โ† SPA shell
โ”‚   โ”œโ”€โ”€ style.css            โ† Dark/light theme CSS
โ”‚   โ””โ”€โ”€ app.js               โ† Vanilla-JS controller
โ”œโ”€โ”€ waveshare/
โ”‚   โ”œโ”€โ”€ epd2in7.py           โ† Official Waveshare driver (adapted)
โ”‚   โ””โ”€โ”€ epdconfig.py         โ† GPIO/SPI pin config
โ”œโ”€โ”€ systemd/
โ”‚   โ””โ”€โ”€ pi-stock-ticker.service
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ install.sh           โ† Full installer
โ”‚   โ””โ”€โ”€ dev.sh               โ† Desktop/dev run (mock display)
โ”œโ”€โ”€ fonts/                   โ† DejaVu Mono (copied by installer)
โ”œโ”€โ”€ data/                    โ† portfolio.db (created at runtime)
โ”œโ”€โ”€ logs/                    โ† app.log, service.log
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ .env.example

Hardware Requirements

Wiring โ€” HAT plug-in

The Waveshare 2.7" HAT plugs directly onto the 40-pin GPIO header.
If you need to wire manually:

HAT pin BCM GPIO Function
RST 17 Reset
DC 25 Data/Command select
CS 8 (CE0) SPI chip select
BUSY 24 Busy signal (input)
CLK 11 (SCLK) SPI clock
DIN 10 (MOSI) SPI data
VCC 3.3 V Power
GND GND Ground

Quick Start

1. Clone the repo

git clone https://github.com/youruser/pi-stock-ticker.git
cd pi-stock-ticker

2. Run the installer

bash scripts/install.sh

The installer will:
- Install system packages and Python dependencies
- Enable the SPI interface
- Copy DejaVu Mono fonts
- Create a .env from .env.example
- Register and enable the systemd service

3. Configure (optional)

nano .env

Key settings:

REFRESH_INTERVAL=300     # price fetch every 5 minutes
DISPLAY_CURRENCY=USD
DISPLAY_ROTATION=true    # rotate pages automatically
PAGE_DURATION=15         # seconds per page

# Optional Telegram alerts
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=

4. Start the service

sudo systemctl start pi-stock-ticker
sudo systemctl status pi-stock-ticker

5. Open the web dashboard

http://<raspberry-pi-ip>:8000

Find your Pi's IP with: hostname -I


Desktop / Development Mode

No Raspberry Pi? Run with a mock display on any machine:

# Create venv and install deps
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Run with mock display (no GPIO needed)
bash scripts/dev.sh

Open http://localhost:8000 โ€” the display preview will render in the browser.


Web Dashboard

Portfolio tab

Display tab

Settings tab

README

This page โ€” also accessible at /readme โ€” rendered from README.md.


API Reference

Interactive docs: http://<pi>:8000/api/docs

Method Endpoint Description
GET /api/assets/ List all assets
POST /api/assets/ Create asset
PUT /api/assets/{id} Update asset
DELETE /api/assets/{id} Delete asset
GET /api/assets/search/crypto?q= Search CoinGecko
GET /api/assets/search/stock?q= Search Yahoo Finance
GET /api/display/preview.png?page= E-ink PNG (all/crypto/stocks/summary)
GET /api/display/preview?page= Base64-encoded preview
GET /api/display/summary Portfolio totals + asset list
POST /api/display/refresh Force price fetch
POST /api/display/clear Clear physical display
GET /api/settings/ Get settings (secrets masked)
PUT /api/settings/ Update settings

Configuration Reference

Variable Default Description
HOST 0.0.0.0 Bind address
PORT 8000 HTTP port
DEBUG false Enable debug logging + hot reload
REFRESH_INTERVAL 300 Seconds between price fetches
DISPLAY_CURRENCY USD Portfolio currency
DISPLAY_ROTATION true Auto-rotate display pages
PAGE_DURATION 15 Seconds per display page
DISPLAY_ENABLED true Enable e-ink output
DISPLAY_MOCK false Suppress hardware calls
COINGECKO_API_KEY `` CoinGecko Pro key (optional)
ALPHA_VANTAGE_KEY `` Alpha Vantage key (optional)
TELEGRAM_BOT_TOKEN `` Telegram bot token
TELEGRAM_CHAT_ID `` Telegram chat/user ID
TELEGRAM_ALERT_THRESHOLD 5.0 Alert when |P&L%| โ‰ฅ this value

Telegram Alerts Setup

  1. Message @BotFather on Telegram โ†’ /newbot โ†’ copy the token
  2. Message @userinfobot โ†’ copy your user ID (or use a group chat ID)
  3. Set TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID in .env or the Settings tab
  4. Alerts fire when any asset's P&L% exceeds TELEGRAM_ALERT_THRESHOLD

Display Pages

Page Content
All Full portfolio โ€” all assets, P&L per row, total in footer
Crypto Crypto assets only with sub-total
Stocks Stock/forex assets only with sub-total
Summary Total value, P&L, best/worst performers, last-updated timestamp

Pages rotate automatically every PAGE_DURATION seconds when DISPLAY_ROTATION=true.
A full e-ink refresh is forced every 10 partial updates to prevent ghosting.


Performance on Raspberry Pi

Resource Typical usage
RAM ~60โ€“90 MB
CPU idle < 1 %
CPU during price fetch 10โ€“20 % (a few seconds)
Disk (SQLite) < 50 MB after a year of history

The service is capped at 256 MB RAM and 80 % CPU by the systemd unit.


Troubleshooting

Display not updating

# Check SPI is enabled
ls /dev/spi*

# Enable SPI if missing
sudo raspi-config nonint do_spi 0
sudo reboot

Prices not fetching

# Check logs
journalctl -u pi-stock-ticker -f

# yfinance needs internet
curl -s https://finance.yahoo.com | head -5

# CoinGecko free tier: 30 req/min
# Increase REFRESH_INTERVAL if you see 429 errors

Service won't start

# Check status
sudo systemctl status pi-stock-ticker

# Re-read service file after editing
sudo systemctl daemon-reload
sudo systemctl restart pi-stock-ticker

"Font not found" in logs

# Copy DejaVu fonts manually
cp /usr/share/fonts/truetype/dejavu/DejaVuSansMono*.ttf fonts/

Updating

cd pi-stock-ticker
git pull
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart pi-stock-ticker

License

MIT โ€” free to use, modify, and distribute.


Built for Raspberry Pi + Waveshare 2.7" e-Paper HAT.
Web UI readable at /readme on any running instance.