Files
trading_bot_v4/TELEGRAM_STATUS_IMPLEMENTATION.md
mindesbunister 97ba6a9856 feat: Add /status command to Telegram bot for position monitoring
- Implemented /status command handler in telegram_command_bot.py
- Shows real-time P&L, entry/current prices, TP/SL levels, position info
- Added TRADING_BOT_URL and API_SECRET_KEY environment variables
- Updated docker-compose.telegram-bot.yml with new env vars
- Bot connects to trading-bot-v4:3000 API via internal Docker network
- Added comprehensive documentation and testing guides
- Command displays formatted position info with emojis (profit/loss indicators)
- Shows 'No open positions' message when no trades active
2025-10-27 12:40:10 +01:00

3.8 KiB

Telegram /status Command - Implementation Summary

Feature Complete

You can now send /status in your Telegram channel to get real-time information about your open position on Drift Protocol.


📊 What You'll See

When No Position Is Open:

📊 No open positions

All clear! Ready for new signals.

When You Have an Open Position:

🟢 SOL-PERP 📈 LONG

💰 P&L: $3.50 (+0.70% account)
📊 Price Change: +0.07%

Entry: $142.5000
Current: $142.6000

Targets:
  TP1: $143.4975 ✅  (if hit)
  TP2: $144.6375 ⏳
  SL: $140.3625

Position: $500.00 @ 10x
Age: 5 min

Legend:

  • 🟢 = Profit | 🔴 = Loss | = Breakeven
  • 📈 = Long | 📉 = Short
  • = Target hit | = Pending

🚀 How to Use

  1. Open your Telegram bot chat
  2. Send: /status
  3. Get instant position info!

You can send it anytime - while trading, after hours, whenever you want to check your position.


🔧 What Changed

Files Modified:

  1. telegram_command_bot.py

    • Added status_command() function
    • Fetches data from trading bot API
    • Formats beautiful status messages
  2. docker-compose.telegram-bot.yml

    • Added TRADING_BOT_URL environment variable
    • Added API_SECRET_KEY environment variable
  3. .env.telegram-bot

    • Added trading bot URL (internal Docker network)
    • Added API secret key for authentication

New Environment Variables:

TRADING_BOT_URL=http://trading-bot-v4:3000
API_SECRET_KEY=2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb

Verification

Container Status:

docker ps | grep telegram-trade-bot
# Output: Up About a minute

Bot Logs:

docker logs telegram-trade-bot --tail 10
# Shows: ✅ Commands: /status - Show open positions

API Connectivity Test:

docker exec telegram-trade-bot python3 -c "import requests; r=requests.get('http://trading-bot-v4:3000/api/trading/positions', headers={'Authorization': 'Bearer 2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb'}); print(r.status_code)"
# Output: 200 ✅

🎯 Live Example Use Cases

Morning Check:

You: /status
Bot: 🟢 SOL-PERP 📈 LONG
     💰 P&L: $8.25 (+1.65% account)
     TP1: $143.50 ✅
     Runner position active!

During Volatile Move:

You: /status
Bot: 🔴 SOL-PERP 📈 LONG
     💰 P&L: -$3.75 (-0.75% account)
     Current: $141.80
     SL: $140.36 (still safe!)

Multiple Times Per Day:

  • Check before meetings
  • Monitor during lunch
  • Quick check before bed
  • Anytime you're curious!

🔐 Security

Only works in YOUR Telegram chat (TELEGRAM_CHAT_ID=579304651)
Requires API authentication (API_SECRET_KEY)
Internal Docker network (not exposed to internet)
Same security as main trading bot


📝 Available Commands

Your Telegram bot now supports:

Command Description
/status Show current open position
/buySOL Open long SOL position
/sellSOL Open short SOL position
/buyBTC Open long BTC position
/sellBTC Open short BTC position
/buyETH Open long ETH position
/sellETH Open short ETH position

🎉 Ready to Use!

Your Telegram bot is running and ready. Just send /status to try it out!

Container: telegram-trade-bot Running
Network: Connected to trading-bot-v4
API: Authenticated and tested
Commands: /status handler active


📚 Documentation Updated

  • TELEGRAM_BOT_README.md - Updated with /status usage
  • TEST_STATUS_COMMAND.md - Testing guide
  • TELEGRAM_STATUS_IMPLEMENTATION.md - This file

Next time you open a position, send /status to see it in action! 🚀