Files
trading_bot_v4/TEST_STATUS_COMMAND.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

111 lines
2.4 KiB
Markdown

# 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:
1. User sends `/status` in Telegram
2. Bot calls `GET /api/trading/positions` on trading-bot-v4:3000
3. Bot parses response and formats position data
4. Bot sends formatted message back to user
### Files Modified:
- `telegram_command_bot.py` - Added `status_command()` handler
- `docker-compose.telegram-bot.yml` - Added environment variables
- `.env.telegram-bot` - Added `TRADING_BOT_URL` and `API_SECRET_KEY`
### Environment Variables Required:
```bash
TRADING_BOT_URL=http://trading-bot-v4:3000
API_SECRET_KEY=<same as main .env file>
```
## Testing
### 1. Test from Terminal (API):
```bash
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 `/buySOL` or use settings page "Test LONG"
- Then send `/status`
- Should see full position details
## Verification
✅ Container running:
```bash
docker ps | grep telegram-trade-bot
```
✅ Logs showing /status handler:
```bash
docker logs telegram-trade-bot --tail 20
```
✅ Network connectivity:
```bash
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