A self-hosted price tracking bot — posting to Telegram, Discord, or logging to a database — is a common, approachable first crypto-adjacent project on a VPS. This guide covers building a basic one using a public price API.
What This Guide Covers (and Doesn't)
This is a price-tracking and notification tool, not a trading bot that executes trades — it doesn't touch funds or exchange accounts, making it a much lower-risk starting project than automated trading.
Prerequisites
- Python installed
- A Telegram bot token (created via Telegram's BotFather) if using Telegram notifications
Step 1 — Install Required Libraries
pip install requests python-telegram-bot --break-system-packages
Step 2 — Fetch Current Price Data
import requests
def get_price(coin_id):
response = requests.get(
f"https://api.coingecko.com/api/v3/simple/price?ids={coin_id}&vs_currencies=usd"
)
return response.json()[coin_id]["usd"]
price = get_price("bitcoin")
print(f"Bitcoin: ${price}")
This example uses a public price API; check the specific API's rate limits and terms of service for your usage volume.
Step 3 — Send a Telegram Notification
import requests
def send_telegram_message(bot_token, chat_id, message):
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
requests.post(url, data={"chat_id": chat_id, "text": message})
send_telegram_message("YOUR_BOT_TOKEN", "YOUR_CHAT_ID", f"Bitcoin: ${price}")
Step 4 — Set a Price Alert Threshold
THRESHOLD = 70000
price = get_price("bitcoin")
if price > THRESHOLD:
send_telegram_message(BOT_TOKEN, CHAT_ID, f"Bitcoin crossed ${THRESHOLD}! Current: ${price}")
Step 5 — Run on a Schedule with Cron
crontab -e
*/15 * * * * /usr/bin/python3 /home/user/price-bot.py
Checks the price every 15 minutes — adjust frequency based on your needs and the price API's rate limits.
Storing Price History
import sqlite3
from datetime import datetime
conn = sqlite3.connect('prices.db')
conn.execute('CREATE TABLE IF NOT EXISTS prices (timestamp TEXT, coin TEXT, price REAL)')
conn.execute('INSERT INTO prices VALUES (?, ?, ?)', (datetime.now().isoformat(), 'bitcoin', price))
conn.commit()
Visualizing Price History
For a simple dashboard displaying stored price history, see How to Set Up a Complete LAMP/LEMP Stack on Debian for the underlying web stack, or build a lightweight chart using a frontend charting library reading from your stored data.
Respecting API Rate Limits
Public price APIs typically have rate limits on free tiers — avoid polling too frequently, and check the specific API's documentation for current limits to avoid being temporarily blocked.
Important: This Is Not Financial Advice Infrastructure
A price ticker bot is an informational tool, not investment advice or an automated decision-making system — any actual trading decisions remain entirely your own responsibility.
Common Errors
API returns an error or empty response — verify the coin ID matches the API's expected identifier format exactly, and check if you've exceeded rate limits.
Telegram message doesn't send — verify the bot token and chat ID are correct, and that you've started a conversation with your bot at least once (required for the bot to message you).
Continue Reading
- How to Set Up systemd Timers as a Cron Alternative
- VPS for Trading Bots: What to Consider
- How to Install Python on Ubuntu & Debian
Browse more articles in Cryptocurrency & Blockchain Node Hosting.