Build a Bitcoin Price Alert with Google Cloud and Telegram
Last updated
Last updated
In this article, I am going to share how to build a Telegram bot for Bitcoin price alerts. The code is written in Python. I use the free tier Google Cloud to run the Python code 24/7 for free. The Python code will read the Bitcoin price from the Binance API, and then it will send a message alert to our Telegram account.
First, we have to create and setup a free tier Google Cloud. You can follow the following . With this setup, we can use Google Cloud for free even after the trial period is over.
First, we have to download and install Miniconda. To download the Miniconda installer, we can use wget commad. If this command is not installed yet, you can install it with the following command:.
Download Miniconda installer with the following command:
To install Miniconda, execute the following command:
I installed Miniconda in the following location:
After the installation process is finished, we have to restart the Google VM.
Talk with the BotFather on Telegram () and then create a new bot. You will get a token to access the HTTP API of the bot.
Install Telegram library for Python from the Google VM with the following command:
Configure telegram-send with your bot using the token with the following command. Then, you will be asked for the token. After that, you will be asked to add your bot on Telegram and send it the given password. After finising, you are ready to use telegram-send.
To test the connection with your Telegram account, you can execute this command from the Google VM:
Now, our Google VM is connected to our Telegram account. Next, we can try to send message from a Python program. This is the Python code:
Run this Python code with the following command:
CronJob creates jobs on a repeating schedule. We can use CronJob to execute our Python code at regular intervals.
To access CronJob setting, use the following command:
Add this setting in order to execute the code every 1 hour.
To get data from REST API, we have to install requests
library for Python:
Use the following code to test the library with Binance API:
This code combines all the functionality to get price data from Binance and then send it to the Telegram account.
After that, we can setup the CronJob to automate the Python code execution, for example:
This figure shows the message in Telegram.
Details of the CronJob time format can be studied at .
Google Cloud Platform (Free Tier) WordPress Setup,
Python in the Cloud Part I - How to run Python in the Cloud / Conda environment setup on GCP,
crontab guru,