Organization: - Created docs/ with setup/, guides/, history/ subdirectories - Created workflows/ with trading/, analytics/, telegram/, archive/ subdirectories - Created scripts/ with docker/, setup/, testing/ subdirectories - Created tests/ for TypeScript test files - Created archive/ for unused reference files Moved files: - 17 documentation files → docs/ - 16 workflow JSON files → workflows/ - 10 shell scripts → scripts/ - 4 test files → tests/ - 5 unused files → archive/ Updated: - README.md with new file structure and documentation paths Deleted: - data/ (empty directory) - screenshots/ (empty directory) Critical files remain in root: - telegram_command_bot.py (active bot - used by Dockerfile) - watch-restart.sh (systemd service dependency) - All Dockerfiles and docker-compose files - All environment files Validation: Containers running (trading-bot-v4, telegram-trade-bot, postgres) API responding (positions endpoint tested) Telegram bot functional (/status command tested) All critical files present in root No code changes - purely organizational. System continues running without interruption. Recovery: git revert HEAD or git reset --hard cleanup-before
5.1 KiB
5.1 KiB
n8n Trading Bot v4 Workflow - Setup Instructions
Step 1: Create API Credential in n8n
- Go to n8n → Credentials → New Credential
- Search for "Header Auth"
- Configure:
- Name:
Trading Bot API Key - Name (field):
Authorization - Value:
Bearer 2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb
- Name:
- Click Save
Step 2: Update Your Telegram Credential
Make sure your Telegram Bot credential exists in n8n:
- Credential Name:
Telegram Bot - Chat ID:
579304651(or change in workflow to your ID)
Step 3: Import the Workflow
- Download:
/home/icke/traderv4/n8n-complete-workflow.json - Go to n8n → Workflows → Import from File
- Select the downloaded JSON file
- Click Import
Step 4: Configure Credentials
After importing, update the credential references:
For "Check Risk" and "Execute Trade" nodes:
- Click on the node
- Under Authentication → Credential for Header Auth
- Select:
Trading Bot API Key(the one you created in Step 1)
For all Telegram nodes:
- Click on each Telegram node
- Under Credential for Telegram API
- Select your Telegram Bot credential
Step 5: Test the Webhook
- Activate the workflow
- Get the webhook URL (shown in the Webhook node)
- Test with curl:
curl -X POST "https://your-n8n-instance.com/webhook/tradingview-bot-v4" \\
-H "Content-Type: application/json" \\
-d '{"body": "Buy SOL | Entry: 140.50"}'
Workflow Flow
TradingView Alert
↓
[Webhook] Receives signal
↓
[Parse Signal] Extracts data (symbol, direction, timeframe)
↓
[Check Risk] Validates trade (API call)
↓
[Risk Passed?] Decision
↓ ↓
YES NO
↓ ↓
[Execute Trade] [Risk Blocked Message]
↓
[Trade Success?] Decision
↓ ↓
SUCCESS FAILED
↓ ↓
[Success Msg] [Error Msg]
Expected Telegram Notifications
Success Message:
🟢 TRADE OPENED SUCCESSFULLY
Buy SOL | Entry: 140.50
📊 Symbol: SOL-PERP
📈 Direction: LONG
💰 Entry: $140.5000
💵 Size: $500.00
⚡ Leverage: 10x
🎯 Take Profit:
TP1: $141.48 (+0.7%)
TP2: $142.63 (+1.5%)
🛑 Stop Loss:
SL: $138.39 (-1.5%)
📊 Slippage: 0.023%
⏰ 14:32
✅ Position monitored automatically
🤖 Auto-exit at TP/SL levels
Risk Blocked Message:
⚠️ TRADE BLOCKED - RISK LIMITS
Buy SOL | Entry: 140.50
📊 Symbol: SOL-PERP
📈 Direction: LONG
🛑 Reason: Daily drawdown limit reached
📝 Details: Check risk management settings
⏰ 14:32
✅ Trade will be allowed when conditions improve
Error Message:
🔴 TRADE EXECUTION FAILED
Buy SOL | Entry: 140.50
📊 Symbol: SOL-PERP
📈 Direction: LONG
❌ Error: Drift wallet not configured
⏰ 14:32
⚠️ Check bot logs:
docker logs trading-bot-v4 --tail=50
TradingView Alert Format
Your TradingView alerts should send data in this format:
Simple format (recommended):
Buy SOL | Entry: 140.50
or
Sell BTC | Entry: 67890.00
The workflow will automatically detect:
- Symbol: SOL, BTC, ETH (defaults to SOL if not found)
- Direction: Buy/Long → long, Sell/Short → short
- Timeframe: Fixed at 5 minutes
API Endpoints Used
-
Risk Check:
http://10.0.0.48:3001/api/trading/check-risk- Method: POST
- Body:
{"symbol": "SOL-PERP", "direction": "long"}
-
Execute Trade:
http://10.0.0.48:3001/api/trading/execute- Method: POST
- Body:
{"symbol": "SOL-PERP", "direction": "long", "timeframe": "5", "signalStrength": "strong"}
Troubleshooting
"Connection refused" error:
- Check if trading bot is running:
docker ps | grep trading-bot - Verify the bot is accessible:
curl http://10.0.0.48:3001/api/trading/positions
"Unauthorized" error:
- Check API key credential is set correctly
- Verify the Bearer token format:
Bearer <your-api-key>
Telegram not sending:
- Verify your Telegram bot token is valid
- Check chat ID is correct (must be a number)
- Test Telegram node independently
No response from webhook:
- Make sure workflow is activated
- Check webhook path matches your TradingView alert
- Verify n8n is accessible from TradingView
Quick Commands
# Check bot status
docker ps | grep trading-bot
# View bot logs
docker logs trading-bot-v4 --tail=50 -f
# Test API directly
curl -X POST http://10.0.0.48:3001/api/trading/check-risk \\
-H "Authorization: Bearer 2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb" \\
-H "Content-Type: application/json" \\
-d '{"symbol":"SOL-PERP","direction":"long"}'
# Check active positions
curl http://localhost:3001/api/trading/positions \\
-H "Authorization: Bearer 2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb"
Next Steps
- ✅ Import workflow
- ✅ Configure credentials
- ✅ Activate workflow
- ⚠️ Configure Drift wallet in trading bot (see main README.md)
- 🚀 Set up TradingView alerts
- 💰 Start trading!