8
n8n 中文网amn8n.com

股票分析助手

高级

这是一个Finance, AI领域的自动化工作流,包含 21 个节点。主要使用 If, Set, Code, Slack, HttpRequest 等节点,结合人工智能技术实现智能自动化。 AI 驱动的股市摘要机器人

前置要求
  • Slack Bot Token 或 Webhook URL
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "e5XxiuYXr5atCH64",
  "meta": {
    "instanceId": "564ad264d05dc77e4e5afc0ced9da90c41c9a77ab9c35729bf6f29309796798d",
    "templateCredsSetupCompleted": true
  },
  "name": "股票分析助手",
  "tags": [
    {
      "id": "TkUb5sI0Ae0hwCo3",
      "name": "Agent",
      "createdAt": "2025-04-07T21:00:21.151Z",
      "updatedAt": "2025-04-07T21:00:21.151Z"
    },
    {
      "id": "xhCApXrnlelxaW2i",
      "name": "Stock",
      "createdAt": "2025-06-09T04:02:42.364Z",
      "updatedAt": "2025-06-09T04:02:42.364Z"
    },
    {
      "id": "eZArPFfgyfBReNUS",
      "name": "AlpacaAPI",
      "createdAt": "2025-06-09T04:02:47.415Z",
      "updatedAt": "2025-06-09T04:02:47.415Z"
    }
  ],
  "nodes": [
    {
      "id": "f9e2b1a6-4bc4-429c-a516-78fc440cb259",
      "name": "股票代码列表",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        0
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"symbols\": \"AAPL,MSFT,NVDA,TSLA,AMZN,GOOGL,META,JPM,XOM,UNH,GME\"\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "46c712d0-8e65-4da0-bdbc-9eadf4213f2f",
      "name": "获取股票数据",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1020,
        0
      ],
      "parameters": {
        "url": "=https://data.alpaca.markets/v2/stocks/bars",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "symbols",
              "value": "={{ $json.symbols }}"
            },
            {
              "name": "timeframe",
              "value": "1Day"
            },
            {
              "name": "limit",
              "value": "1000"
            },
            {
              "name": "feed",
              "value": "iex"
            },
            {
              "name": "=start",
              "value": "={{ new Date(Date.now() - 100 * 24 * 60 * 60 * 1000).toISOString().split('T')[0] }}"
            },
            {
              "name": "end",
              "value": "={{ new Date().toISOString().split('T')[0] }}"
            }
          ]
        }
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "REDACTED_ID",
          "name": "REDACTED_NAME"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e8d96c0c-e927-4676-a02f-7729c0126165",
      "name": "解读数据",
      "type": "n8n-nodes-base.code",
      "position": [
        1240,
        0
      ],
      "parameters": {
        "language": "python",
        "pythonCode": "import pandas as pd\nimport numpy as np\nimport json\n\nbars_by_symbol = items[0]['json']['bars']\nstocks = []\n\nfor symbol, bars in bars_by_symbol.items():\n    closes = [bar['c'] for bar in bars if 'c' in bar]\n    if len(closes) < 30:\n        continue\n\n    df = pd.DataFrame({'close': closes})\n\n    # RSI(14)\n    delta = df['close'].diff()\n    gain = delta.clip(lower=0)\n    loss = -delta.clip(upper=0)\n    avg_gain = gain.rolling(14).mean()\n    avg_loss = loss.rolling(14).mean()\n    rs = avg_gain / avg_loss\n    df['rsi'] = 100 - (100 / (1 + rs))\n\n    # MACD (12,26,9)\n    ema12 = df['close'].ewm(span=12, adjust=False).mean()\n    ema26 = df['close'].ewm(span=26, adjust=False).mean()\n    df['macd'] = ema12 - ema26\n    df['signal'] = df['macd'].ewm(span=9, adjust=False).mean()\n\n    latest = df.iloc[-1]\n    rsi = latest['rsi']\n    macd = latest['macd']\n    signal = latest['signal']\n\n    status = \"Hold\"\n    if rsi < 30 and macd > signal:\n        status = \"Buy\"\n    elif rsi > 70 and macd < signal:\n        status = \"Sell\"\n\n    stocks.append({\n        \"ticker\": symbol,\n        \"rsi\": round(float(rsi), 2),\n        \"macd\": round(float(macd), 2),\n        \"signal\": round(float(signal), 2),\n        \"status\": status\n    })\n\nreturn [{\n    \"json\": {\n        \"summary\": json.dumps({\n            \"stocks\": stocks\n        }, separators=(',', ':')),\n      \"stocks\": stocks\n    }\n}]\n"
      },
      "typeVersion": 2
    },
    {
      "id": "5ace21ee-80b0-4d79-be68-ded17b53b5a2",
      "name": "股票分析助手",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1440,
        0
      ],
      "parameters": {
        "text": "=Here is the technical indicator data as JSON:\n\n{{ $json.summary }}\n\nPulled as of {{ $now }}",
        "prompt": "define",
        "options": {},
        "resource": "assistant",
        "assistantId": {
          "mode": "list",
          "value": "REDACTED_ASSISTANT_ID",
          "cachedResultName": "REDACTED_ASSISTANT"
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "REDACTED_ID",
          "name": "REDACTED_NAME"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "97f8d2af-02a9-4f93-8bf7-ee083b13dccf",
      "name": "发送摘要给用户",
      "type": "n8n-nodes-base.slack",
      "position": [
        1816,
        0
      ],
      "webhookId": "57e1eff1-81c1-42f1-b8ee-fb3e40551362",
      "parameters": {
        "text": "={{ $json.output }}",
        "user": {
          "mode": "list",
          "value": "REDACTED_USER_ID",
          "cachedResultName": "REDACTED_USER"
        },
        "select": "user",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "REDACTED_ID",
          "name": "REDACTED_NAME"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "21b091f5-ce81-4d98-8978-f7193734a72c",
      "name": "定时触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        120,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 30 6-14 * * 1-5"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "94804d45-b868-4501-a53c-0a1063768f14",
      "name": "检查市场是否开放",
      "type": "n8n-nodes-base.if",
      "position": [
        560,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "acca2d72-d9db-436d-aee8-81a3a359fe85",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.is_open }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8366acca-42ff-4106-8b37-316727ac8963",
      "name": "市场已关闭",
      "type": "n8n-nodes-base.noOp",
      "position": [
        800,
        200
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ee50cf08-efe2-4886-8527-23c069495afd",
      "name": "检查市场状态",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        360,
        0
      ],
      "parameters": {
        "url": "https://paper-api.alpaca.markets/v2/clock",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth"
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "REDACTED_ID",
          "name": "REDACTED_NAME"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "97de7640-5be5-4821-9cea-a8d481590256",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -360
      ],
      "parameters": {
        "width": 660,
        "content": "# 🧠 股票分析助手"
      },
      "typeVersion": 1
    },
    {
      "id": "4c40864c-ad6d-420f-88b8-a497d7c71a5d",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        40,
        -360
      ],
      "parameters": {
        "color": 7,
        "height": 700,
        "content": "## 📅 计划触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "28ee034a-cb6a-4a54-8ce1-fef5e439e2de",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        280,
        -360
      ],
      "parameters": {
        "color": 7,
        "width": 460,
        "height": 700,
        "content": "## 🏛️ 市场状态检查"
      },
      "typeVersion": 1
    },
    {
      "id": "ab88e6c4-bafb-47d6-9292-b54850f1d984",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        -360
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 540,
        "content": "## 📈 股票代码设置"
      },
      "typeVersion": 1
    },
    {
      "id": "01892c69-4c22-4c78-a1db-1add2d06993c",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        -360
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 540,
        "content": "## 🔗 获取股票数据"
      },
      "typeVersion": 1
    },
    {
      "id": "a1b98ff6-b033-4f0c-90c6-b6bf2ea0e461",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1180,
        -360
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 540,
        "content": "## 🧮 解读数据"
      },
      "typeVersion": 1
    },
    {
      "id": "0ac7e6ad-405e-46b6-81b9-3367c7793136",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1400,
        -360
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 540,
        "content": "## 🤖 AI助手摘要"
      },
      "typeVersion": 1
    },
    {
      "id": "10b73555-9619-4327-beac-d36a5a88f844",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        180
      ],
      "parameters": {
        "color": 3,
        "width": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "91c98665-4226-4579-a9df-2dd4ad137638",
      "name": "流程结束",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2040,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f11bdac9-2fbe-4ea5-a470-d89d26aa01ba",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1760,
        -360
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 540,
        "content": "## 💬 发布到Slack"
      },
      "typeVersion": 1
    },
    {
      "id": "8221dafd-302c-4bbe-9cea-25bdbe980acb",
      "name": "### 替换 Airtable 连接",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1980,
        -360
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 540,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "d492d1bc-99ba-43da-bf15-1cbe11badb13",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -180
      ],
      "parameters": {
        "color": 5,
        "width": 660,
        "height": 940,
        "content": "## 🤖 AI助手提示"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "timezone": "America/Los_Angeles",
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "0523c0a7-8874-4eff-bcd7-cf3d9ab7c362",
  "connections": {
    "Ticker List": {
      "main": [
        [
          {
            "node": "Fetch Stock Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Interpret Data": {
      "main": [
        [
          {
            "node": "Stock Analysis Assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Stock Data": {
      "main": [
        [
          {
            "node": "Interpret Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Check Market Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Market Status": {
      "main": [
        [
          {
            "node": "Check if Market is open",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Market is open": {
      "main": [
        [
          {
            "node": "Ticker List",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Market is Closed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Summary to User(s)": {
      "main": [
        [
          {
            "node": "End of Flow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Stock Analysis Assistant": {
      "main": [
        [
          {
            "node": "Send Summary to User(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 财务, 人工智能

需要付费吗?

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

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

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流