KuCoin AI代理 v1.02

高级

这是一个Crypto Trading、AI Chatbot、Multimodal AI领域的自动化工作流,包含 35 个节点。主要使用 Set、Code、Telegram、Agent、HttpRequestTool 等节点。 使用 KuCoin AI 代理获取交易所数据 | GPT-4o + Telegram

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "WUDAKeJzCkwYJWhT",
  "meta": {
    "instanceId": "a5283507e1917a33cc3ae615b2e7d5ad2c1e50955e6f831272ddd5ab816f3fb6"
  },
  "name": "KuCoin AI代理 v1.02",
  "tags": [],
  "nodes": [
    {
      "id": "40d3604c-9a06-44fd-96fb-a3e8ab7acf05",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1264,
        736
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "yUizd8t0sD5wMYVG",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "94f8aa5b-70b5-49a2-a7d3-c6758c27615c",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1008,
        240
      ],
      "webhookId": "f6d6d17e-bf55-4ff2-b2c1-5b0729157802",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "NRLKuLR7z8vCesub",
          "name": "BinanceSpotTradingAIAgent_Bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "33874650-9204-47a2-a705-7c8852dded20",
      "name": "用户认证(替换Telegram ID)",
      "type": "n8n-nodes-base.code",
      "position": [
        -688,
        240
      ],
      "parameters": {
        "jsCode": "if ($input.first().json.message.from.id !== <<Replace>>) { // Replace with your actual ID\n  return {unauthorized: true};\n} else {\n  // Return the original data when authorized\n  return $input.all();\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "fc6cfa39-7dcc-4a52-af2c-ac646fd9a1f2",
      "name": "添加\"SessionId\"",
      "type": "n8n-nodes-base.set",
      "position": [
        -416,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "47598bf1-e55f-4cc0-ae75-272085e7ce02",
              "name": "=sessionId",
              "type": "string",
              "value": "={{ $json.message.chat.id }}"
            },
            {
              "id": "daa49d74-e55e-47bc-ac52-8686d591ab83",
              "name": "message",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d81987fc-02dd-4b65-bff4-b005f63faee3",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        896,
        240
      ],
      "webhookId": "3b2fd921-572c-4e5d-8e0e-23a817d1a7f5",
      "parameters": {
        "text": "={{ $json.message }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "NRLKuLR7z8vCesub",
          "name": "BinanceSpotTradingAIAgent_Bot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f7fc9038-2a34-4c2c-abd9-934c53ca4f2c",
      "name": "如果消息超过 4000 字符则拆分",
      "type": "n8n-nodes-base.code",
      "position": [
        464,
        240
      ],
      "parameters": {
        "jsCode": "// Input: assumes incoming message in `item.json.message`\nconst input = $json.output;\nconst chunkSize = 4000;\n\n// Function to split text\nfunction splitMessage(text, size) {\n  const result = [];\n  for (let i = 0; i < text.length; i += size) {\n    result.push(text.substring(i, i + size));\n  }\n  return result;\n}\n\n// Logic\nif (input.length <= chunkSize) {\n  return [{ json: { message: input } }];\n} else {\n  const chunks = splitMessage(input, chunkSize);\n  return chunks.map(chunk => ({ json: { message: chunk } }));\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "0b1e49c0-1dd1-44bb-acb7-4a964925d5f5",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        -32
      ],
      "parameters": {
        "color": 4,
        "height": 460,
        "content": "## 触发传入Telegram命令"
      },
      "typeVersion": 1
    },
    {
      "id": "5a6a8a98-02f9-4c80-85b2-2de68913e48c",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -32
      ],
      "parameters": {
        "color": 2,
        "height": 460,
        "content": "## 验证用户访问权限"
      },
      "typeVersion": 1
    },
    {
      "id": "b081804a-fe79-45da-a1fc-8475fbbd14b4",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        -32
      ],
      "parameters": {
        "color": 5,
        "height": 460,
        "content": "## 生成会话元数据"
      },
      "typeVersion": 1
    },
    {
      "id": "ab0c5696-8ace-49ce-8caa-27f6c14f8a7b",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -224
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 660,
        "content": "## KuCoin现货市场AI代理"
      },
      "typeVersion": 1
    },
    {
      "id": "bb596a9a-e594-4c48-938d-87f79e14e8cc",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        -32
      ],
      "parameters": {
        "color": 5,
        "width": 260,
        "height": 460,
        "content": "## 处理Telegram消息限制"
      },
      "typeVersion": 1
    },
    {
      "id": "4ebe0a92-299f-4074-997d-a4de853a1de8",
      "name": "便利贴5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -32
      ],
      "parameters": {
        "color": 4,
        "height": 460,
        "content": "## 发送最终报告到Telegram"
      },
      "typeVersion": 1
    },
    {
      "id": "be156b45-cb7d-4f14-aa8d-356c16aaa825",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1344,
        640
      ],
      "parameters": {
        "height": 540,
        "content": "## 用于推理的GPT模型"
      },
      "typeVersion": 1
    },
    {
      "id": "6bd54e6e-a5bf-4107-a53b-8183e12809bc",
      "name": "便签 7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1172,
        "content": "### 🏷 工具:**订单簿深度**"
      },
      "typeVersion": 1
    },
    {
      "id": "e1025717-59c4-4c7d-baa6-ee9d6c9a5cda",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 932,
        "content": "### **最佳买卖价(Book Ticker)**"
      },
      "typeVersion": 1
    },
    {
      "id": "1550f50b-9f44-4794-959d-5cfe2dc46844",
      "name": "便签 9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        640
      ],
      "parameters": {
        "color": 3,
        "height": 540,
        "content": "## 短期记忆模块"
      },
      "typeVersion": 1
    },
    {
      "id": "98f7f3fd-c24a-4f0a-905b-63550d74bc53",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -992,
        736
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "9d927de7-dd01-49bb-9204-ee4220fda5a9",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1044,
        "content": "### **24小时统计**"
      },
      "typeVersion": 1
    },
    {
      "id": "a7756691-1ebd-45a5-a474-fc272aa26456",
      "name": "便签11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 868,
        "content": "### **价格(最新)**"
      },
      "typeVersion": 1
    },
    {
      "id": "b73f76d2-4705-4586-a6d5-3109b7513094",
      "name": "便签12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1060,
        "content": "### **K线(蜡烛图)**"
      },
      "typeVersion": 1
    },
    {
      "id": "b28e6cae-489e-4c71-8514-0687f80798f3",
      "name": "便签13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 932,
        "content": "### **平均价格(通过Ticker)**"
      },
      "typeVersion": 1
    },
    {
      "id": "f5becf91-8947-4f2a-aa21-27aae3ec0c0c",
      "name": "便签14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 804,
        "content": "### 🏷 工具:**最近交易**"
      },
      "typeVersion": 1
    },
    {
      "id": "a0bed784-ec26-449e-8d4a-1d1dc19d1340",
      "name": "计算器",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        1520,
        592
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "78dd87bf-b1b4-4b6e-a5dd-61c3187c631d",
      "name": "思考",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        1808,
        592
      ],
      "parameters": {
        "description": "### 🏷 工具:**思考**"
      },
      "typeVersion": 1.1
    },
    {
      "id": "3aad6e1f-d622-43bb-8b08-2abfd667f09b",
      "name": "便签15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 836,
        "content": "### **计算器**"
      },
      "typeVersion": 1
    },
    {
      "id": "b5cd1090-3b35-4319-be51-007ef7350a54",
      "name": "便签16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1728,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 932,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Think**\n\n**Purpose:**\n\n* Lightweight **reasoning helper**.\n* Lets the AI Agent process intermediate logic, format outputs, or decide how to combine multiple API results before sending the final report.\n* Does not fetch data itself.\n\n**Use cases:**\n\n* Clean/reshape JSON from Binance endpoints\n* Extract only the needed fields (e.g., `lastPrice`, `volume`)\n* Help prepare data for Telegram message formatting\n\n**n8n setup notes:**\n\n* No API call, just an **AI Tool** node.\n* Connect upstream API results → Think → Report Agent."
      },
      "typeVersion": 1
    },
    {
      "id": "fd353acc-ae35-4e35-ad5c-06f14a289382",
      "name": "KuCoin  AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -96,
        240
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "You are the KuCoin Spot Market Data Agent.\n\nYou have HTTP request access to the official KuCoin Spot REST API to retrieve market data for any requested trading pair.\nYour job is to fetch and present data only. You do not analyze, predict, or recommend.\n\n---\n\nAPI Access\n- Base endpoint: https://api.kucoin.com\n- All requests are HTTP GET\n- Responses are JSON\n- Parameters use query strings (e.g., ?symbol=BTC-USDT&limit=100)\n- Symbol format: uppercase with dash (e.g., BTC-USDT)\n\n---\n\nAvailable Market Data Endpoints\n1. Order Book Depth\n   GET /api/v1/market/orderbook/level2_100?symbol=BTC-USDT\n   - Returns top bids/asks (100 entries).\n   - Variants: level2_20, level2_100, level2_1\n\n2. Recent Trades\n   GET /api/v1/market/histories?symbol=BTC-USDT\n   - Most recent trades (default limit = 100)\n\n3. Aggregate Ticker (24h Stats)\n   GET /api/v1/market/stats?symbol=BTC-USDT\n   - Includes open, high, low, close, last, volume, % change\n\n4. Kline / Candlestick Data\n   GET /api/v1/market/candles?symbol=BTC-USDT&type=15min&limit=20\n   - Intervals: 1min,3min,5min,15min,30min,1h,2h,4h,6h,8h,12h,1d,1w\n   - Default limit = 100, max = 1500\n\n5. Ticker — Latest Symbol Price\n   GET /api/v1/market/orderbook/level1?symbol=BTC-USDT\n   - Best bid/ask and last trade price\n\n---\n\nUtility Tools\n- Calculator → perform math (spreads, % changes, normalizations)\n- Think → reshape JSON, select fields, prepare outputs\n\n---\n\nOutput Format\nStart every response with:\n[SYMBOL] — KuCoin Spot Data\n\nThen group logically:\nPrice\n• Last: {{lastPrice}}\n• Avg: {{avgPrice}}\n• Change (24h): {{pctChange}}%\n\n24h Stats\n• Open: {{open}} • High: {{high}} • Low: {{low}} • Close: {{close}}\n• Volume: {{baseVol}} • Quote Vol: {{quoteVol}}\n\nOrder Book (Top 5)\n• Bids: [price x qty] …\n• Asks: [price x qty] …\n\nKlines (latest 20)\n• Interval: {{interval}} (O/H/L/C per candle)\n\n---\n\nRules\n- Always call the correct KuCoin API endpoint.\n- Do not fabricate or calculate values yourself.\n- Do not provide trading advice, sentiment, or predictions.\n- Do not output raw JSON; present clean, human-readable values.\n- If data is missing or request fails, show N/A.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "c576165c-f0c4-48d0-bcce-20bca6cfaa09",
      "name": "24h Stats",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -704,
        592
      ],
      "parameters": {
        "url": "https://api.kucoin.com/api/v1/market/stats",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **24h Stats**\n\n**Endpoint:** `GET /api/v1/market/stats`\n**What it does:** Returns the **24-hour stats** for a given trading pair: open, high, low, close, last, change %, base volume, quote volume.\n\n**Params:**\n* `symbol` (STRING, required) → KuCoin pair format with dash, e.g. `BTC-USDT`\n\n**Returns:** `time, symbol, buy, sell, changeRate, changePrice, high, low, vol, volValue, last, averagePrice, takerFeeRate, makerFeeRate, takerCoefficient, makerCoefficient`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\n```\n\n**Notes:**\n* This endpoint provides the **24h rolling window stats**.\n* For metadata (min/max order sizes, increments), use `/api/v2/symbols/{symbol}`."
      },
      "typeVersion": 4.2
    },
    {
      "id": "59c784f7-0125-4449-955c-6a53b6ed6bfe",
      "name": "Order Book Depth",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -416,
        592
      ],
      "parameters": {
        "url": "={{ 'https://api.kucoin.com/api/v1/market/orderbook/' + $fromAI('level', `level2_100`, 'string') }}",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **Order Book Depth**\n\n**Endpoint:** `GET /api/v1/market/orderbook/{level}`\n**What it does:** Returns **order book** bids/asks for a KuCoin symbol.\n\n**Levels (choose via `level`):**\n* `level2_20` → top 20 levels\n* `level2_100` → top 100 levels (default)\n* `level2_1` → best bid/ask (book ticker equivalent)\n\n**Params:**\n* `level`  (STRING, required) → one of `level2_20`, `level2_100`, `level2_1` (we default `level2_100`)\n* `symbol` (STRING, required) → KuCoin pair with dash, e.g. `BTC-USDT`\n\n**Returns:** `time, sequence, bids: [[price, size], ...], asks: [[price, size], ...]`\n\n**n8n query mapping:**\n```txt\nlevel  = $fromAI('level', 'level2_100', 'string')\nsymbol = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\n```\n\n**Notes:**\n* For **best bid/ask only**, set `level = level2_1`.\n* If you need deeper/full book snapshots, KuCoin also offers `/api/v3/market/orderbook/level2?symbol=...&depth=...`."
      },
      "typeVersion": 4.2
    },
    {
      "id": "53732cb5-f3c1-473b-baee-bd7e48715677",
      "name": "Price (Latest)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -112,
        592
      ],
      "parameters": {
        "url": "https://api.kucoin.com/api/v1/market/orderbook/level1",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **Price (Latest)**\n\n**Endpoint:** `GET /api/v1/market/orderbook/level1`\n**What it does:** Returns the **latest price** and **best bid/ask** for a KuCoin symbol.\n\n**Params:**\n* `symbol` (STRING, required) → KuCoin format with dash, e.g. `BTC-USDT`\n\n**Returns:** fields such as `time`, `symbol`, `price` (last), `bestBid`, `bestBidSize`, `bestAsk`, `bestAskSize`.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\n```\n\n**Notes:** Use this for quick latest price + spread snapshot. For full 24h stats, use `/api/v1/market/stats`."
      },
      "typeVersion": 4.2
    },
    {
      "id": "8fa72375-9547-4920-93f5-f0d37d7f4170",
      "name": "Best Bid/Ask",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        192,
        592
      ],
      "parameters": {
        "url": "https://api.kucoin.com/api/v1/market/orderbook/level1",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **Best Bid/Ask (Book Ticker)**\n\n**Endpoint:** `GET /api/v1/market/orderbook/level1`\n**What it does:** Returns the **best bid/ask** and the **latest price** for a KuCoin symbol.\n\n**Params:**\n* `symbol` (STRING, required) → KuCoin format with dash, e.g. `BTC-USDT`\n\n**Returns:** fields such as `time`, `symbol`, `bestBid`, `bestBidSize`, `bestAsk`, `bestAskSize`, `price` (last).\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\n```\n\n**Notes:** Use for quick spread snapshot. For full book depth, use `/api/v1/market/orderbook/level2_X`."
      },
      "typeVersion": 4.2
    },
    {
      "id": "c621ca98-1c7d-4d30-83f6-f5a1cca5f478",
      "name": "Klines (Candles)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        544,
        592
      ],
      "parameters": {
        "url": "https://api.kucoin.com/api/v1/market/candles",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            },
            {
              "name": "type",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `15min`, 'string') }}"
            },
            {
              "name": "startAt",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', ``, 'number') }}"
            },
            {
              "name": "endAt",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters3_Value', ``, 'number') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **Klines (Candles)**\n\n**Endpoint:** `GET /api/v1/market/candles`\n**What it does:** Retrieve candlestick bars for a KuCoin symbol and interval.\n\n**Params:**\n* `symbol` (STRING, required — e.g., `BTC-USDT`)\n* `type` (ENUM, required — e.g., `1min,3min,5min,15min,30min,1hour,2hour,4hour,6hour,8hour,12hour,1day,1week,1month`)\n* `startAt` (LONG, optional — start time in seconds)\n* `endAt` (LONG, optional — end time in seconds)\n\n**Returns (array per candle):** `[ time, open, close, high, low, volume, turnover ]`\n\n**n8n query mapping:**\n```txt\nsymbol  = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\ntype    = $fromAI('parameters1_Value', '15min', 'string')\nstartAt = $fromAI('parameters2_Value', '', 'number')\nendAt   = $fromAI('parameters3_Value', '', 'number')\n```\n\n**Notes:** Without `startAt` and `endAt`, returns the most recent candles."
      },
      "typeVersion": 4.2
    },
    {
      "id": "0b9d91af-abe1-4d59-99d6-5cc14cfb126b",
      "name": "Average Price (via Ticker)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        880,
        592
      ],
      "parameters": {
        "url": "https://api.kucoin.com/api/v1/market/orderbook/level1",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **Average Price (via Ticker)**\n\n**Endpoint:** `GET /api/v1/market/orderbook/level1`\n**What it does:** Returns the **latest market data** for a symbol, including last trade price, best bid/ask, size, and time.\n\n**Params:**\n* `symbol` (STRING, required — e.g., `BTC-USDT`)\n\n**Returns:** `{ \"symbol\":\"BTC-USDT\",\"bestBid\":\"...\",\"bestAsk\":\"...\",\"price\":\"...\",\"size\":\"...\",\"time\":... }`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\n```\n\n**Notes:** KuCoin does not provide a rolling `avgPrice` endpoint like Binance. Use this for **real-time average proxy** via bid/ask spread and last price."
      },
      "typeVersion": 4.2
    },
    {
      "id": "2164f096-c4b1-4398-b40c-717d87b59330",
      "name": "Recent Trades",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        1216,
        592
      ],
      "parameters": {
        "url": "https://api.kucoin.com/api/v1/market/histories",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `BTC-USDT`, 'string') }}"
            },
            {
              "name": "limit",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `100`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### 🏷 Tool: **Recent Trades**\n\n**Endpoint:** `GET /api/v1/market/histories`\n**What it does:** Returns the **most recent public trades** for a KuCoin symbol.\n\n**Params:**\n* `symbol` (STRING, required) → e.g., `BTC-USDT`\n* `limit`  (INT, optional; default 100)\n\n**Returns:** array of trades like `{ sequence, price, size, side, time }` (newest first).\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'BTC-USDT', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```"
      },
      "typeVersion": 4.2
    },
    {
      "id": "dc96dd65-67dc-4b1d-ada3-b5dd9e586f12",
      "name": "便签17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2144,
        -1136
      ],
      "parameters": {
        "width": 912,
        "height": 3024,
        "content": "# 📄 KuCoin AI Agent v1.02 – Documentation\n\n## 🧩 Overview\n\nThis workflow connects a Telegram bot with an AI agent that can **fetch Spot Market data from the official KuCoin REST API**.\n\n* **Trigger:** Telegram message\n* **Auth:** Telegram user ID check\n* **Core AI Agent:** KuCoin Spot Market Data Agent\n* **Output:** Clean, structured report sent back to Telegram\n\n---\n\n## 🔗 API Access\n\n**Base URL:** `https://api.kucoin.com`\n**Method:** All requests are **HTTP GET**\n**Response:** JSON\n\n---\n\n## 📌 Supported Endpoints\n\n1. **24h Stats**\n\n   * `GET /api/v1/market/stats?symbol=BTC-USDT`\n   * Returns: open, high, low, last, change rate, volume, quote volume, etc.\n\n2. **Order Book Depth**\n\n   * `GET /api/v1/market/orderbook/level2_100?symbol=BTC-USDT`\n   * Returns: top bids/asks up to 100 entries.\n\n3. **Latest Price**\n\n   * `GET /api/v1/market/orderbook/level1?symbol=BTC-USDT`\n   * Returns: best bid, best ask, last traded price.\n\n4. **Klines (Candlestick Data)**\n\n   * `GET /api/v1/market/candles?symbol=BTC-USDT&type=15min&limit=20`\n   * Returns OHLCV data for supported intervals.\n\n5. **Recent Trades**\n\n   * `GET /api/v1/market/histories?symbol=BTC-USDT`\n   * Returns recent trades (price, size, side, time).\n\n---\n\n## 🧩 Utility Tools\n\n* **Calculator** → Math operations (spreads, % change, averages).\n* **Think** → Helper for cleaning JSON, reshaping, formatting outputs.\n\n---\n\n## ⚙️ Workflow Components\n\n### 1. **Telegram Trigger**\n\n* Listens for new Telegram messages.\n* Passes user input downstream.\n\n### 2. **User Authentication**\n\n* Checks Telegram `from.id` against approved ID.\n* Blocks unauthorized users.\n\n### 3. **Adds SessionId**\n\n* Stores Telegram chat ID as `sessionId`.\n* Used for memory + multi-turn conversations.\n\n### 4. **Simple Memory**\n\n* Buffer window memory to track session context.\n\n### 5. **OpenAI Chat Model**\n\n* GPT model (`gpt-4.1-mini`) used for reasoning, structuring responses.\n\n### 6. **KuCoin AI Agent**\n\n* Agent configured with system message:\n\n  * Fetches **only market data** (no predictions or advice).\n  * Uses official **KuCoin API endpoints**.\n  * Always returns structured, readable outputs.\n\n### 7. **Message Splitter**\n\n* Splits GPT output if >4000 chars (Telegram limit).\n\n### 8. **Telegram SendMessage**\n\n* Sends final structured report (or split chunks) back to the user.\n\n---\n\n## 📤 Output Rules\n\n* Clean, human-readable summaries.\n* Grouped into **Price, 24h Stats, Order Book, Klines, Trades**.\n* No raw JSON unless debugging.\n* No financial advice or fabricated values.\n\n---\n\n## ⚠️ Special Notes\n\n* `symbol` format on KuCoin: **BTC-USDT** (with dash, not concatenated).\n* All endpoints are **public**, no API key required.\n* Default `limit` values set for safety (e.g., 20 klines, 100 trades).\n\n\n---\n\n## 🚀 Support & Licensing\n\n🔗 **Don Jayamaha – LinkedIn**\n[linkedin.com/in/donjayamahajr](http://linkedin.com/in/donjayamahajr)\n\n© 2025 Treasurium Capital Limited Company. All rights reserved.\nThis system architecture, prompts, and workflow structure are proprietary and protected by **U.S. copyright law**.\nReuse or resale prohibited without license.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7403d36e-62eb-4baa-933c-915fcf6fc566",
  "connections": {
    "Think": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "24h Stats": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Best Bid/Ask": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Recent Trades": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Price (Latest)": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Adds \"SessionId\"": {
      "main": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Klines (Candles)": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "KuCoin  AI Agent": {
      "main": [
        [
          {
            "node": "Splits message is more than 4000 characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Order Book Depth": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "User Authentication (Replace Telegram ID)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Average Price (via Ticker)": {
      "ai_tool": [
        [
          {
            "node": "KuCoin  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "User Authentication (Replace Telegram ID)": {
      "main": [
        [
          {
            "node": "Adds \"SessionId\"",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Splits message is more than 4000 characters": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

这是一个高级难度的工作流,适用于Crypto Trading、AI Chatbot、Multimodal AI等场景。适合高级用户,包含 16+ 个节点的复杂工作流

需要付费吗?

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

工作流信息
难度等级
高级
节点数量35
分类3
节点类型11
难度说明

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

作者
Don Jayamaha Jr

Don Jayamaha Jr

@don-the-gem-dealer

With 12 years of experience as a Blockchain Strategist and Web3 Architect, I specialize in bridging the gap between traditional industries and decentralized technologies. My expertise spans tokenized assets, crypto payment integrations, and blockchain-driven market solutions.

外部链接
在 n8n.io 上查看 →

分享此工作流