Skip to main content
This tutorial will guide you through building a real-time price monitoring bot from scratch that automatically sends Telegram notifications when target token price changes exceed a set threshold.
Estimated Time: 30 minutes
Difficulty Level: ⭐⭐ Beginner

Objective

Build a bot that monitors token prices and sends automatic notifications: Feature Checklist:
  • ✅ Subscribe to real-time price stream
  • ✅ Set price change trigger conditions (> X%)
  • ✅ Send Telegram notifications
  • ✅ Support multi-token monitoring

Tech Stack


Prerequisites

  • ChainStream account (to get Access Token)
  • Node.js 18+
  • Telegram Account

Step 1: Connect WebSocket

1.1 Install Dependencies

1.2 Create Project Structure

1.3 Configuration Files

.env:
config.js:

1.4 WebSocket Connection

index.js:

Step 2: Set Trigger Conditions

Trigger conditions are configured in config.js:

Advanced Trigger Conditions

Can be extended to more complex conditions:

Step 3: Send Notifications

3.1 Create Telegram Bot

1

Create Bot

Search for @BotFather in Telegram, send /newbot
2

Get Token

Follow prompts to create Bot, get Bot Token
3

Get Chat ID

  • Send a message to your Bot
  • Visit https://api.telegram.org/bot<TOKEN>/getUpdates
  • Find chat.id

3.2 Telegram Notification Module

bot.js:

Verify Installation

Run Bot

Expected Output

Trigger Test

Temporarily set threshold to 0.01% for quick testing:

Extension Suggestions


FAQ

  1. Check if Access Token is correct
  2. Confirm network can access ChainStream
  3. Check if firewall is blocking WebSocket
  1. Confirm Bot Token is correct
  2. Confirm Chat ID is correct
  3. Make sure you’ve sent a message to the Bot (activate conversation)
Add more configurations to the WATCH_TOKENS array in config.js.

WebSocket API

WebSocket subscription details

Webhook Fundamentals

Use Webhook instead of WebSocket