Skip to content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Alpha Vantage to MQTT

This script was written to provide stock price to a MQTT sensor in the HomeAssistant home automation platform. Unfortunately the built in Alpha Vantage componet fails if you have more than 1 or 2 stocks that you want to follow. And this script also allows you to offload the sensor update to another system to save your HomeAssistant resources from non-mission critical functions.



  • Install the app by cloning this repo
  • git clone
  • Install the required python libraries:
  • pip install paho-mqtt
  • pip install alpha_vantage
  • pip install python-dotenv
  • Edit the env-sample and saved as .env


This script is meant to run with something like supervisord, and has a default interval of 3600 seconds (1 hour). If you want to have this script to update your stocks continiously set the interval greater than zero. If interval is set to 0 the script will exit after running once. If you want to have cron or some other system mange the script execution then simply set the interval to 0 in the .env

There is a brief write up about the specific use case I built this for at []


  • This script publishes stock price to topic stock/<stock_name>/price
  • This script utilizes the get_batch_stock_quotes method of the Alpha Vantage API to reduce the number of calls to the API to avoid hitting the API more than once a second.
  • This script is built to run continiously and will pause for the interval set in the .env file.
  • The script has an app_mode set in the .env file. When app_mode is set to debug the script will output status messages to stdout. If you would like to supress these, change app_mode to somethign other than debug. Default app_mode is prod.
  • Log the script to Splunk using Splunk's HTTP Event Collector

You can Splunk It if you want to. You can leave your friends behind...

I added the ability to log to Splunk's HTTP Event Collector if you are like me and like to Splunk everything. The script leverages George Starcher's Python Class.

If you want to use the Splunk component you will need to install George Starcher's Python Class

  • pip install git+git://

The update your .env to include the details of your Splunk server:

# Splunk Server:
# Splunk HEC Port - Default is 8088:
# Splunk Hec SSL:
# Splunk HEC Token:
# Splunk index:
# Splunk sourcetype:
# Splunk Source:
# Splunk host:

If you don't set a token, the script will ignore the Splunk portion.

If you are new to Splunk or the Splunk's HTTP Event Collector you can find more information at Use Splunk's HTTP Event Collector


This script was written and tested using python 3.7.2

You can’t perform that action at this time.