8
n8n 中文网amn8n.com

前100只股票价格变动自动日报

中级

这是一个Crypto Trading, Multimodal AI领域的自动化工作流,包含 13 个节点。主要使用 Set, Code, Cron, WhatsApp, EmailSend 等节点。 使用Twelve Data API生成每日股市报告,通过WhatsApp和电子邮件发送

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "z8p6r4MRvb3YWvpa",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
    "templateCredsSetupCompleted": true
  },
  "name": "前 100 只股票价格变动自动日报",
  "tags": [],
  "nodes": [
    {
      "id": "e84b9576-6c4a-424c-9f64-0ce3cdca5909",
      "name": "每日市场收盘触发器",
      "type": "n8n-nodes-base.cron",
      "position": [
        -624,
        -32
      ],
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 17
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d4544920-d3b4-4928-88c9-435fd82e7cbe",
      "name": "设置配置变量",
      "type": "n8n-nodes-base.set",
      "position": [
        -400,
        -32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "api-key-assignment",
              "name": "twelvedata_api_key",
              "type": "string",
              "value": "your_api_key_add_here"
            },
            {
              "id": "symbols-assignment",
              "name": "top_symbols",
              "type": "string",
              "value": "AAPL,MSFT,GOOGL,AMZN,TSLA"
            },
            {
              "id": "whatsapp-number",
              "name": "whatsapp_number",
              "type": "string",
              "value": "+919999992211"
            },
            {
              "id": "email-recipient",
              "name": "email_recipient",
              "type": "string",
              "value": "abc@gmail.com"
            },
            {
              "id": "fd42d040-23dc-456f-89ee-144be97a1e8c",
              "name": "",
              "type": "string",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "30d03cb8-c49a-4eb1-8e58-5cf8434c313b",
      "name": "从 Twelve Data 获取股票数据",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -176,
        -32
      ],
      "parameters": {
        "url": "=https://api.twelvedata.com/quote?symbol={{ $json.top_symbols }}&apikey={{ $json.twelvedata_api_key }}",
        "options": {
          "timeout": 30000
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "interval",
              "value": "1day"
            },
            {
              "name": "outputsize",
              "value": "1"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9ab66310-6532-4267-bf5e-38131317a677",
      "name": "处理股票变动",
      "type": "n8n-nodes-base.code",
      "position": [
        48,
        -32
      ],
      "parameters": {
        "jsCode": "const stockData = $input.first().json;\nlet processedStocks = [];\n\n// Check for API error\nif (stockData.error) {\n  throw new Error(`Twelve Data API Error: ${stockData.error.message}`);\n}\n\n// Handle single or multiple stock responses\nlet quotes = [];\nif (Array.isArray(stockData)) {\n  quotes = stockData;\n} else if (stockData.symbol) {\n  quotes = [stockData];\n} else {\n  quotes = Object.values(stockData).filter(item => item.symbol);\n}\n\nfor (let stock of quotes) {\n  if (stock && stock.symbol && stock.percent_change) {\n    const percentChange = parseFloat(stock.percent_change);\n    const price = parseFloat(stock.close || stock.price);\n    const change = parseFloat(stock.change);\n    processedStocks.push({\n      symbol: stock.symbol,\n      name: stock.name || stock.symbol,\n      price: isNaN(price) ? null : price,\n      change: isNaN(change) ? null : change,\n      percent_change: isNaN(percentChange) ? null : percentChange,\n      volume: stock.volume ? parseInt(stock.volume) : null,\n      movement_type: percentChange > 0 ? 'gain' : 'loss',\n      abs_percent_change: Math.abs(percentChange)\n    });\n  }\n}\n\n// Sort by absolute percentage change\nprocessedStocks.sort((a, b) => b.abs_percent_change - a.abs_percent_change);\n\n// Top 5 movers\nconst topMovers = processedStocks.slice(0, 5);\nconst gainers = topMovers.filter(stock => stock.percent_change > 0).slice(0, 3);\nconst losers = topMovers.filter(stock => stock.percent_change < 0).slice(0, 3);\n\nconst currentDate = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });\n\nreturn [{ json: { date: currentDate, total_stocks: processedStocks.length, top_gainers: gainers, top_losers: losers, biggest_movers: topMovers } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "940a5f7c-555d-4eab-8bd1-d4a44060d315",
      "name": "格式化 WhatsApp 消息",
      "type": "n8n-nodes-base.code",
      "position": [
        272,
        -112
      ],
      "parameters": {
        "jsCode": "const data = $input.first().json;\nlet message = `📈 *DAILY STOCK MARKET REPORT*\\n`;\nmessage += `📅 Date: ${data.date}\\n`;\nmessage += `📊 Analyzed: ${data.total_stocks} stocks\\n\\n`;\nmessage += `🟢 *TOP GAINERS*\\n━━━━━━━━━━━━━\\n`;\ndata.top_gainers.forEach((stock, index) => {\n  message += `${index + 1}. ${stock.symbol}\\n`;\n  message += `   💰 $${stock.price?.toFixed(2) || 'N/A'}\\n`;\n  message += `   📈 +${stock.percent_change?.toFixed(2) || 'N/A'}% (+$${stock.change?.toFixed(2) || 'N/A'})\\n\\n`;\n});\nmessage += `🔴 *TOP LOSERS*\\n━━━━━━━━━━━━━\\n`;\ndata.top_losers.forEach((stock, index) => {\n  message += `${index + 1}. ${stock.symbol}\\n`;\n  message += `   💰 $${stock.price?.toFixed(2) || 'N/A'}\\n`;\n  message += `   📉 ${stock.percent_change?.toFixed(2) || 'N/A'}% ($${stock.change?.toFixed(2) || 'N/A'})\\n\\n`;\n});\nmessage += `\\n⚡ Generated by Stock Alert Bot`;\nreturn [{ json: { whatsapp_message: message } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "3d3b1981-004c-4ae1-a450-63690b0e9100",
      "name": "格式化邮件内容",
      "type": "n8n-nodes-base.code",
      "position": [
        272,
        48
      ],
      "parameters": {
        "jsCode": "const data = $input.first().json;\nlet htmlContent = `<!DOCTYPE html><html><head><style>body { font-family: Arial, sans-serif; margin: 20px; background-color: #f5f5f5; }.container { max-width: 600px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; }.header { text-align: center; border-bottom: 2px solid #007bff; padding-bottom: 10px; }.section { margin-bottom: 20px; }.stock-table { width: 100%; border-collapse: collapse; }.stock-table th, .stock-table td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; }.stock-table th { background-color: #f8f9fa; }.gain { color: #28a745; }.loss { color: #dc3545; }.symbol { font-weight: bold; color: #007bff; }</style></head><body><div class=\"container\"><div class=\"header\"><h2>📈 Daily Stock Market Report</h2><p><strong>Date:</strong> ${data.date}</p></div><div class=\"section\"><h3 style=\"color: #28a745;\">🟢 Top Gainers</h3><table class=\"stock-table\"><thead><tr><th>Symbol</th><th>Price</th><th>Change</th><th>% Change</th></tr></thead><tbody>`;\ndata.top_gainers.forEach((stock) => {\n  htmlContent += `<tr><td class=\"symbol\">${stock.symbol}</td><td>$${stock.price?.toFixed(2) || 'N/A'}</td><td class=\"gain\">+$${stock.change?.toFixed(2) || 'N/A'}</td><td class=\"gain\">+${stock.percent_change?.toFixed(2) || 'N/A'}%</td></tr>`;\n});\nhtmlContent += `</tbody></table></div><div class=\"section\"><h3 style=\"color: #dc3545;\">🔴 Top Losers</h3><table class=\"stock-table\"><thead><tr><th>Symbol</th><th>Price</th><th>Change</th><th>% Change</th></tr></thead><tbody>`;\ndata.top_losers.forEach((stock) => {\n  htmlContent += `<tr><td class=\"symbol\">${stock.symbol}</td><td>$${stock.price?.toFixed(2) || 'N/A'}</td><td class=\"loss\">$${stock.change?.toFixed(2) || 'N/A'}</td><td class=\"loss\">${stock.percent_change?.toFixed(2) || 'N/A'}%</td></tr>`;\n});\nhtmlContent += `</tbody></table></div><div style=\"text-align: center; margin-top: 20px; color: #666;\"><p>⚡ Generated by Stock Alert System</p></div></body></html>`;\nconst plainText = `DAILY STOCK MARKET REPORT\\nDate: ${data.date}\\nStocks Analyzed: ${data.total_stocks}\\n\\nTOP GAINERS:\\n${data.top_gainers.map((stock, i) => `${i+1}. ${stock.symbol}: $${stock.price?.toFixed(2) || 'N/A'} (+${stock.percent_change?.toFixed(2) || 'N/A'}%)`).join('\\n')}\\n\\nTOP LOSERS:\\n${data.top_losers.map((stock, i) => `${i+1}. ${stock.symbol}: $${stock.price?.toFixed(2) || 'N/A'} (${stock.percent_change?.toFixed(2) || 'N/A'}%)`).join('\\n')}\\n\\nGenerated by Stock Alert System`;\nreturn [{ json: { email_html: htmlContent, email_text: plainText, email_subject: `Daily Stock Report - ${data.date}` } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "d703c8f4-20c5-4960-8b11-59dd20d8952a",
      "name": "发送邮件提醒",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        496,
        48
      ],
      "webhookId": "c8c21150-59d1-4fa9-841c-eb46cd4409cc",
      "parameters": {
        "html": "={{ $json.email_html }}",
        "options": {},
        "subject": "={{ $json.email_subject }}",
        "toEmail": "={{ $('Set Configuration Variables\t').item.json.email_recipient }}",
        "fromEmail": "alert@gmail.com",
        "emailFormat": "html"
      },
      "credentials": {
        "smtp": {
          "id": "G1kyF8cSWTZ4vouN",
          "name": "SMTP -test"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "a6436b0d-b49e-4186-b9d7-e80177665e8f",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -176
      ],
      "parameters": {
        "width": 160,
        "height": 300,
        "content": "周一至周五每天下午 5:00(市场收盘后)触发。"
      },
      "typeVersion": 1
    },
    {
      "id": "1b1643d8-294d-457f-9164-9a0990ecef94",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -176
      ],
      "parameters": {
        "color": 4,
        "width": 170,
        "height": 300,
        "content": "设置 API 密钥、股票代码和提醒接收者。"
      },
      "typeVersion": 1
    },
    {
      "id": "e1cafd10-344b-4d39-91d6-04588d7e6d67",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        -176
      ],
      "parameters": {
        "color": 3,
        "width": 170,
        "height": 300,
        "content": "通过 Twelve Data API 获取选定股票代码的数据。"
      },
      "typeVersion": 1
    },
    {
      "id": "4dcb1252-bcc4-4b6d-8a05-b5d8600bce13",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -176
      ],
      "parameters": {
        "color": 5,
        "width": 170,
        "height": 300,
        "content": "处理股票数据以识别涨幅最大和跌幅最大的股票。"
      },
      "typeVersion": 1
    },
    {
      "id": "444844c9-b1c2-40b6-907e-0b93e08aea6c",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -208
      ],
      "parameters": {
        "color": 6,
        "width": 170,
        "height": 332,
        "content": "通过 WhatsApp 和邮件发送格式化的提醒。"
      },
      "typeVersion": 1
    },
    {
      "id": "26752e0e-0ab8-4f67-858b-c0d954891d9b",
      "name": "发送消息",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        480,
        -112
      ],
      "webhookId": "51455c3e-b9ee-4048-88c6-bfb2631aa10c",
      "parameters": {
        "textBody": "={{ $json.whatsapp_message }}",
        "operation": "send",
        "phoneNumberId": "=+919877663344",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('Set Configuration Variables\t').item.json.whatsapp_number }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "b0PxTDPdWzznWnfG",
          "name": "WhatsApp-test "
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e99f69ff-d8ff-4f02-980c-5c27a29d37cb",
  "connections": {
    "Format Email Content\t": {
      "main": [
        [
          {
            "node": "Send Email Alert\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format WhatsApp Message\t": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Stock Movements\t": {
      "main": [
        [
          {
            "node": "Format WhatsApp Message\t",
            "type": "main",
            "index": 0
          },
          {
            "node": "Format Email Content\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Market Close Trigger\t": {
      "main": [
        [
          {
            "node": "Set Configuration Variables\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Configuration Variables\t": {
      "main": [
        [
          {
            "node": "Fetch Stock Data from Twelve Data\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Stock Data from Twelve Data\t": {
      "main": [
        [
          {
            "node": "Process Stock Movements\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
Oneclick AI Squad

Oneclick AI Squad

@oneclick-ai

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

外部链接
在 n8n.io 查看

分享此工作流