Build a Crypto Price Alert System with Telegram and AWS Lambda

Introduction

In this guide, we’ll create a lightweight crypto price alert system that sends notifications via Telegram when a cryptocurrency’s price crosses a user-defined threshold. Leveraging AWS Lambda, this solution is cost-effective and scalable.

👉 Explore more crypto tools here


Why a Price Alert System Matters

  • Time-Saving: Avoid manual price tracking.
  • Stress Reduction: Automate sell/buy triggers.
  • Customizable: Set alerts for any cryptocurrency and threshold.

Core Components

1. Defining a Price Alert

A price alert includes:
id: Unique identifier.
asset: Cryptocurrency symbol (e.g., ethereum).
targetPrice: Trigger price (e.g., $4,000).
condition: “more” (price ≥ target) or “less” (price ≤ target).
isNotified: Prevents duplicate alerts.

typescript
type PriceAlertCondition = "more" | "less";
export type PriceAlert = {
asset: string;
targetPrice: number;
condition: PriceAlertCondition;
isNotified: boolean;
};

2. Database Management

Using DynamoDB, we handle CRUD operations:
getAllPriceAlerts: Fetch active alerts.
putPriceAlert: Add new alerts.
updatePriceAlert: Toggle isNotified status.

3. Fetching Prices

The CoinGecko API provides real-time data:

typescript
const getAssetPrices = async (ids: string[], currency = "usd") => {
const url = `https://api.coingecko.com/api/v3/simple/price?ids=${ids.join(",")}&vs_currencies=${currency}`;
const response = await fetch(url);
return response.json();
};

👉 Discover advanced crypto APIs


How It Works

  1. Set Alerts: Define thresholds (e.g., Ethereum ≤ $3,800).
  2. Check Prices: Lambda polls CoinGecko every 10 minutes.
  3. Send Alerts: Triggers Telegram notifications via node-telegram-bot-api.

typescript
if (price > targetPrice && condition === "more") {
await sendTelegramAlert(`${asset} is now above $${targetPrice}!`);
}


Deployment

AWS Lambda Setup

  1. Environment Variables: Store TELEGRAM_BOT_TOKEN, CHAT_ID, and DYNAMODB_TABLE.
  2. Scheduling: Use CloudWatch Events to run hourly.

Terraform Scripts

Automate resource provisioning:
hcl
resource "aws_lambda_function" "price_watcher" {
function_name = "crypto-alerts"
handler = "index.handler"
runtime = "nodejs18.x"
}


FAQs

1. How often does the system check prices?

The Lambda runs every 10 minutes via CloudWatch.

2. Can I add multiple cryptocurrencies?

Yes! Extend the asset field in alerts (e.g., bitcoin, solana).

3. Is this system free to run?

AWS Lambda offers 1M free monthly requests; CoinGecko’s free tier supports 50 calls/minute.

4. How do I customize notifications?

Modify sendPriceChangeAlert() to include emojis or price charts.

5. What if I miss an alert?

Alerts persist until the price reverts below/above the threshold.


Conclusion

This Telegram + AWS Lambda solution automates crypto price tracking with minimal code. Whether you’re a trader or long-term holder, instant alerts help you act swiftly.

👉 Start building your alert system today

Next Steps:
– Add multi-user support.
– Integrate with Slack/Discord.
– Implement historical price analysis.

Happy coding! 🚀