Tutorials & Guides

How to create a cryptocurrency price tracking bot in telegram

Imagine a world where you don’t have to check your screen to know the price of cryptocurrencies.

You might miss out on good investment opportunities. But what if there was a better way? What if you could get instant notifications on your phone whenever your favorite coin reaches a specific price point?

Telegram bots are automated programs that interact with users within the Telegram messaging app. These are popular in the crypto space and can help you make informed trades.

Here’s what you need to build a crypto price tracking bot on Telegram

To create a custom crypto price alert bot on Telegram, you need:

  • Python (Latest Version): This powerful programming language will be the backbone of your bot.
  • Basic Python Knowledge: Familiarity with Python concepts will make the coding process smoother.
  • Text Editor: Choose your weapon of choice – any text editor will work.
  • CoinMarketCap API: This free API provides real-time crypto market data to fuel your bot.

You can also use the Coinbase, Coingecko or Binance APIs.

While not as customizable, no-code platforms offer a simple way to create bots. This may be a good option for those without much technical experience.

Buildship, BotPenguin, ManyChat, and Intercom let users create Telegram bots without coding. However, keep in mind that the platform has some limited features.

Why make your own Telegram price tracking bot?

In crypto, staying one step ahead is key. There are so many price-tracking services and apps that it’s easy to get overwhelmed.

Your Telegram bot can help you focus on your favorite digital assets.

Benefits of using a Telegram crypto price alert bot:

  • Convenience: Receive real-time price alerts directly in Telegram, eliminating the need to constantly monitor prices yourself.

  • Customization: Set alerts for specific cryptocurrencies and target prices based on your investment interests.

  • Automation: Automate the process of monitoring prices and receiving alerts, freeing up your time for other tasks.

Ready to build your own crypto bot and track the market? Stay tuned for the next part where we’ll show you step-by-step how to build your own Telegram price tracking bot!

Step 1 : Create Telegram Bot Using Botfather

BotFather is a Telegram service. You can access it through the app or website. It helps users create and manage bots on the Telegram platform, but it doesn’t provide code libraries or SDKs for programming bots.

You need to use a programming language like Python or Node.js with Telegram’s Bot API to interact with your bots.

  1. In your Telegram app, type “Botfather” in the search bar and you’ll see something like this👇 .

2. Tap “Send Message” and watch the dialog pop up. You can then select the option “/newbot – create a new bot”.

3. Choose a name for your bot. It must end in `bot`. Like this, for example: AlertpriceBot.Try something else if the name you entered is already taken.
4. Once that’s done, you’ll get a token to access the HTTP API (a secret key that allows you to talk to your bot, so only you can tell it what to say). Keep your token secure and store it safely, it can be used by anyone to control your bot.

Step 2: Get your CoinMarketCap API token

CoinMarketCap is a website that provides information about cryptocurrency prices, market capitalization, trading volume and other related data.

But few people know that CoinMarketCap has an API that is available to businesses, developers for the paid part and individuals thanks to free basic access for personal use.

  • Just go to https://coinmarketcap.com/api/ and click on “GET YOUR API KEY KNOW”.

You will then be redirected to this portal: https://pro.coinmarketcap.com/signup/ where you can create your account by entering your name and email address.

  • Once you’ve created an account. Make sure you don’t share your API secret key with anyone.

P.S.: Coinbase, Coingecko and Binance are alternatives to CoinMarketCap. You can use one of these APIs.

Step 3: Programming the bot

After step 1 and 2, you can program your bot. To do this, you’ll need to install two Python libraries to connect with the CoinMarketCap API and create the Telegram bot.

  1. Python-telegram-bot : It lets developers use Python to interact with the Telegram Bot API, making it easier to build and customize bots for various purposes.

You can use Python-telegram-bot with any text editor or Integrated Development Environment (IDE) that supports Python development.

Popular choices include Visual Studio Code, PyCharm, Atom, Sublime Text, and others. These editors provide features like syntax highlighting, code completion, and debugging tools, which can enhance your development experience when working on Telegram bots with Python-telegram-bot.

Here’s a general guide on how to download and set up Python-telegram-bot using Visual Studio Code:

👉Install Visual Studio Code: If you haven’t already, download and install Visual Studio Code from the official website: https://code.visualstudio.com/

👉Open Visual Studio Code: Launch Visual Studio Code after installation.

👉Create a New Python Project: Open the command palette by pressing `Ctrl + Shift + P` (Windows/Linux) or `Cmd + Shift + P` (Mac), then type “Python: Create New Blank Python File” and press Enter. Save the file with a `.py` extension, for example, `my_bot.py`.

👉Install Python-telegram-bot: Open the terminal in Visual Studio Code by selecting `Terminal -> New Terminal` from the menu, then type the following command and press Enter:


   pip install python-telegram-bot


👉Start Coding: Now you can start writing your Telegram bot code in the Python file you created (`my_bot.py`). Import the necessary modules from `telegram.ext` to get started.

👉Run Your Bot: You can run your bot directly from Visual Studio Code. Open the terminal again and navigate to the directory where your Python file is located using the `cd` command. Then, run your bot script using the `python` command followed by the name of your Python file. For example:


   python my_bot.py


This is a general guide. Your setup and preferences may vary. This should help you get started with Python-telegram-bot in Visual Studio Code.

  1. requests :  This library is used to make HTTP requests to APIs, which the bot will use to fetch cryptocurrency prices. It makes it easier to send requests and process responses, so you can easily get data from the CoinMarketCap API.

To add the “requests” library to your Python project in a text editor like Visual Studio Code, you typically follow these steps:

👉Open Your Project : The Python-Telegram-Bot project you installed before.

👉Open Terminal: Open the integrated terminal in Visual Studio Code. You can do this by selecting `Terminal` from the top menu and then choosing `New Terminal`.

👉Install requests: In the terminal, use pip (Python’s package installer) to install the requests library. Type the following command and press Enter:
   pip install requests

This command will download and install the requests library along with its dependencies into your Python environment.

👉Verify Installation: Once the installation is complete, you can verify that requests is installed by running the following command in the terminal:  pip list

 This command will display a list of installed Python packages, and you should see “requests” listed among them.

👉Start Using requests: Now you can start using the requests library in your Python code. Import it at the beginning of your Python script with:  “`python  import requests


Your code should look like this:

Let’s look at each line of this code :

1. Importing Libraries:

  • from telegram import Update: This line imports the Update class from the telegram library. This class will be used to access information about incoming messages from Telegram users.
  • from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes: This line imports several classes from the telegram.ext library:

    • ApplicationBuilder: This class is used to create a Telegram bot application.
    • CommandHandler: This class is used to define functions that will handle specific Telegram commands sent by users (e.g., /start, /data).
    • ContextTypes: This class defines the context in which a command handler is executed.
  • import requests: This line imports the requests library, which allows us to make HTTP requests to web APIs.
  • import json: This line imports the json library, which is used to work with JSON data (JavaScript Object Notation).

API Key and Base URL:

  • api_key = “YOUR_COINMARKETCAP_API_KEY”: This line defines a variable api_key but doesn’t assign a value yet. You’ll need to replace “YOUR_COINMARKETCAP_API_KEY” with your actual API key from CoinMarketCap to access their data.
  • base_url = “https://api.coinmarketcap.com/v1/”: This line defines the base URL for CoinMarketCap’s API endpoints.

3. Fetching Cryptocurrency Data (get_crypto_data function):

  • This function takes a crypto argument, which is the name of the cryptocurrency (e.g., “bitcoin”, “ethereum”).
  • It builds the complete URL for the CoinMarketCap API endpoint to get data for that specific cryptocurrency. It includes your API key for authentication.
  • It uses the requests library to make a GET request to that URL.
  • It checks for errors using try…except blocks:
    • If the request is successful (status code 200), it extracts the relevant data from the JSON response and returns it.
    • If there’s an HTTP error (e.g., server unavailable), it prints an error message.
    • If any other exception occurs, it prints a generic error message.
  • If the request fails to retrieve data, the function returns None.

4. Fetching Top 10 Cryptos (get_top_cryptos function):

  • This function is similar to get_crypto_data but retrieves data for the top 10 cryptocurrencies.
  • It builds the URL with a limit of 10 and returns a list containing data for all 10 currencies of your choice. It could be one or more cryptos.

5. Telegram Bot Logic (async functions):

Please note: The code shows placeholders (…) for the actual logic within these functions. We’ll explain the general idea.

  • These functions are declared as async because they might involve waiting for responses from Telegram or the CoinMarketCap API.
  • start(update, context): This function likely handles the /start command, sending a welcome message to the user.
  • data(update, context): This function likely handles a command like /data {crypto_name}. It extracts the cryptocurrency name from the message, retrieves data using get_crypto_data, and then formats and sends the data back to the user in a reply message (depending on the data received).

There could be similar functions for other commands like high_low, supply, and ranks, using the appropriate functions (get_crypto_data or get_top_cryptos) to retrieve data.

6. Building and Running the Bot:

  • app = ApplicationBuilder().token(‘YOUR_TG_BOT_TOKEN’).build(): This line creates a Telegram bot application using the ApplicationBuilder class. You’ll need to replace ‘YOUR_TG_BOT_TOKEN’ with your actual Telegram bot token from Botfather.
  • There would be lines following this to add handlers for each command using the CommandHandler class, linking them to the corresponding functions (e.g., start, data).
  • Finally, app.run_polling() starts the bot and keeps it running, listening for incoming messages from Telegram users.

Step 4 : Handling Errors by testing the bot

Test your Telegram bot before you or other users interact with it. Here’s how to test your bot:

  1. Run the Bot Code: Execute the Python script using your code editor (like Visual Studio Code).
  2. Find Your Bot on Telegram: Open the Telegram app and search for your bot using the username you assigned during creation.
  3. Interact with Your Bot: Start a chat with your bot and experiment with the commands. Here are some examples:
    • /start: Launches the bot.
    • /data <crypto name>: Retrieves current data for a specific cryptocurrency (e.g., /data bitcoin).
    • /high_low <crypto name>: Provides the highest and lowest prices of a cryptocurrency within the last 24 hours.

How does it work?
When you use a command :

  • the bot gets data from CoinMarketCap’s API.
  • The bot replies in the chat window. If you used /data Solana, the bot would reply with Solana’s current price.

Unlock advanced features for a better experience

Your crypto-currency price alert bot is a good place to start, but wouldn’t it be great to have a cryptocurrency companion that goes beyond the numbers? 

Adding portfolio tracking makes your basic bot a powerful tool for better-informed and more successful.

How to create a crypto price alert  bot on Telegram without coding?

You can create a crypto price alert bot for Telegram without coding. Here’s a popular option:

Build a Crypto-Tracking Telegram Bot with BuildShip (No Code Needed!)

BuildShip lets you create a Telegram bot without writing code.

Getting Started with BuildShip

First, get a BuildShip account. Log in, then click “Add New Workflow.”

Setting Up the Trigger

Select the “Webhook” trigger as your starting point. We’ll configure this later to receive updates when the crypto price changes.

Create an API key  (Coinbase or CoinMarketCap API key)

  1. Head over to your Coinbase account settings and navigate to the API section.
  1. Create a new API key and enable the “View Accounts” permission. This allows your bot to access crypto price data.
  1. Copy the API key – you’ll need it later in BuildShip.

Building the Price Check Functionality

  1. Add an HTTP Request node from the node library.

2. Configure the request details:

    • Method: GET
    • Headers: Add a header named “Authorization” and set its value to “Bearer” followed by your Coinbase API key (obtained in step 3).

    Parsing the Price Data

    1. Add a “JSON Parse” node after the HTTP Request node. This will convert the response from Coinbase (which is in JSON format) into a format BuildShip can understand.

    Sending the Price Update

    1. Add a “Send Telegram Message” node from the node library.

    2. Fill in the following details:

    • Chat ID: This can be found in a Telegram group chat ( with your Builship and Rawdatabot bots ) by sending a message and using the “Get Chat ID” option.
    • Telegram API Key: Obtain this from BotFather as described in the previous blog post.
    • Text: Here, you can create a message template that includes the fetched cryptocurrency name and price data retrieved from the JSON parsed data in the previous step.

    Triggering Price Updates (Optional)

    While the bot will check the price once upon deployment, you can configure the initial webhook trigger to fire periodically using BuildShip’s scheduling options. This allows the bot to automatically check for price updates at set intervals.

    Deploying Your Bot

    1. Click “Ship” to deploy your workflow.
    1. Invite your BuildShip bot to a Telegram group or chat and see it deliver the latest crypto prices!

    Customization Ideas

    1. Track multiple cryptocurrencies by adding separate workflows for each.
    1. Allow users to trigger price checks by sending a specific command to the bot.
    1. Set up alerts to notify users when prices reach a certain threshold.

    Leverage Telegram’s bots and Crypto signals

    Crypto Telegram bots can help crypto enthusiasts. They provide alerts, allow customization, and can automate tasks. However, be cautious of scams and only use bots from trusted sources.

    Crypto signals are recommendations to buy or sell crypto based on analysis. They can help both beginners and experienced traders.

    Signals aren’t guaranteed profits. Their accuracy depends on the source. Do your own research before following a signal.

    There are two main places to find crypto signals:

    • Telegram Channels: Many crypto analysts and trading groups offer signals on Telegram channels. These can be free or require paid subscriptions. It’s important to research the provider’s reputation and track record before subscribing.
    • Trading Bots (Advanced): Some trading bots integrate with crypto signal providers. These bots can receive signals and even execute trades automatically. This is an advanced strategy for experienced users.

    Remember, bots rely on your input and can’t predict the market perfectly. Use them for guidance, but make your own investment decisions!

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Back to top button