A Python-based Docker container that monitors stock prices using the yfinance library and publishes updates to an MQTT broker.
Create the necessary directories on your host machine to store configuration and logs:
mkdir -p ${PWD}/data ${PWD}/data/log
Create the configuration file at ${PWD}/data/stocks.ini.
[mqtt]
broker = 192.168.xxx.xxx
port = 1883
user = <mqtt_user>
passwd = <mqtt_password>
[info]
starttime = 12
endtime = 21
period = 300
[stocks]
ticker = GOOG,IBM,TSLA,NVDA
Because the Yahoo Finance API is subject to frequent changes, it is recommended to build the image locally to ensure the latest library fixes are applied:
docker build -t prometheus199/stockspython:latest .
Execute the following command to start the monitor. Ensure the TZ variable matches your local timezone to sync the starttime and endtime logic correctly.
docker run -d \
--name stocks \
--restart unless-stopped \
-v ${PWD}/data:/app/data \
-e TZ=Europe/London \
prometheus199/stockspython:latest
Alternatively, define the service in a docker-compose.yml file:
services:
stocks:
container_name: stocks
image: prometheus199/stockspython:latest
build: .
volumes:
- ./data:/app/data
restart: unless-stopped
environment:
- TZ=Europe/London
python:3.11-slimyfinance, paho-mqtt, configparser-u) to provide real-time log output.Content type
Image
Digest
sha256:5a27fdee0…
Size
101.5 MB
Last updated
8 months ago
docker pull prometheus199/stockspython:v1.0