Sign inSign up

prometheus199/stockspython

By prometheus199

•Updated 8 months ago

stock prices via mqtt

Image
1

344

prometheus199/stockspython repository overview

⁠Stock Price MQTT Reporter

A Python-based Docker container that monitors stock prices using the yfinance library and publishes updates to an MQTT broker.

⁠Environment Setup

Create the necessary directories on your host machine to store configuration and logs:

mkdir -p ${PWD}/data ${PWD}/data/log

⁠Configuration

Create the configuration file at ${PWD}/data/stocks.ini.

  • starttime/endtime: Operational hours in local time.
  • period: Polling frequency in seconds.
[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

⁠Deployment

⁠Building the Image

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 .

⁠Running the Container

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

⁠Docker Compose Configuration

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

⁠Technical Details

  • Base Image: python:3.11-slim
  • Libraries: yfinance, paho-mqtt, configparser
  • Persistence: Config and logs are maintained on the host via volume mounting.
  • Execution: The script runs in unbuffered mode (-u) to provide real-time log output.

Tag summary

Content type

Image

Digest

sha256:5a27fdee0…

Size

101.5 MB

Last updated

8 months ago

docker pull prometheus199/stockspython:v1.0