8
n8n 中文网amn8n.com

Reddit 加密货币情报与市场暴涨检测器

中级

这是一个Crypto Trading领域的自动化工作流,包含 15 个节点。主要使用 Code, Discord, HttpRequest, ScheduleTrigger 等节点。 Reddit加密货币市场情报与CoinGecko警报至Discord

前置要求
  • Discord Bot Token 或 Webhook
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "Qs7SzwsfqN05P3H2",
  "meta": {
    "instanceId": "c4eae34af81eeff658410c97c38d8a485e4c73ba5cea5b25eef189aa5e5a73b9",
    "templateCredsSetupCompleted": true
  },
  "name": "Reddit 加密货币情报与市场暴涨检测器",
  "tags": [],
  "nodes": [
    {
      "id": "de966d28-3914-4942-889c-355dbd984451",
      "name": "获取 Reddit 帖子",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        256,
        0
      ],
      "parameters": {
        "url": "https://www.reddit.com/r/CryptoCurrency/new/.rss",
        "options": {},
        "responseFormat": "string"
      },
      "typeVersion": 1
    },
    {
      "id": "f73f317a-d1ef-425f-bd21-d99e57813ff0",
      "name": "提取代币提及",
      "type": "n8n-nodes-base.code",
      "position": [
        528,
        0
      ],
      "parameters": {
        "jsCode": "// Handle both string and object responses safely\nlet xml = items[0].json;\n\nif (typeof xml === 'object') {\n  // Sometimes n8n wraps RSS inside a \"body\" or returns it as JSON\n  xml = xml.body || JSON.stringify(xml);\n}\n\n// Ensure xml is a string\nif (typeof xml !== 'string') {\n  xml = String(xml);\n}\n\n// Extract <title> tags (works for Atom feeds too)\nconst titles = [];\nconst regex = /<title>(?:<!\\[CDATA\\[)?(.*?)(?:\\]\\]>)?<\\/title>/gms;\nlet match;\nwhile ((match = regex.exec(xml)) !== null) {\n  titles.push(match[1].toLowerCase());\n}\n\n// Find coin mentions\nconst coinsMentioned = new Set();\n\nfor (const title of titles) {\n  if (title.includes('btc') || title.includes('bitcoin')) coinsMentioned.add('bitcoin');\n  if (title.includes('eth') || title.includes('ethereum')) coinsMentioned.add('ethereum');\n  if (title.includes('sol') || title.includes('solana')) coinsMentioned.add('solana');\n  if (title.includes('doge') || title.includes('dogecoin')) coinsMentioned.add('dogecoin');\n  if (title.includes('xrp')) coinsMentioned.add('ripple');\n  if (title.includes('ada') || title.includes('cardano')) coinsMentioned.add('cardano');\n}\n\n// Return results\nreturn Array.from(coinsMentioned).map(coin => ({ json: { coin } }));"
      },
      "typeVersion": 1
    },
    {
      "id": "af8387f2-a014-4398-be40-ad0d4c1168d3",
      "name": "获取代币数据",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        800,
        0
      ],
      "parameters": {
        "url": "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&page=1",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "1e21559f-f057-4ec5-9696-c451ff3a3929",
      "name": "检测价格暴涨",
      "type": "n8n-nodes-base.code",
      "position": [
        1072,
        0
      ],
      "parameters": {
        "jsCode": "// Get input data safely\nconst itemsIn = items.length > 0 ? items : [];\nif (itemsIn.length === 0) {\n  return [{ json: { message: 'No price data received' } }];\n}\n\n// Extract prices safely\nconst priceData = itemsIn.map(i => i.json).filter(d => d && d.current_price !== undefined);\n\n// Early exit if missing data\nif (priceData.length === 0) {\n  return [{ json: { message: 'No valid price data found' } }];\n}\n\n// Detect spikes: > 10% up or down in 24h\nconst threshold = 10; // percent\nconst spikes = [];\n\nfor (const token of priceData) {\n  const change = token.price_change_percentage_24h;\n  if (typeof change === 'number' && Math.abs(change) >= threshold) {\n    spikes.push({\n      id: token.id,\n      symbol: token.symbol,\n      name: token.name,\n      current_price: token.current_price,\n      change_24h: change,\n      direction: change > 0 ? 'up' : 'down',\n      last_updated: token.last_updated\n    });\n  }\n}\n\n// Return n8n-compatible output\nif (spikes.length === 0) {\n  return [{ json: { message: 'No major price spikes detected' } }];\n}\n\nreturn spikes.map(spike => ({ json: spike }));"
      },
      "typeVersion": 1
    },
    {
      "id": "601b2165-dec2-4807-ad72-5343eecf2b23",
      "name": "撰写 Discord 消息",
      "type": "n8n-nodes-base.code",
      "position": [
        1328,
        0
      ],
      "parameters": {
        "jsCode": "const data = $json;\n\n// If no spike data, send a generic message\nif (!data.symbol || !data.name || data.change_24h === undefined) {\n  return {\n    json: {\n      content: `No price spikes detected in the latest check.`\n    }\n  };\n}\n\nconst directionEmoji = data.direction === 'up' ? '🚀' : '📉';\nconst changeText = data.change_24h.toFixed(2);\nconst msg = `${directionEmoji} **${data.name} (${data.symbol.toUpperCase()})** moved *${changeText}%* ${data.direction} in the last 24h!\\n💰 Price: $${data.current_price}\\n🕒 Updated: ${data.last_updated}`;\n\nreturn {\n  json: {\n    content: msg\n  }\n};"
      },
      "typeVersion": 1
    },
    {
      "id": "dcba08bf-62c3-4cff-a327-d0fc45d14718",
      "name": "发送消息",
      "type": "n8n-nodes-base.discord",
      "position": [
        1568,
        0
      ],
      "webhookId": "27e78eb8-df02-4ae4-b9b7-b831dbb1bec1",
      "parameters": {
        "content": "={{ $json.content }}",
        "guildId": {
          "__rl": true,
          "mode": "list",
          "value": "1280652666577354803",
          "cachedResultUrl": "https://discord.com/channels/1280652666577354803",
          "cachedResultName": "Renz's server"
        },
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "1280652667408089210",
          "cachedResultUrl": "https://discord.com/channels/1280652666577354803/1280652667408089210",
          "cachedResultName": "general"
        }
      },
      "credentials": {
        "discordBotApi": {
          "id": "9ivVgYWgpq4MNHqd",
          "name": "Discord Bot Token"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "6c67e9ae-1b14-422d-aaf2-df6b4a4d0aaf",
      "name": "每小时",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6f44e950-9086-4aa6-89e3-39ea0ddc0998",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        -240
      ],
      "parameters": {
        "width": 224,
        "height": 400,
        "content": "此节点安排工作流每小时自动运行一次。"
      },
      "typeVersion": 1
    },
    {
      "id": "bd5d8e35-74de-4cc4-ad71-e0b152ff236b",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -240
      ],
      "parameters": {
        "color": 2,
        "width": 272,
        "height": 400,
        "content": "此节点使用 Reddit 的公共 RSS 源从 r/CryptoCurrency 子版块获取最新帖子。"
      },
      "typeVersion": 1
    },
    {
      "id": "a99448b3-dcde-459f-abba-ec9c675d49b9",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        -240
      ],
      "parameters": {
        "color": 4,
        "width": 272,
        "height": 400,
        "content": "此节点从 CoinGecko 公共 API 获取检测到的代币符号的实时价格数据和24小时百分比变化。"
      },
      "typeVersion": 1
    },
    {
      "id": "8294e1e8-bb28-4bcd-8088-19e322765e16",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 400,
        "content": "此代码节点从 Reddit 帖子标题中提取代币代码或符号(例如 $BTC, $ETH, $SOL, $MOONX)。"
      },
      "typeVersion": 1
    },
    {
      "id": "c00ae4b4-706b-4a1a-ac4f-feb932fb80ff",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 256,
        "height": 400,
        "content": "此代码节点检测显著的市场波动(默认为24小时内±5%)。"
      },
      "typeVersion": 1
    },
    {
      "id": "69608355-b258-45ee-b304-c336817cd929",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        -240
      ],
      "parameters": {
        "color": 6,
        "height": 400,
        "content": "此节点为 Discord 构建清晰、格式良好的警报消息。"
      },
      "typeVersion": 1
    },
    {
      "id": "9d4903f1-7a90-4307-bf97-f9c56b1a37ec",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1488,
        -240
      ],
      "parameters": {
        "color": 7,
        "height": 400,
        "content": "此节点通过 Webhook 将撰写的消息发布到您的 Discord 频道。"
      },
      "typeVersion": 1
    },
    {
      "id": "34f756c9-e83a-4cf8-b171-3abaf3358965",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1728,
        -208
      ],
      "parameters": {
        "width": 672,
        "height": 368,
        "content": "此 n8n 自动化持续监控 r/CryptoCurrency 子版块以获取新代币提及,将其与实时 CoinGecko 市场数据关联,并检测显著的市场波动。"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "589c20d8-9d91-4fb5-bd33-065d2b1be371",
  "connections": {
    "Hourly": {
      "main": [
        [
          {
            "node": "Fetch Reddit Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Coin Data": {
      "main": [
        [
          {
            "node": "Detect Price Spike",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Price Spike": {
      "main": [
        [
          {
            "node": "Compose Discord Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Reddit Posts": {
      "main": [
        [
          {
            "node": "Extract Coin Mentions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Coin Mentions": {
      "main": [
        [
          {
            "node": "Fetch Coin Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Discord Message": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 加密货币交易

需要付费吗?

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

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

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

作者
AFK Crypto

AFK Crypto

@afkcrypto

Automation expert and founder of AFK Crypto with over 5 years of experience in crypto automations.

外部链接
在 n8n.io 查看

分享此工作流