- 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
2.4 KiB
2.4 KiB
Testing the /status Command
✅ Feature Implemented
The Telegram bot now supports the /status command to show current open positions.
What It Shows
When you send /status in your Telegram chat, you'll receive:
If No Positions Are Open:
📊 No open positions
All clear! Ready for new signals.
If Position Is Open:
🟢 SOL-PERP 📈 LONG
💰 P&L: $3.50 (+0.70% account)
📊 Price Change: +0.07%
Entry: $142.5000
Current: $142.6000
Targets:
TP1: $143.4975 ⏳
TP2: $144.6375
SL: $140.3625
Position: $500.00 @ 10x
Age: 5 min
Emojis Used:
- 🟢 Green = Position in profit
- 🔴 Red = Position in loss
- ⚪ White = Breakeven
- 📈 = Long position
- 📉 = Short position
- ✅ = Target hit
- ⏳ = Target pending
Technical Details
How It Works:
- User sends
/statusin Telegram - Bot calls
GET /api/trading/positionson trading-bot-v4:3000 - Bot parses response and formats position data
- Bot sends formatted message back to user
Files Modified:
telegram_command_bot.py- Addedstatus_command()handlerdocker-compose.telegram-bot.yml- Added environment variables.env.telegram-bot- AddedTRADING_BOT_URLandAPI_SECRET_KEY
Environment Variables Required:
TRADING_BOT_URL=http://trading-bot-v4:3000
API_SECRET_KEY=<same as main .env file>
Testing
1. Test from Terminal (API):
curl -H "Authorization: Bearer YOUR_API_SECRET_KEY" \
http://localhost:3001/api/trading/positions | jq .
2. Test from Telegram:
- Open your Telegram bot chat
- Send:
/status - Should receive position info or "No open positions"
3. Test with Active Position:
- Execute a test trade first:
- Send
/buySOLor use settings page "Test LONG"
- Send
- Then send
/status - Should see full position details
Verification
✅ Container running:
docker ps | grep telegram-trade-bot
✅ Logs showing /status handler:
docker logs telegram-trade-bot --tail 20
✅ Network connectivity:
docker exec telegram-trade-bot python3 -c "import requests; r=requests.get('http://trading-bot-v4:3000/api/trading/positions', headers={'Authorization': 'Bearer YOUR_KEY'}); print(r.status_code)"
Should output: 200
Next Steps
You can now monitor your positions in real-time from your phone!
Just send /status anytime to check:
- Current P&L
- How close you are to TP/SL
- How long the trade has been open