Skip to content

K4nes/CryptoPriceBot

Repository files navigation

CryptoPriceBot

Telegram bot for getting live cryptocurrency prices from CoinMarketCap.

Setup

npm install
cp .env.example .env

Edit .env with your credentials:

Start the bot:

npm start

Run tests:

npm test

In Telegram, the slash command menu (descriptions for /start, /help, /price) is set automatically on startup. While a /price request is fetching data from CoinMarketCap, the bot may show a typing indicator. Very long answers are split across up to three messages so they stay within Telegram’s per-message length limit.

Commands

Get help with all commands

/help

Response shows all available commands and examples.

Get price of 1 crypto

/price BTC

Response:

1 BTC = $67000.00 USD (Bitcoin)
📈 24h: +2.5%

Get price of specific amount

/price 0.5 SOL

Response:

0.5 SOL = $42.00 USD (Solana)
📈 24h: +1.2%

Use crypto name instead of ticker

/price solana

Response:

1 SOL = $84.00 USD (Solana)
📈 24h: +1.2%

Convert to other currencies

/price 1 BTC -idr

Response:

1 BTC = $67000.00 USD (Bitcoin)
1 BTC = Rp 1072000000.00 IDR (Bitcoin)
📈 24h: +2.5%

Multiple crypto and currencies

/price 0.5 BTC -idr,eur
/price solana eth -usd

Ambiguous symbols (multiple matches)

When a symbol matches multiple tokens, the bot shows ranked options:

🔍 Top matches for "pros":
PROS (Prosper)
  30 PROS = $0.0197 USD
  📈 24h: +0.51%
  Rank: #1912
━━━━━━━━━━━━━━━━━━━━
PROS (Pharos)
  30 PROS = $0.7573 USD
  📈 24h: +0.51%
  Rank: #3723
━━━━━━━━━━━━━━━━━━━━

First-Time Users

/start sends a short welcome, then the same command help text as /help (format, flags, and examples).

Rate Limits

  • Bot: 10 requests per minute per user (configurable via env)
  • CMC API: varies by plan

Environment Variables

Variable Default Description
RATE_LIMIT 10 Max requests per user per window
RATE_WINDOW_SEC 60 Rate limit window in seconds
LOG_LEVEL INFO ERROR / WARN / INFO / DEBUG
TELEGRAM_BOT_TOKEN Telegram bot token (required)
CMC_API_KEY CoinMarketCap API key (required)

Logging

Set via LOG_LEVEL env var (default: INFO):

  • ERROR — Only errors
  • WARN — Errors + warnings
  • INFO — Errors, warnings, and startup/shutdown events
  • DEBUG — Everything including slow request traces

Logs written to logs/bot.log with 5MB rotation.

Format

/price <amount> <symbol> [-target_currency1,target_currency2]
Parameter Description
amount Number of crypto units (default: 1)
symbol Ticker (BTC, ETH) or name (bitcoin, solana)
-idr Convert to Indonesian Rupiah
-eur Convert to Euro
-gbp Convert to British Pound
-jpy Convert to Japanese Yen
-eth Convert to Ethereum
-btc Convert to Bitcoin
-usd Explicitly request USD (default)

Examples

/price btc              → 1 BTC = $67000 USD
/price 0.5 sol          → 0.5 SOL = $42 USD
/price solana -idr      → 1 SOL = $84 USD + IDR
/price bitcoin -eth     → 1 BTC = USD + ETH

About

Telegram bot for live crypto prices via the CoinMarketCap API. Multi-currency quotes, symbol/name resolution, and /price commands.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors