docs: Document 1-minute webhook fix and add setup instructions (Common Pitfall #80)
This commit is contained in:
323
docs/1MIN_ALERT_SETUP_INSTRUCTIONS.md
Normal file
323
docs/1MIN_ALERT_SETUP_INSTRUCTIONS.md
Normal file
@@ -0,0 +1,323 @@
|
||||
# ✅ 1-Minute Market Data Alert Setup (FIXED Dec 9, 2025)
|
||||
|
||||
## Issue Resolved
|
||||
|
||||
**Problem:** Telegram bot timing out waiting for fresh ATR data
|
||||
```
|
||||
⏳ Waiting for next 1-minute datapoint...
|
||||
Will execute with fresh ATR (max 60s)
|
||||
⚠️ Timeout waiting for fresh data
|
||||
Using preset ATR: 0.43
|
||||
```
|
||||
|
||||
**Root Cause:** TradingView alert sends `action: "market_data_1min"` but endpoint expected exact match `"market_data"`
|
||||
|
||||
**Fix:** Webhook now accepts both `"market_data"` and `"market_data_1min"` actions
|
||||
|
||||
**Status:** ✅ DEPLOYED Dec 9, 2025 19:18 CET (commit 9668349)
|
||||
|
||||
---
|
||||
|
||||
## TradingView Alert Configuration
|
||||
|
||||
### Step 1: Add Indicator to Chart
|
||||
|
||||
1. Open **SOL-PERP 1-minute chart** in TradingView
|
||||
2. Add indicator: **"1-Minute Market Data Feed"** (`1min_market_data_feed.pinescript`)
|
||||
3. Verify it's on the chart (shows ADX/ATR/RSI/Volume/Price Position table)
|
||||
|
||||
### Step 2: Create Alert
|
||||
|
||||
1. Click **Alert** button (clock icon) or press `Alt+A`
|
||||
2. **Condition:** Select "1min Market Data" from dropdown
|
||||
3. **Options:**
|
||||
- Trigger: **Once Per Bar Close** (fires every minute)
|
||||
- Expiration: Never (or set to 1 month)
|
||||
4. **Alert actions:**
|
||||
- Check: **Webhook URL**
|
||||
- URL: Your n8n webhook URL (e.g., `https://n8n.your-domain.com/webhook/trading-signal`)
|
||||
- Message: **Use default** (auto-filled from indicator)
|
||||
|
||||
### Step 3: Verify Alert Message
|
||||
|
||||
The alert should send this JSON (auto-generated by indicator):
|
||||
```json
|
||||
{
|
||||
"action": "market_data_1min",
|
||||
"symbol": "{{ticker}}",
|
||||
"timeframe": "1",
|
||||
"atr": 0.55,
|
||||
"adx": 28.5,
|
||||
"rsi": 62,
|
||||
"volumeRatio": 1.35,
|
||||
"pricePosition": 72,
|
||||
"currentPrice": 142.85,
|
||||
"timestamp": "{{timenow}}",
|
||||
"exchange": "{{exchange}}",
|
||||
"indicatorVersion": "v9"
|
||||
}
|
||||
```
|
||||
|
||||
**CRITICAL:** Verify `action` field says `"market_data_1min"` (endpoint now accepts this!)
|
||||
|
||||
### Step 4: Test Alert
|
||||
|
||||
**Manual Test:**
|
||||
```bash
|
||||
curl -X POST http://localhost:3001/api/trading/market-data \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"action": "market_data_1min",
|
||||
"symbol": "SOLUSDT",
|
||||
"timeframe": "1",
|
||||
"atr": 0.55,
|
||||
"adx": 28.5,
|
||||
"rsi": 62,
|
||||
"volumeRatio": 1.35,
|
||||
"pricePosition": 72,
|
||||
"currentPrice": 142.85
|
||||
}'
|
||||
```
|
||||
|
||||
**Expected Response:**
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"symbol": "SOL-PERP",
|
||||
"message": "Market data cached and stored successfully",
|
||||
"expiresInSeconds": 300
|
||||
}
|
||||
```
|
||||
|
||||
**Check Cache:**
|
||||
```bash
|
||||
curl http://localhost:3001/api/trading/market-data | jq '.cache."SOL-PERP"'
|
||||
```
|
||||
|
||||
**Expected Output:**
|
||||
```json
|
||||
{
|
||||
"symbol": "SOL-PERP",
|
||||
"atr": 0.55,
|
||||
"adx": 28.5,
|
||||
"rsi": 62,
|
||||
"volumeRatio": 1.35,
|
||||
"pricePosition": 72,
|
||||
"currentPrice": 142.85,
|
||||
"timestamp": 1765302277051,
|
||||
"timeframe": "1",
|
||||
"ageSeconds": 15
|
||||
}
|
||||
```
|
||||
|
||||
### Step 5: Verify in Telegram
|
||||
|
||||
Send `long sol` to Telegram bot. Should see:
|
||||
```
|
||||
⏳ Waiting for next 1-minute datapoint...
|
||||
Will execute with fresh ATR (max 60s)
|
||||
|
||||
✅ Fresh data received
|
||||
ATR: 0.55 | ADX: 28.5 | RSI: 62.0
|
||||
Executing LONG SOL...
|
||||
```
|
||||
|
||||
**NOT:**
|
||||
```
|
||||
⚠️ Timeout waiting for fresh data
|
||||
Using preset ATR: 0.43
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Alert Rate Limits
|
||||
|
||||
**Per Symbol:** 1 alert every minute = 60/hour
|
||||
**Total for 3 Symbols:** 180 alerts/hour
|
||||
|
||||
**TradingView Free Tier:**
|
||||
- 20 alert slots total
|
||||
- Unlimited alert fires
|
||||
- 1-minute alerts use 3 slots (SOL, ETH, BTC)
|
||||
|
||||
**Remaining Slots:** 17 for trading signals (v9, stop hunt, etc.)
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Issue: Telegram bot still timing out
|
||||
|
||||
**Check 1: Is alert active in TradingView?**
|
||||
- Go to Alerts panel
|
||||
- Look for "1min Market Data - SOL-PERP"
|
||||
- Status should be green (active)
|
||||
|
||||
**Check 2: Is webhook firing?**
|
||||
```bash
|
||||
docker logs trading-bot-v4 2>&1 | grep "Received market data webhook" | tail -5
|
||||
```
|
||||
|
||||
Expected:
|
||||
```
|
||||
📡 Received market data webhook: { action: 'market_data_1min', symbol: 'SOLUSDT', atr: 0.55, adx: 28.5 }
|
||||
✅ Market data cached for SOL-PERP
|
||||
```
|
||||
|
||||
If no logs: Alert not configured or webhook URL wrong
|
||||
|
||||
**Check 3: Is data in cache?**
|
||||
```bash
|
||||
curl -s http://localhost:3001/api/trading/market-data | jq '.availableSymbols'
|
||||
```
|
||||
|
||||
Expected: `["SOL-PERP"]` or `["SOL-PERP", "ETH-PERP", "BTC-PERP"]`
|
||||
|
||||
If empty: No data received in last 5 minutes
|
||||
|
||||
**Check 4: n8n webhook routing**
|
||||
- Verify n8n receives TradingView webhook
|
||||
- Check "Parse Signal Enhanced" node extracts action correctly
|
||||
- Verify routes to bot's `/api/trading/market-data` endpoint
|
||||
|
||||
### Issue: Cache shows stale data
|
||||
|
||||
**Symptoms:**
|
||||
```json
|
||||
{
|
||||
"ageSeconds": 350 // > 300 seconds (5 minutes)
|
||||
}
|
||||
```
|
||||
|
||||
**Cause:** Alert not firing every minute
|
||||
|
||||
**Fix:**
|
||||
1. Check alert condition: **Once Per Bar Close** (not "Only Once")
|
||||
2. Check alert is active (not paused/expired)
|
||||
3. Verify 1-minute chart is loaded in TradingView (alerts need chart open)
|
||||
|
||||
### Issue: Wrong ATR value
|
||||
|
||||
**Symptoms:** Telegram shows `ATR: 0.43` (preset) instead of fresh value
|
||||
|
||||
**Diagnosis:**
|
||||
```bash
|
||||
curl -s http://localhost:3001/api/trading/market-data | jq '.cache."SOL-PERP".atr'
|
||||
```
|
||||
|
||||
If returns `null` or old value: Alert not sending fresh ATR
|
||||
|
||||
**Fix:**
|
||||
1. Check TradingView alert message includes `"atr": {{ta.atr(14)}}`
|
||||
2. Verify indicator is on chart (calculates ATR)
|
||||
3. Re-create alert with fresh message template
|
||||
|
||||
---
|
||||
|
||||
## File Locations
|
||||
|
||||
**TradingView Indicator:**
|
||||
```
|
||||
workflows/trading/1min_market_data_feed.pinescript
|
||||
```
|
||||
|
||||
**Webhook Endpoint:**
|
||||
```
|
||||
app/api/trading/market-data/route.ts
|
||||
```
|
||||
|
||||
**Market Data Cache:**
|
||||
```
|
||||
lib/trading/market-data-cache.ts
|
||||
```
|
||||
|
||||
**Telegram Bot Logic:**
|
||||
```
|
||||
telegram_command_bot.py
|
||||
Lines 775-825: Fresh data waiting logic
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Git Commits
|
||||
|
||||
**Fix:**
|
||||
- 9668349 - "fix: Accept market_data_1min action in webhook endpoint" (Dec 9, 2025)
|
||||
|
||||
**Previous Related:**
|
||||
- 2a1badf - "critical: Fix Smart Validation Queue - restore signals from database on startup" (Dec 9, 2025)
|
||||
|
||||
---
|
||||
|
||||
## Expected Behavior After Setup
|
||||
|
||||
### Manual Telegram Trade Flow
|
||||
|
||||
```
|
||||
User: long sol
|
||||
|
||||
Bot: ⏳ Waiting for next 1-minute datapoint...
|
||||
Will execute with fresh ATR (max 60s)
|
||||
|
||||
[Wait 0-60 seconds for next TradingView alert]
|
||||
|
||||
Bot: ✅ Fresh data received
|
||||
ATR: 0.5543 | ADX: 28.5 | RSI: 62.0
|
||||
Executing LONG SOL...
|
||||
|
||||
Bot: ✅ OPENED LONG SOL
|
||||
Entry: $142.8394
|
||||
Size: $2224.44 @ 10x
|
||||
TP1: $143.69 (ATR-based, fresh data!)
|
||||
TP2: $144.55
|
||||
SL: $141.54
|
||||
```
|
||||
|
||||
**Key Indicators Fix is Working:**
|
||||
1. ✅ "Fresh data received" message appears
|
||||
2. ✅ ATR value matches current volatility (not preset 0.43)
|
||||
3. ✅ Wait time < 60 seconds (data available)
|
||||
4. ✅ TP/SL calculated from fresh ATR
|
||||
|
||||
---
|
||||
|
||||
## Monitoring
|
||||
|
||||
**Check alert is firing every minute:**
|
||||
```bash
|
||||
# Watch webhook hits in real-time
|
||||
docker logs -f trading-bot-v4 2>&1 | grep "market data webhook"
|
||||
```
|
||||
|
||||
**Check cache freshness:**
|
||||
```bash
|
||||
# Data age should be < 60 seconds
|
||||
watch -n 5 'curl -s http://localhost:3001/api/trading/market-data | jq ".cache.\"SOL-PERP\".ageSeconds"'
|
||||
```
|
||||
|
||||
**Check database storage:**
|
||||
```sql
|
||||
-- Query last 10 market data points
|
||||
docker exec trading-bot-postgres psql -U postgres -d trading_bot_v4 -c \
|
||||
"SELECT symbol, timeframe, atr, adx,
|
||||
TO_CHAR(timestamp, 'HH24:MI:SS') as time
|
||||
FROM \"MarketData\"
|
||||
WHERE symbol='SOL-PERP' AND timeframe='1'
|
||||
ORDER BY timestamp DESC LIMIT 10;"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
✅ TradingView alert fires every 60 seconds
|
||||
✅ Webhook logs show "Received market data webhook" every minute
|
||||
✅ Cache shows fresh data (ageSeconds < 60)
|
||||
✅ Telegram bot uses fresh ATR (not preset 0.43)
|
||||
✅ TP/SL targets adapt to current volatility
|
||||
✅ Database stores all 1-minute datapoints
|
||||
|
||||
**System is working when:**
|
||||
- Manual trades complete within 60 seconds (not timeout)
|
||||
- ATR values change based on market conditions
|
||||
- TP/SL distances adapt to volatility automatically
|
||||
Reference in New Issue
Block a user