In the fast-moving world of cryptocurrency, prices can change in the blink of an eye. Checking your smartphone every 5 minutes isn't just exhausting—it's a productivity killer that leads to "chart fatigue" and emotional trading. Why not build a personal bot that stays awake while you work, alerting you only when it actually matters?
Today, we will create a high-speed Price Alert Bot. It uses the free public API from CoinGecko to fetch real-time prices for Bitcoin (or any other coin) and prints a notification to your console if the price hits your target. No complicated dashboards, no trading fees—just clean Python code that you can customize in minutes.
Why Python is the King of Crypto Automation
If you're wondering why we're using Python instead of just using a mobile app, the answer is extensibility. A mobile app tells you what it wants you to know. A Python script tells you exactly what you want to know. With libraries like requests and ccxt, you can go from a simple alert bot to a fully automated high-frequency trading bot with just a few more lines of code.
Python's readability makes it the perfect language for finance. When you're dealing with live market data and potentially your own money, you want code that is easy to debug and simple to audit at a glance.
The API Choice: Why CoinGecko?
For this tutorial, we are using the CoinGecko API. Unlike Binance or Coinbase, CoinGecko doesn't require an API key for its public "simple" price endpoint. This means you can get started instantly without signing up or managing secret keys. It's the most frictionless way to get data for over 10,000 coins.
However, keep in mind that the free tier has a rate limit (around 10-30 calls per minute). For a simple alert bot that checks every minute, this is more than enough. If you need sub-second updates, you'll eventually need to look into websockets or a paid Pro key.
Prerequisites: Getting Ready
To follow along, you only need the requests library to handle HTTP API calls. If you haven't installed it yet, open your terminal and run:
import requests
import time
# ⚙️ Configuration
COIN_ID = 'bitcoin' # Try 'ethereum', 'solana', or 'cardano'
CURRENCY = 'usd' # Change to 'idr', 'eur', or 'gbp' if needed
THRESHOLD = 65000 # The price that triggers the alert
def get_current_price(coin_id, currency):
"""Fetches the latest price from CoinGecko API"""
url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_id}&vs_currencies={currency}"
try:
response = requests.get(url)
response.raise_for_status() # Check for HTTP errors
data = response.json()
return data[coin_id][currency]
except Exception as e:
print(f"❌ Error fetching price: {e}")
return None
def main():
print(f"🚀 Starting Price Alert Bot for {COIN_ID.upper()}...")
print(f"Target Alert: Send notification if price is below ${THRESHOLD}")
while True:
price = get_current_price(COIN_ID, CURRENCY)
if price:
current_time = time.strftime("%H:%M:%S")
print(f"[{current_time}] {COIN_ID.upper()}: ${price}")
if price < THRESHOLD:
print("⚠️ ALERT: PRICE DROPPED BELOW TARGET!")
# INSERT NOTIFICATION LOGIC HERE
# Wait for 60 seconds to avoid hitting rate limits
time.sleep(60)
if __name__ == "__main__":
main()Adding Real-World Value: Telegram Alerts
Printing an alert to your terminal is fine, but what if you're not at your desk? You can integrate the Telegram Bot API in less than 5 minutes to send alerts directly to your phone.
1. Talk to @BotFather on Telegram to create a bot and get your API_TOKEN.
2. Get your CHAT_ID using @userinfobot.
3. Add this simple function to your script:
def send_telegram_alert(message):
bot_token = 'YOUR_API_TOKEN'
chat_id = 'YOUR_CHAT_ID'
url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={message}"
requests.get(url)
Now, instead of just printing to the console, your bot will ping your phone whenever the market makes a move!
Handling Errors Like a Pro
In a real production environment, you don't want your bot to crash if your Wi-Fi hiccups or the API is momentarily down. That's why we use a try...except block and response.raise_for_status(). This ensures that even if one request fails, the bot continues to retry in the next loop instead of dying silently.
Frequently Asked Questions
Can I track multiple coins at once?
Yes! You can pass a comma-separated string to the ids parameter in the URL (e.g., ids=bitcoin,ethereum,solana). You would then need to loop through the JSON response to check the price for each coin.
Will this bot get me banned from CoinGecko?
Not if you are reasonable. A check every 60 seconds is completely within their fair-use policy. However, if you try to check every 0.1 seconds from a free account, your IP will eventually be blocked. Always be respectful of free public APIs.
What happens if Bitcoin is exactly at the threshold?
In our code, we use if price < THRESHOLD, so it only triggers if the price is strictly lower. You can change this to <= if you want it to trigger exactly at that level. In trading, we call this the "Limit Trigger."
"Data is the new oil, but automation is the engine that actually makes it valuable."
The Bottom Line
Building your own tools isn't just about saving money on app subscriptions; it's about gaining total control over your data. With this 1-minute bot, you've taken the first step toward building a custom trading workstation that works for you 24/7. Happy coding!
Disclaimer: "All content is for educational use only. Trading is high risk. Not financial advice."