Development of a Telegram Bot for Crypto Portfolio Monitoring
A typical scenario: a trader has assets scattered across 5–10 networks – in Uniswap liquidity pools, Lido staking, Aave lending. To assess total exposure and liquidation risks, they have to open 6 tabs and collect data manually. Our Telegram bot aggregates data from all networks in real time: it shows a unified portfolio, customizable alerts, and critical events. The solution pays for itself within a week if it prevents even one liquidation over $1000 – that's the savings our users report. Additionally, our bot replaces paid monitoring services costing up to $100/month – you get the same data without a monthly subscription. Our team has 5+ years of blockchain development experience and has completed 50+ monitoring projects. Contact us – we'll test the bot on your wallets for free and show you how it works.
Problems We Solve
Data Fragmentation Across Networks
Each network requires a separate RPC or API key. We connect Ethereum, Polygon, Arbitrum, Optimism, Base, and BNB Chain via Moralis Web3 API for token balances and DeBank API for DeFi positions. For Bitcoin and Solana, we use separate adapters. All data is collected asynchronously using asyncio.gather. The bot response time is under 2 seconds even with 50+ wallets.
Delay in Price Alerts
Polling prices every 10 seconds is expensive and inaccurate. Instead, we subscribe to Binance and Bybit WebSocket streams (free) for the top 100 coins. For others, we use Chainlink price feed events. No price movement is missed: alerts arrive within 1–2 seconds. WebSocket alerts are 10 times faster than polling every 10 seconds.
Monitoring Health Factor in Lending Protocols
The Aave health factor depends on collateral and debt prices. We track it via contract events (Alchemy webhook) on any change, as well as periodic checks on price moves. If the HF drops below 1.2, an automatic alert with recommended actions is sent.
How to Set Up a Health Factor Alert?
Step-by-step guide for the built-in /addalert command:
- Choose
health_factorfrom the suggestions. - Enter the wallet address that has already been added via
/addwallet. - Set a threshold, e.g., 1.2.
- Select the protocol (Aave V3, Compound V3). The bot automatically identifies active positions and starts monitoring. When HF changes, the bot sends a message with the current value and a link to Etherscan.
Bot Architecture
Telegram Bot API (polling/webhook) ↓ Bot handler (aiogram 3.x, Python 3.11) ↓ Portfolio aggregator service ├── Price service (Binance WebSocket + CoinGecko REST) ├── Balance fetcher (Moralis Balance API / Alchemy Token API) ├── DeFi positions (DeBank API + direct calls to Aave/Compound) └── Event listener (Alchemy webhooks for on-chain events) ↓ Database (PostgreSQL + Redis cache) ├── user wallets (public addresses) ├── alert configurations └── cached portfolio snapshots (TTL: prices 30s, balances 2-5 min) ↓ Alert scheduler (APScheduler cron + event-driven triggers) Redis is critical for caching: each /portfolio request doesn't hit external APIs but retrieves data from cache. This reduces load on third-party services and speeds up responses 3–5 times.
Data Source Comparison
| Source | Data Type | Cost | Limits | Latency |
|---|---|---|---|---|
| Moralis Balance API | ERC-20 balances | Up to 40k req/day free | 100 wallets/request | ~1s |
| Alchemy Token API | ERC-20 balances | Free (300M CU/month) | 3 req/s | ~0.5s |
| DeBank API | DeFi positions | Free (100k req/day) | 1 req/s | ~2s |
| Zerion API | DeFi positions | Paid (from $49/month) | Per plan | ~1s |
| Binance WebSocket | Prices | Free | 1024 streams | real-time |
| Chainlink price feed | On-chain prices | Free (via node) | ~$0.05/request | ~1 block |
Choosing Moralis and Alchemy over paid Zerion saves up to $50/month on data connections.
Alert Types
| Alert Type | Example Setting | Latency |
|---|---|---|
| Price change | BTC -5% in 1 hour | 1-2 sec |
| Health factor | Aave HF < 1.2 | ~1 block |
| Large transaction | > $100k from wallet | real-time |
| Whale movement | address from watchlist sent > $50k | real-time |
| New token | unknown ERC-20 arrived at wallet | 1-2 sec |
How We Do It: Stack and Implementation
Stack: Python 3.11 + aiogram 3.x + asyncio. For each user we store a list of wallets in PostgreSQL (one query per command). The aggregator collects data in parallel:
async def get_portfolio(wallets: list[str]) -> Portfolio: async with asyncio.TaskGroup() as tg: balance_task = tg.create_task(balance_fetcher.fetch_all(wallets)) defi_task = tg.create_task(defi_fetcher.fetch_all(wallets)) price_task = tg.create_task(price_service.fetch_prices()) return Portfolio(balances=balance_task.result(), positions=defi_task.result(), usd_values=price_task.result()) Output formatting – HTML with emojis, tables, Etherscan links. Example:
/portfolio Your portfolio (updated 2 sec ago): **Ethereum** ETH: 2.345 ($7,850) ↗ 1.2% USDC: 15,000.00 ($15,000) ▸ 0% Aave: deposit 10 ETH, debt 5,000 USDC, Health Factor: 1.45 **Polygon** MATIC: 5000 ($4,200) ↗ 3.1% Uniswap V3: MATIC/USDC (0.05%) — $2,300 Why Security Takes Center Stage?
The bot works only with public addresses. The user never enters private keys or seed phrases. During onboarding we explicitly state: 'No private data.' If the bot detects an attempt to enter text resembling a private key (64 hex chars or 12/24 words) – the command is ignored, and the user receives a warning. Addresses are stored in an encrypted column in PostgreSQL. For rate limiting – aiogram-level rate limiting: no more than 30 commands/min per user.
At each step, we use proven solutions: for example, Chainlink documentation for price feeds or official Aave contracts for HF. This ensures reliability, backed by hundreds of audits.
Work Process for an Order
- Analysis – discuss which networks, protocols, alerts are needed. 2. Architecture design – choose data sources, providers, caching. 3. Bot implementation – Python/aiogram, Telegram Bot API integration, API and WebSocket connections. 4. Testing – unit tests on command handlers, integration tests with API mocks, stress test with 100+ wallets. 5. Deployment – on Railway, Fly.io, or your VPS with Docker. We provide documentation and operation instructions.
What's Included
- Base:
/addwallet,/removewallet,/portfolio,/alertscommands. - Alerts for price, health factor, large transactions.
- Support for all EVM chains (Bitcoin/Solana – optional).
- Redis caching for fast response.
- Admin and deployment documentation.
- Guarantee of functionality and modifications within one month after delivery.
Estimated Timeline
Basic version – from 2 to 3 business days. Extended version with DeFi positions and WebSocket – from 5 to 10 days. Cost is calculated individually after requirements analysis. Contact us to discuss your scenario – we'll select the optimal architecture. Order your Telegram bot for crypto portfolio monitoring – get a consultation on your case.
Example code for the /portfolio command (full version)
@router.message(Command("portfolio")) async def portfolio_command(message: Message): user = await get_user(message.from_user.id) if not user.wallets: await message.answer("First add a wallet with /addwallet 0x...") return async with asyncio.TaskGroup() as tg: pf = tg.create_task(aggregator.get_portfolio(user.wallets)) prices = tg.create_task(price_service.get_all_prices()) portfolio = pf.result() text = format_portfolio(portfolio, prices.result()) await message.answer(text, parse_mode="HTML") Order your Telegram bot for crypto portfolio monitoring – get a consultation on your case.







