feat: Add simplified n8n workflow without secret validation

- New n8n-workflow-simple.json with 10 nodes (vs 13 in complete version)
- Direct flow: TradingView webhook → Parse → Risk check → Execute → Telegram
- No TradingView webhook secret validation (simpler setup)
- Updated guide to explain single API_SECRET_KEY authentication
- Customized for flow.egonetix.de webhook URL
- Clearer documentation of security model and testing steps
This commit is contained in:
mindesbunister
2025-10-23 16:04:52 +02:00
parent 4a9a80f045
commit 8ff5efbb6d
2 changed files with 339 additions and 34 deletions

View File

@@ -4,13 +4,24 @@ Complete guide to set up the automated trading workflow in n8n.
---
## 🔐 Security Model (Simplified)
This workflow uses **ONE secret** for authentication:
**API_SECRET_KEY** - Authenticates n8n → v4 Trading Bot API
- Set in `v4/.env` (generate with: `openssl rand -hex 32`)
- Set in n8n environment variables (must match v4)
- Used when calling `/api/trading/check-risk` and `/api/trading/execute`
**Your TradingView webhook** (`https://flow.egonetix.de/webhook/tradingview-webhook`) is directly accessible. If you need additional security, use `n8n-workflow-complete.json` which includes optional TradingView secret validation.
---
## 📋 Workflow Overview
```
TradingView Alert (Webhook)
Validate Secret
Parse Signal (SOL/BTC/ETH, LONG/SHORT)
Check Risk Limits (API call to /api/trading/check-risk)
@@ -22,16 +33,20 @@ Format Message (Success/Error/Blocked)
Send Telegram Notification
```
**Two workflow versions available:**
- `n8n-workflow-simple.json` - **Recommended** - Direct flow without secret validation
- `n8n-workflow-complete.json` - With optional TradingView webhook secret validation
---
## 🚀 Quick Setup
### Step 1: Import Workflow
1. Open your n8n instance
1. Open your n8n instance (e.g., https://flow.egonetix.de)
2. Click **"+ New Workflow"**
3. Click **"⋮"** (three dots) → **"Import from File"**
4. Select `n8n-workflow-complete.json`
4. Select `n8n-workflow-simple.json` (recommended) or `n8n-workflow-complete.json`
5. Click **"Import"**
### Step 2: Configure Environment Variables
@@ -39,19 +54,18 @@ Send Telegram Notification
In n8n, go to **Settings****Environment Variables** and add:
```bash
# Your trading bot API URL
# Your trading bot API URL (where v4 is running)
TRADING_BOT_API_URL=http://your-server:3000
# API secret key (must match .env in v4)
API_SECRET_KEY=your_secret_key_from_env
# TradingView webhook validation
TRADINGVIEW_WEBHOOK_SECRET=your_tradingview_secret
# API secret key (must match v4/.env)
API_SECRET_KEY=your_secret_key_from_v4_env
# Telegram credentials
TELEGRAM_CHAT_ID=your_telegram_chat_id
```
**Note:** `TRADINGVIEW_WEBHOOK_SECRET` is only needed if using `n8n-workflow-complete.json`
### Step 3: Configure Telegram Credentials
1. In n8n, click **"Telegram - Send Notification"** node
@@ -63,7 +77,7 @@ TELEGRAM_CHAT_ID=your_telegram_chat_id
1. Click **"Webhook - TradingView Alert"** node
2. Click **"Test URL"** or **"Production URL"**
3. Copy the webhook URL (looks like: `https://your-n8n.com/webhook/tradingview-webhook`)
3. Copy the webhook URL (should be: `https://flow.egonetix.de/webhook/tradingview-webhook`)
4. Save this for TradingView setup
### Step 5: Activate Workflow
@@ -84,18 +98,9 @@ TELEGRAM_CHAT_ID=your_telegram_chat_id
- **Response:** Return on Last Node
- **Raw Body:** Enabled
**What it does:** Receives TradingView alerts via webhook
**What it does:** Receives TradingView alerts directly via webhook
### Validate Secret Node
**Node:** `Validate Secret`
- **Type:** IF condition
- **Condition:** `{{$json.body.secret}} equals {{$env.TRADINGVIEW_WEBHOOK_SECRET}}`
**What it does:** Prevents unauthorized trade execution
**Important:** Make sure TradingView webhook includes `?secret=YOUR_SECRET` in URL
**Your webhook URL:** `https://flow.egonetix.de/webhook/tradingview-webhook`
### Parse TradingView Signal Node
@@ -106,7 +111,7 @@ TELEGRAM_CHAT_ID=your_telegram_chat_id
**What it does:**
- Extracts symbol, action, timeframe from TradingView alert
- Normalizes data for v4 API
- Normalizes data for v4 API (SOL→SOLUSDT, buy→long, etc.)
- Supports various TradingView alert formats
**Supported formats:**
@@ -225,12 +230,14 @@ Auto-exit at TP/SL levels.
### Alert Configuration
1. **In TradingView:** Right-click chart → Add Alert
2. **Condition:** Your indicator/strategy
2. **Condition:** Your indicator/strategy (e.g., Green Dot appears)
3. **Alert Name:** "SOL Long Signal" (or similar)
4. **Webhook URL:**
```
https://your-n8n.com/webhook/tradingview-webhook?secret=YOUR_SECRET
https://flow.egonetix.de/webhook/tradingview-webhook
```
**No secret parameter needed!** Just the direct webhook URL.
### Alert Message (JSON)
@@ -243,7 +250,6 @@ Use this format in the **Message** field:
"timeframe": "{{interval}}",
"price": "{{close}}",
"timestamp": "{{timenow}}",
"secret": "YOUR_TRADINGVIEW_SECRET",
"strategy": "5min_scalp",
"strength": "strong"
}
@@ -252,7 +258,8 @@ Use this format in the **Message** field:
**Important fields:**
- `symbol`: Stock/crypto symbol (SOLUSDT, BTCUSD, etc.)
- `action`: "buy"/"sell" or "long"/"short"
- `secret`: Must match `TRADINGVIEW_WEBHOOK_SECRET` in n8n env
- `timeframe`: Chart interval (5, 15, 60, etc.)
- `price`: Current price from TradingView
### Notification Settings
@@ -272,15 +279,14 @@ Use this format in the **Message** field:
```bash
# Send test webhook from command line
curl -X POST https://your-n8n.com/webhook/tradingview-webhook \
curl -X POST https://flow.egonetix.de/webhook/tradingview-webhook \
-H "Content-Type: application/json" \
-d '{
"symbol": "SOLUSDT",
"action": "buy",
"timeframe": "5",
"price": "140.25",
"timestamp": "2025-10-23T10:00:00Z",
"secret": "YOUR_SECRET"
"timestamp": "2025-10-23T10:00:00Z"
}'
```
@@ -325,7 +331,7 @@ You should receive a formatted Telegram message with trade details.
**Solutions:**
1. Check webhook is **Active** (toggle at top)
2. Verify webhook URL in TradingView matches n8n
2. Verify webhook URL in TradingView matches n8n: `https://flow.egonetix.de/webhook/tradingview-webhook`
3. Test with curl command (see Testing section)
4. Check n8n logs for errors
@@ -334,9 +340,8 @@ You should receive a formatted Telegram message with trade details.
**Problem:** "Unauthorized Webhook" message
**Solutions:**
1. Verify `secret` in TradingView alert matches `TRADINGVIEW_WEBHOOK_SECRET`
2. Check environment variable is set in n8n
3. Secret is case-sensitive!
- **Only applies if using `n8n-workflow-complete.json`**
- If using `n8n-workflow-simple.json`, this error won't occur
### API Authentication Failed