DEV Community

Ozor
Ozor

Posted on

How to Build a Crypto Price Alert Bot in Node.js (No Dependencies)

If you trade or hold crypto, you've probably wanted a simple way to get notified when prices move. Most alert services are either paid, require account signup, or are overkill for basic monitoring.

In this tutorial, we'll build a lightweight price alert bot in Node.js — zero dependencies, under 60 lines of code. It checks prices via a free API and sends alerts to Discord (or any webhook).

What We're Building

A script that:

  • Watches any crypto token (BTC, ETH, SOL, etc.)
  • Triggers alerts when price crosses your thresholds
  • Sends notifications via Discord webhook
  • Runs on a schedule with zero infrastructure

Step 1: Get an API Key

We need live crypto prices. Grab a free API key (200 credits, no credit card):

curl -X POST https://agent-gateway-kappa.vercel.app/api/keys/create
Enter fullscreen mode Exit fullscreen mode

Save the key from the response.

Step 2: The Alert Bot (60 Lines)

Create price-alerts.mjs:

const API_KEY = process.env.CRYPTO_API_KEY || "YOUR_KEY_HERE";
const DISCORD_WEBHOOK = process.env.DISCORD_WEBHOOK || "";
const BASE_URL = "https://agent-gateway-kappa.vercel.app";

// Define your alerts
const alerts = [
  { coin: "bitcoin",  above: 100000, below: 60000 },
  { coin: "ethereum", above: 3000,   below: 1500 },
  { coin: "solana",   above: 200,    below: 50 },
];

// Track which alerts fired (avoid spam)
const firedAlerts = new Set();

async function getPrice(coin) {
  const res = await fetch(
    `${BASE_URL}/v1/crypto-feeds/prices?coins=${coin}`,
    { headers: { Authorization: `Bearer ${API_KEY}` } }
  );
  const data = await res.json();
  const key = Object.keys(data.prices)[0];
  return {
    price: data.prices[key].price,
    change: data.prices[key].change_pct,
    symbol: key,
  };
}

async function sendAlert(message) {
  console.log(`ALERT: ${message}`);
  if (DISCORD_WEBHOOK) {
    await fetch(DISCORD_WEBHOOK, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ content: message }),
    });
  }
}

async function checkAlerts() {
  console.log(`[${new Date().toISOString()}] Checking prices...`);

  for (const alert of alerts) {
    try {
      const { price, change, symbol } = await getPrice(alert.coin);
      console.log(`  ${symbol}: $${price.toLocaleString()} (${change > 0 ? "+" : ""}${change}%)`);

      const aboveKey = `${alert.coin}-above-${alert.above}`;
      const belowKey = `${alert.coin}-below-${alert.below}`;

      if (price >= alert.above && !firedAlerts.has(aboveKey)) {
        firedAlerts.add(aboveKey);
        firedAlerts.delete(belowKey); // Reset opposite
        await sendAlert(
          `🚀 ${symbol} hit $${price.toLocaleString()} (above $${alert.above.toLocaleString()}) | ${change > 0 ? "+" : ""}${change}% today`
        );
      }
      if (price <= alert.below && !firedAlerts.has(belowKey)) {
        firedAlerts.add(belowKey);
        firedAlerts.delete(aboveKey);
        await sendAlert(
          `📉 ${symbol} dropped to $${price.toLocaleString()} (below $${alert.below.toLocaleString()}) | ${change}% today`
        );
      }
    } catch (err) {
      console.error(`  Error checking ${alert.coin}:`, err.message);
    }
  }
}

// Run every 5 minutes
checkAlerts();
setInterval(checkAlerts, 5 * 60 * 1000);
console.log("Price alert bot running. Checking every 5 minutes.");
Enter fullscreen mode Exit fullscreen mode

Step 3: Run It

export CRYPTO_API_KEY="gw_your_key_here"
export DISCORD_WEBHOOK="https://discord.com/api/webhooks/your/webhook"
node price-alerts.mjs
Enter fullscreen mode Exit fullscreen mode

Output:

Price alert bot running. Checking every 5 minutes.
[2026-03-05T21:00:00.000Z] Checking prices...
  BTCUSDT: $71,308 (-2.36%)
  ETHUSDT: $2,094 (-2.43%)
  SOLUSDT: $89 (-3.38%)
Enter fullscreen mode Exit fullscreen mode

Adding Percentage-Based Alerts

Want alerts when a coin moves more than X% in a day? Add this to the checkAlerts function:

// Percentage-based alerts
const PCT_THRESHOLD = 5; // Alert on 5%+ moves

for (const alert of alerts) {
  const { price, change, symbol } = await getPrice(alert.coin);
  const pctKey = `${alert.coin}-pct-${Math.floor(Math.abs(change))}`;

  if (Math.abs(change) >= PCT_THRESHOLD && !firedAlerts.has(pctKey)) {
    firedAlerts.add(pctKey);
    const direction = change > 0 ? "📈 surged" : "📉 crashed";
    await sendAlert(
      `${direction} ${symbol}: ${change > 0 ? "+" : ""}${change}% today ($${price.toLocaleString()})`
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

Running 24/7 with PM2

Install PM2 globally and keep your bot running:

npm install -g pm2
pm2 start price-alerts.mjs --name crypto-alerts
pm2 save
pm2 startup  # Auto-restart on reboot
Enter fullscreen mode Exit fullscreen mode

Check logs:

pm2 logs crypto-alerts --lines 20
Enter fullscreen mode Exit fullscreen mode

Running as a GitHub Action (Free)

If you don't want to maintain a server, use GitHub Actions to check every 15 minutes:

# .github/workflows/price-check.yml
name: Crypto Price Check
on:
  schedule:
    - cron: '*/15 * * * *'  # Every 15 minutes
  workflow_dispatch:

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: node price-alerts.mjs
        env:
          CRYPTO_API_KEY: ${{ secrets.CRYPTO_API_KEY }}
          DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
Enter fullscreen mode Exit fullscreen mode

Sending Alerts to Slack Instead

Replace the Discord webhook with a Slack webhook — the format is slightly different:

async function sendAlert(message) {
  console.log(`ALERT: ${message}`);
  if (SLACK_WEBHOOK) {
    await fetch(SLACK_WEBHOOK, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ text: message }),
    });
  }
}
Enter fullscreen mode Exit fullscreen mode

API Cost

Each price check costs 1 credit. With 200 free credits:

  • Checking 3 coins every 5 minutes = ~3 credits/hour
  • That's 66 hours of monitoring on the free tier
  • Top up with USDC on Base for unlimited monitoring

The full script is under 60 lines, has zero dependencies, and works with any crypto token. The API returns 500+ tokens including all major pairs, DeFi tokens, and meme coins.

Get your free API key: agent-gateway-kappa.vercel.app

Top comments (0)