8
n8n 中文网amn8n.com

加密货币RSI警报系统与EODHD、Telegram和TradingView图表

中级

这是一个Crypto Trading, Multimodal AI领域的自动化工作流,包含 15 个节点。主要使用 If, Set, Code, SplitOut, Telegram 等节点。 与EODHD、Telegram和TradingView图表集成的加密货币RSI警报系统

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "c2b1f8c1d4a74a0cb8a1f1d3b7b0e7c1b9d2f5a8f3e44c9c93a1e2f4a6b7c8d9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "m1",
      "name": "当点击\"执行工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -520,
        -160
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "note_overview",
      "name": "便签 - 概述",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -540,
        -360
      ],
      "parameters": {
        "color": 6,
        "width": 860,
        "height": 260,
        "content": "## 加密货币RSI提醒机器人(概述)"
      },
      "typeVersion": 1
    },
    {
      "id": "set1",
      "name": "编辑字段(观察列表)",
      "type": "n8n-nodes-base.set",
      "position": [
        -300,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "sym_arr",
              "name": "symbol",
              "type": "array",
              "value": "[\"BTC-USD.CC\",\"ETH-USD.CC\",\"SOL-USD.CC\"]"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "note_watchlist",
      "name": "便签 - 观察列表",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -300
      ],
      "parameters": {
        "color": 6,
        "width": 560,
        "height": 160,
        "content": "### 编辑字段(观察列表)"
      },
      "typeVersion": 1
    },
    {
      "id": "split_out",
      "name": "拆分输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -80,
        -160
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "symbol"
      },
      "typeVersion": 1
    },
    {
      "id": "note_split",
      "name": "便签 - 拆分输出",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -100,
        -300
      ],
      "parameters": {
        "color": 6,
        "width": 520,
        "height": 150,
        "content": "### 拆分输出"
      },
      "typeVersion": 1
    },
    {
      "id": "loop",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        140,
        -160
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "note_loop",
      "name": "便签 - 循环",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        120,
        -300
      ],
      "parameters": {
        "color": 6,
        "width": 560,
        "height": 120,
        "content": "### 遍历项目"
      },
      "typeVersion": 1
    },
    {
      "id": "http",
      "name": "HTTP请求(EODHD日内1小时)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        360,
        -260
      ],
      "parameters": {
        "url": "=https://eodhd.com/api/intraday/{{ $json.symbol }}",
        "method": "GET",
        "options": {
          "redirect": {
            "redirect": {}
          },
          "response": {
            "response": {}
          },
          "splitIntoItems": true
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "interval",
              "value": "1h"
            },
            {
              "name": "fmt",
              "value": "json"
            },
            {
              "name": "api_token",
              "value": "={{ $env.EODHD_TOKEN }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "note_http",
      "name": "便签 - HTTP",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        -420
      ],
      "parameters": {
        "color": 6,
        "width": 560,
        "height": 160,
        "content": "### HTTP(EODHD)"
      },
      "typeVersion": 1
    },
    {
      "id": "code",
      "name": "代码(RSI + 消息)",
      "type": "n8n-nodes-base.code",
      "position": [
        580,
        -260
      ],
      "parameters": {
        "jsCode": "// n8n Code node — Run Once for All Items\\n// Computes RSI(14) (Wilder) on 1h candles and raises 30/70 cross alerts.\\n\\nconst PERIOD = 14;\\nconst OVERBOUGHT = 70;\\nconst OVERSOLD = 30;\\n\\n// Collect ALL candles from the HTTP node (1 item = 1 candle)\\nconst inputItems = $input.all();\\nlet candles = [];\\nfor (const it of inputItems) {\\n  if (Array.isArray(it.json)) candles.push(...it.json);\\n  else candles.push(it.json);\\n}\\n\\n// Normalize + sort by time (prefer numeric timestamp, fallback to datetime)\\ncandles = candles\\n  .filter(r => r && r.close !== undefined)\\n  .map(r => ({\\n    t: (Number.isFinite(+r.timestamp) ? +r.timestamp\\n       : (typeof r.datetime === 'number' ? r.datetime : Date.parse(r.datetime)/1000)),\\n    close: +r.close\\n  }))\\n  .filter(r => Number.isFinite(r.t) && Number.isFinite(r.close))\\n  .sort((a,b) => a.t - b.t);\\n\\nif (candles.length < PERIOD + 2) {\\n  return [{ json: { error: 'Not enough candles for RSI', count: candles.length } }];\\n}\\n\\nconst closes = candles.map(c => c.close);\\n\\n// Wilder RSI (full series)\\nfunction rsiSeries(values, period = 14) {\\n  const deltas = [];\\n  for (let i = 1; i < values.length; i++) deltas.push(values[i] - values[i - 1]);\\n  let gain = 0, loss = 0;\\n  for (let i = 0; i < period; i++) { const d = deltas[i]; if (d >= 0) gain += d; else loss -= d; }\\n  let avgGain = gain / period; let avgLoss = loss / period;\\n  const rsis = new Array(values.length).fill(null);\\n  rsis[period] = avgLoss === 0 ? 100 : 100 - (100 / (1 + (avgGain / avgLoss)));\\n  for (let i = period + 1; i < values.length; i++) {\\n    const d = deltas[i - 1];\\n    const up = Math.max(d, 0);\\n    const down = Math.max(-d, 0);\\n    avgGain = ((avgGain * (period - 1)) + up) / period;\\n    avgLoss = ((avgLoss * (period - 1)) + down) / period;\\n    const rs = avgLoss === 0 ? Infinity : (avgGain / avgLoss);\\n    rsis[i] = 100 - (100 / (1 + rs));\\n  }\\n  return rsis;\\n}\\n\\nconst rsis = rsiSeries(closes, PERIOD);\\nconst lastIdx = rsis.length - 1;\\nconst rsiNow = +rsis[lastIdx].toFixed(1);\\nconst rsiPrev = +rsis[lastIdx - 1].toFixed(1);\\nconst lastClose = +closes[lastIdx].toFixed(2);\\nconst lastTs = candles[lastIdx].t;\\n\\n// Signals\\nlet signal = null;\\nif (rsiPrev > OVERSOLD && rsiNow <= OVERSOLD) signal = 'enter_oversold';\\nelse if (rsiPrev < OVERBOUGHT && rsiNow >= OVERBOUGHT) signal = 'enter_overbought';\\nelse if (rsiPrev <= OVERSOLD && rsiNow > OVERSOLD) signal = 'exit_oversold';\\nelse if (rsiPrev >= OVERBOUGHT && rsiNow < OVERBOUGHT) signal = 'exit_overbought';\\n\\n// ======= TEST TOGGLE (set true only to test Telegram delivery) =======\\nconst FORCE_ALERT  = false;                 // keep false in production\\nconst FORCE_SIGNAL = 'enter_overbought';    // 'enter_oversold' | 'exit_oversold' | 'exit_overbought'\\nif (FORCE_ALERT) signal = FORCE_SIGNAL;\\n// =====================================================================\\n\\n// Current symbol from the loop item (fallback to input $json)\\nconst symbol = $('Split Out')?.item?.json?.symbol || $json.symbol || 'UNKNOWN';\\n\\nconst TF = '1h';\\nconst fmt = (n, d=2) => Number(n).toLocaleString('en-US',{minimumFractionDigits:d, maximumFractionDigits:d});\\nconst tsUTC = (ts) => new Date(ts*1000).toISOString().replace('T',' ').slice(0,16) + ' UTC';\\n\\nlet emoji = '🔔', headline = '';\\nif (signal === 'enter_oversold')        { emoji='🔻'; headline = `enters <u>oversold</u> (RSI ${rsiNow} ≤ 30)`; }\\nelse if (signal === 'enter_overbought') { emoji='🚀'; headline = `enters <u>overbought</u> (RSI ${rsiNow} ≥ 70)`; }\\nelse if (signal === 'exit_oversold')    { emoji='✅'; headline = `exits <u>oversold</u> (RSI ${rsiNow})`; }\\nelse if (signal === 'exit_overbought')  { emoji='✅'; headline = `exits <u>overbought</u> (RSI ${rsiNow})`; }\\n\\nconst alertTextHtml = signal ? (\\n  `${emoji} <b>${symbol}</b> ${headline}\\n` +\\n  `Price: <b>$${fmt(lastClose)}</b> · TF: <b>${TF}</b> · ${tsUTC(lastTs)}\\n` +\\n  `RSI: <b>${rsiPrev} → ${rsiNow}</b> (30/70)\\n` +\\n  `— <i>RSI Heatwave</i>`\\n) : null;\\n\\nconst alertText = signal ? `${symbol} | ${headline.replace(/<[^>]*>/g,'')} | Price $${fmt(lastClose)} · TF ${TF} · ${tsUTC(lastTs)} | RSI ${rsiPrev}→${rsiNow}` : null;\\n\\n// TradingView link (BINANCE + USD) from EODHD symbol (e.g., BTC-USD.CC → BTCUSD)\\nconst rawSymbol = $('Split Out')?.item?.json?.symbol ?? $json.symbol ?? symbol;\\nconst sym  = Array.isArray(rawSymbol) ? rawSymbol[0] : rawSymbol; \\nconst base = String(sym).split('-')[0].toUpperCase();\\nconst tradingViewUrl = `https://www.tradingview.com/symbols/${base}USD/?exchange=BINANCE`;\\n\\nreturn [{ json: { symbol, rsi: rsiNow, rsiPrev, period: PERIOD, lastClose, signal, timestamp: lastTs, alertText, alertTextHtml, tradingViewUrl } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "note_code",
      "name": "便签 - 代码",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -420
      ],
      "parameters": {
        "color": 6,
        "width": 560,
        "height": 170,
        "content": "### 代码(RSI + 消息)"
      },
      "typeVersion": 1
    },
    {
      "id": "if",
      "name": "IF(有信号?)",
      "type": "n8n-nodes-base.if",
      "position": [
        140,
        40
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond1",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.signal }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "tg",
      "name": "发送文本消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        360,
        40
      ],
      "parameters": {
        "text": "={{ $json.alertTextHtml }}",
        "chatId": "={{ $env.TELEGRAM_CHAT_ID }}",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "View chart",
                    "additionalFields": {
                      "url": "={{ $json.tradingViewUrl }}"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "parse_mode": "HTML",
          "disable_web_page_preview": true
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "REPLACE_WITH_YOUR_TELEGRAM_CRED_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "note_tg",
      "name": "便签 - Telegram",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        180
      ],
      "parameters": {
        "color": 6,
        "width": 560,
        "height": 140,
        "content": "### Telegram(发送)"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "IF (has signal?)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTTP Request (EODHD intraday 1h)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF (has signal?)": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code (RSI + message)": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields (watchlist)": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request (EODHD intraday 1h)": {
      "main": [
        [
          {
            "node": "Code (RSI + message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Edit Fields (watchlist)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 加密货币交易, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量15
分类2
节点类型9
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流