{
  "id": "kZ3wJtLi5OI0WzFF",
  "name": "HTX AI Agent v1.02",
  "tags": [],
  "nodes": [
    {
      "id": "297e04f4-eea6-483a-ac66-b7eaa8736c75",
      "name": "OpenAI Chat Model",
      "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": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9a3813bf-2888-47d9-b6fe-ae4d6acff278",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1008,
        240
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "24b0013b-ad84-4e59-b8eb-47bf0c44ebb4",
      "name": "User Authentication (Replace 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": "5c213506-27d4-448a-86a7-4bd310a8d3d3",
      "name": "Adds \"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": "d46968c2-f161-4b84-8d7a-afbe3d273b55",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        896,
        240
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9c52c121-7184-4f3f-a6ca-a6ff152486ac",
      "name": "Splits message is more than 4000 characters",
      "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": "3fdfb9bf-1c8e-41de-8a3f-d31251024614",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        -32
      ],
      "parameters": {
        "color": 4,
        "height": 460,
        "content": "## Trigger Incoming Telegram Command\nNode: Telegram Trigger\n**Listens for new Telegram messages** from users.\nTriggers the full agent process and passes raw user input downstream."
      },
      "typeVersion": 1
    },
    {
      "id": "b3ecb16d-982a-4199-961e-734b9bfd8045",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -32
      ],
      "parameters": {
        "color": 2,
        "height": 460,
        "content": "## Validate User Access\nNode: User **Authentication\nChecks incoming Telegram ID** against the approved user list."
      },
      "typeVersion": 1
    },
    {
      "id": "ee812a3d-e975-4c84-9725-592c4cf00d95",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        -32
      ],
      "parameters": {
        "color": 5,
        "height": 460,
        "content": "## Generate Session Metadata\nNode: Add S**essionId\nCreates a sessionId using the Telegram chat_id**.\nThis is passed into all downstream tools for memory and workflow routing."
      },
      "typeVersion": 1
    },
    {
      "id": "57c343be-dc21-4ede-bfeb-5f94bb2a3d6b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -496
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 932,
        "content": "## Main AI Agent: Data Fetcher (HTX)\n\n**Node: HTX Data Agent**\nThis is the **core orchestrator**. It uses OpenAI **only to format and present raw HTX market data**, not to analyze or generate strategies.\n\nIt has direct **HTTP request access** to the **HTX REST API** (`https://api.huobi.pro`) and retrieves:\n\n* **Live Price (Aggregated Ticker)** \u2014 `/market/detail/merged`\n  Returns best bid/ask + last trade price, volume, turnover.\n\n* **24h Market Summary** \u2014 `/market/detail`\n  Rolling 24-hour stats: open, high, low, close, volume, amount, count.\n\n* **Market Depth** \u2014 `/market/depth`\n  Order book bids/asks up to requested step/levels.\n\n* **Full Order Book** \u2014 `/market/fullMbp`\n  Complete market depth, up to **5000 levels**, refreshed once per second.\n\n* **Last Trade** \u2014 `/market/trade`\n  The latest executed trade.\n\n* **Recent Trades** \u2014 `/market/history/trade`\n  Most recent trades list.\n\n* **Klines (Candlesticks)** \u2014 `/market/history/kline`\n  Supports multiple intervals (`1s, 1min, 5min, 15min, 1day, 1week, 1mon, 1year`, etc.).\n  The AI chooses the correct interval keyword (`seconds, minutes, days, weeks, months, years`).\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c308c89f-1650-4cf4-8845-51c45f1e6876",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        -32
      ],
      "parameters": {
        "color": 5,
        "width": 260,
        "height": 460,
        "content": "## Handle Telegram Message Limits\nNode: Code (split logic)\nChecks if the **GPT output exceeds 4000 characters**.\nIf so, it splits the message into safe chunks and passes them on sequentially."
      },
      "typeVersion": 1
    },
    {
      "id": "e95075f4-d564-4009-8511-c8d7c2f77370",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -32
      ],
      "parameters": {
        "color": 4,
        "height": 460,
        "content": "## Send Final Report to Telegram\nNode: Telegram sendMessage\nSends **formatted HTML report (or split chunks)** directly to the authenticated user via Telegram bot."
      },
      "typeVersion": 1
    },
    {
      "id": "9caa9127-eb4d-42f2-833b-f8ce8396edd7",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1344,
        640
      ],
      "parameters": {
        "height": 540,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## GPT Model for Reasoning\nNode: OpenAI Chat Model\nModel: **gpt-4o-mini**\nUsed to:\n\nInterpret signal values\n\nGenerate structured HTML\n\n**Recommend spot and leverage trades**\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9538e331-7ae2-4d6f-97c7-6dfd66ccbe58",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1076,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Order Book Depth**\n\n**Endpoint:** `GET /market/depth`\n\n**What it does:** Returns the **order book snapshot** (bids/asks) for a trading pair up to the requested depth level.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n- `type` (STRING, required) \u2192 depth aggregation level (`step0`\u2013`step5`)\n  - `step0` = no aggregation (full precision)\n  - `step1` = aggregated to 1 decimal place\n  - \u2026 up to `step5`\n- `depth` (INT, optional) \u2192 max entries per side (default 20, max 150)\n\n**Returns:** `ts`, `tick.bids: [[price, qty], ...]`, `tick.asks: [[price, qty], ...]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\ntype   = $fromAI('parameters1_Value', 'step0', 'string')\ndepth  = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:** For lightweight quick book snapshot, use `step0` with smaller depth (20/50)."
      },
      "typeVersion": 1
    },
    {
      "id": "540558b9-6cbe-49be-937e-234489be85fa",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 868,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Best Bid/Ask (Order Book Ticker)**\n\n**Endpoint:** `GET /market/detail/merged`\n\n**What it does:** Returns the best **bid/ask** snapshot along with the latest trade price for a symbol.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n\n**Returns:** `tick.bid` = `[price, qty]`, `tick.ask` = `[price, qty]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** Use lowercase symbols without `-` or `/` (e.g., `btcusdt`)."
      },
      "typeVersion": 1
    },
    {
      "id": "803bcfaf-7d72-4616-b459-e6ad8db4ac8c",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        640
      ],
      "parameters": {
        "color": 3,
        "height": 540,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Short-Term Memory Module\nNode: **Simple Memory\nStores the sessionId**, symbol, and other state data.\nUseful for:\n\nMulti-turn Telegram interactions\n\nTracking indicator agreement across timeframes\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "98ebfd96-fa61-4908-9bc0-feb3c57c191b",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -992,
        736
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "3438fe42-4c59-4ebf-9633-70dc3243c244",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 884,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **24h Stats (Ticker Detail)**\n\n**Endpoint:** `GET /market/detail`\n**What it does:** Returns the **24h rolling summary** for a single HTX spot symbol: **open/high/low/close**, **amount (base volume)**, **vol (quote turnover)**, and **trade count**.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n\n**Returns (core fields):** `ts`, `tick.open`, `tick.close`, `tick.high`, `tick.low`, `tick.amount`, `tick.vol`, `tick.count`.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** For all symbols at once, use `GET /market/tickers`.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "6811afcf-331a-4120-aa73-5612cf980f67",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 820,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ### **Price (Latest)**\n\n**Endpoint:** `GET /market/detail/merged`\n\n**What it does:** Returns the **latest trade price**, best bid/ask, and other snapshot details for a symbol.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n\n**Returns:** `tick.close` = last trade price, plus bid/ask/volumes.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** Use lowercase symbols without `-` or `/` (e.g., `btcusdt`)."
      },
      "typeVersion": 1
    },
    {
      "id": "5ef7dc9e-d003-4b36-bf4f-61ede9307fc5",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1060,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Klines (Candles)**\n\n**Endpoint:** `GET /market/history/kline`\n\n**What it does:** Returns candlestick data for a symbol/interval.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 lowercase (e.g., `btcusdt`)\n- `period` (ENUM, required \u2014 e.g., `1min,5min,15min,30min,60min,4hour,1day,1mon,1week,1year`)\n- `size` (INT, optional, default 20, max 2000)\n\n**Returns (array per candle):** `[id, open, close, low, high, amount, vol, count]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\nperiod = $fromAI('parameters1_Value', '15min', 'string')\nsize   = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:**\n- Use lowercase symbols without `-` (e.g., `btcusdt`).\n- If no `size` provided, defaults to 20 latest candles."
      },
      "typeVersion": 1
    },
    {
      "id": "b155271b-7656-4a6e-9e24-9496e18b77f8",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 900,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Merged Ticker (Bid/Ask/Last)**\n\n**Endpoint:** `GET /market/detail/merged`\n**What it does:** Returns best bid/ask and last price for a symbol. Use Calculator to derive a midpoint `(bid+ask)/2` if you need an average.\n\n**Params:** `symbol` (STRING, required) \u2192 lowercase, no dash (e.g., `btcusdt`)\n\n**Returns (key fields):** `tick.bid`, `tick.ask`, `tick.close`, `tick.high`, `tick.low`, `tick.amount`, `tick.vol`, `ts`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** HTX has no direct avg-price endpoint; this is the canonical ticker to pair with Calculator for midpoint."
      },
      "typeVersion": 1
    },
    {
      "id": "c999ffb2-e531-4111-b3b5-6d001343af02",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 868,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Recent Trades**\n\n**Endpoint:** `GET /market/history/trade`\n**What it does:** Returns the most recent trades for a given symbol.\n\n**Params:**\n* `symbol` (STRING, required) \u2192 lowercase, no dash (e.g., `btcusdt`)\n* `size` (INT, default 100, max 2000 \u2014 we set default 100)\n\n**Returns:** array of trade batches \u2192 each batch has `data: [{id, price, amount, direction, ts}]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\nsize   = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** Unlike Binance, HTX nests trades inside `data` arrays per batch."
      },
      "typeVersion": 1
    },
    {
      "id": "699f4811-924c-4734-add9-7e92453f22a5",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        1520,
        592
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9f866f49-6516-4248-8092-28fe70363c7e",
      "name": "Think",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        1808,
        592
      ],
      "parameters": {
        "description": "### \ud83c\udff7 Tool: **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 \u2192 Think \u2192 Report Agent."
      },
      "typeVersion": 1.1
    },
    {
      "id": "e05fedc2-d50f-4bb5-a499-e96a16f2d3bf",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 836,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Calculator**\n\n**Purpose:**\n\n* Perform **math operations** inside the workflow.\n* Supports add/subtract/multiply/divide, percentages, rounding, etc.\n\n**Use cases:**\n\n* Calculate spreads (ask \u2013 bid)\n* Compute % changes from open vs. last price\n* Normalize volumes or confidence scores\n\n**n8n setup notes:**\n\n* Node: `Calculator` (n8n built-in)\n* Input fields can come from Binance API JSON\n* Output can be chained into Think \u2192 Final Report\n"
      },
      "typeVersion": 1
    },
    {
      "id": "6e6d72dc-2560-4a28-bbb5-0bd53b70f3c7",
      "name": "Sticky Note16",
      "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 \u2192 Think \u2192 Report Agent."
      },
      "typeVersion": 1
    },
    {
      "id": "60b4a1c1-a32f-4679-8818-e09f7ba2c25e",
      "name": "HTX AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -96,
        240
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "You are the **HTX Spot Market Data Agent**.\n\nYou have **HTTP request access** to the official **HTX REST API** (`https://api.huobi.pro`) to retrieve spot market data for any requested trading pair.\n\nYour job is to **fetch and present raw market data only**.  \nYou do **not** analyze, predict, or recommend.\n\n---\n\n## \ud83d\udd17 Available Endpoints\n\n1. **Live Price (Aggregated Ticker)**  \n   `GET /market/detail/merged`  \n   \u2022 Returns best bid/ask, last trade price, volume, turnover.\n\n2. **24h Market Summary**  \n   `GET /market/detail`  \n   \u2022 24h stats: open, high, low, close, volume, amount, count.\n\n3. **Market Depth**  \n   `GET /market/depth`  \n   \u2022 Order book bids/asks (step/levels configurable).\n\n4. **Full Order Book**  \n   `GET /market/fullMbp`  \n   \u2022 Complete market depth (up to 5000 levels).\n\n5. **Last Trade**  \n   `GET /market/trade`  \n   \u2022 Most recent single trade.\n\n6. **Recent Trades**  \n   `GET /market/history/trade`  \n   \u2022 List of recent trades.\n\n7. **Klines (Candlesticks)**  \n   `GET /market/history/kline`  \n   \u2022 Multiple intervals supported (`1s, 1min, 5min, 15min, 1day, 1week, 1mon, 1year`).  \n   \u2022 The AI automatically selects the correct interval (`seconds, minutes, days, weeks, months, years`).\n\n---\n\n## \ud83d\udce4 Output Format\n\nAlways respond in **clean, structured text** (Telegram HTML). Example:\n\n```\n\nBTC-USDT \u2014 HTX Spot Data\n\nPrice\n\u2022 Last: 58000.12\n\u2022 Change (24h): +2.4%\n\n24h Stats\n\u2022 Open: 56500 \u2022 High: 58500 \u2022 Low: 56200\n\u2022 Volume: 12,430 BTC \u2022 Turnover: 720M USDT\n\nOrder Book (Top 5)\n\u2022 Bids: \\[57990 x 0.5], \\[57980 x 1.2], \u2026\n\u2022 Asks: \\[58010 x 0.8], \\[58020 x 1.5], \u2026\n\nKlines (15m, latest 5)\n\u2022 O/H/L/C: 57800 / 58020 / 57750 / 57990\n\n```\n\n---\n\n## \u26a0\ufe0f Rules\n\n* Always **call the correct HTX API endpoint**.  \n* Do **not** fabricate or calculate values (except simple formatting).  \n* Do **not** output raw JSON.  \n* Do **not** give advice, predictions, or strategies.  \n* If data is missing, output `N/A`.\n```\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "8e68fe2c-a84c-4340-b6c8-e9d0a69c717b",
      "name": "24h Stats",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -704,
        608
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/detail",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **24h Stats (Ticker Detail)**\n\n**Endpoint:** `GET /market/detail`\n**What it does:** Returns the **24h rolling summary** for a single HTX spot symbol: **open/high/low/close**, **amount (base volume)**, **vol (quote turnover)**, and **trade count**.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n\n**Returns (core fields):** `ts`, `tick.open`, `tick.close`, `tick.high`, `tick.low`, `tick.amount`, `tick.vol`, `tick.count`.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** For all symbols at once, use `GET /market/tickers`.\n"
      },
      "typeVersion": 4.2
    },
    {
      "id": "0a3e5648-3f35-4ba8-bed1-3b60f307f001",
      "name": "Order Book Depth",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -400,
        608
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/depth",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            },
            {
              "name": "type",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `step0`, 'string') }}"
            },
            {
              "name": "depth",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', `20`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Order Book Depth**\n\n**Endpoint:** `GET /market/depth`\n\n**What it does:** Returns the **order book snapshot** (bids/asks) for a trading pair up to the requested depth level.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n- `type` (STRING, required) \u2192 depth aggregation level (`step0`\u2013`step5`)\n  - `step0` = no aggregation (full precision)\n  - `step1` = aggregated to 1 decimal place\n  - \u2026 up to `step5`\n- `depth` (INT, optional) \u2192 max entries per side (default 20, max 150)\n\n**Returns:** `ts`, `tick.bids: [[price, qty], ...]`, `tick.asks: [[price, qty], ...]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\ntype   = $fromAI('parameters1_Value', 'step0', 'string')\ndepth  = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:** For lightweight quick book snapshot, use `step0` with smaller depth (20/50)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "0df3137a-638e-4c99-8121-c8d119566ca8",
      "name": "Price (Latest)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -112,
        608
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/detail/merged",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Price (Latest)**\n\n**Endpoint:** `GET /market/detail/merged`\n\n**What it does:** Returns the **latest trade price**, best bid/ask, and other snapshot details for a symbol.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n\n**Returns:** `tick.close` = last trade price, plus bid/ask/volumes.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** Use lowercase symbols without `-` or `/` (e.g., `btcusdt`)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "2a5e0910-992b-409d-83d5-5af4121f71af",
      "name": "Best Bid/Ask",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        208,
        608
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/detail/merged",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Best Bid/Ask (Order Book Ticker)**\n\n**Endpoint:** `GET /market/detail/merged`\n\n**What it does:** Returns the best **bid/ask** snapshot along with the latest trade price for a symbol.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 e.g., `btcusdt` (lowercase, no dash)\n\n**Returns:** `tick.bid` = `[price, qty]`, `tick.ask` = `[price, qty]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** Use lowercase symbols without `-` or `/` (e.g., `btcusdt`)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "c31f039c-42da-47ed-9c7a-bd47dd276634",
      "name": "Klines (Candles)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        544,
        592
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/history/kline",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            },
            {
              "name": "period",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `15min`, 'string') }}"
            },
            {
              "name": "size",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', `20`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Klines (Candles)**\n\n**Endpoint:** `GET /market/history/kline`\n\n**What it does:** Returns candlestick data for a symbol/interval.\n\n**Params:**\n- `symbol` (STRING, required) \u2192 lowercase (e.g., `btcusdt`)\n- `period` (ENUM, required \u2014 e.g., `1min,5min,15min,30min,60min,4hour,1day,1mon,1week,1year`)\n- `size` (INT, optional, default 20, max 2000)\n\n**Returns (array per candle):** `[id, open, close, low, high, amount, vol, count]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\nperiod = $fromAI('parameters1_Value', '15min', 'string')\nsize   = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:**\n- Use lowercase symbols without `-` (e.g., `btcusdt`).\n- If no `size` provided, defaults to 20 latest candles."
      },
      "typeVersion": 4.2
    },
    {
      "id": "b773e24e-b4b3-49b2-82a5-89a110613538",
      "name": "Average Price",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        880,
        592
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/detail/merged",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Merged Ticker (Bid/Ask/Last)**\n\n**Endpoint:** `GET /market/detail/merged`\n**What it does:** Returns best bid/ask and last price for a symbol. Use Calculator to derive a midpoint `(bid+ask)/2` if you need an average.\n\n**Params:** `symbol` (STRING, required) \u2192 lowercase, no dash (e.g., `btcusdt`)\n\n**Returns (key fields):** `tick.bid`, `tick.ask`, `tick.close`, `tick.high`, `tick.low`, `tick.amount`, `tick.vol`, `ts`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\n```\n\n**Notes:** HTX has no direct avg-price endpoint; this is the canonical ticker to pair with Calculator for midpoint."
      },
      "typeVersion": 4.2
    },
    {
      "id": "96a09dbc-cfd5-46d2-ba6a-1cb4dfd661b3",
      "name": "Recent Trades",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        1216,
        592
      ],
      "parameters": {
        "url": "https://api.huobi.pro/market/history/trade",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `btcusdt`, 'string') }}"
            },
            {
              "name": "size",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `100`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Recent Trades**\n\n**Endpoint:** `GET /market/history/trade`\n**What it does:** Returns the most recent trades for a given symbol.\n\n**Params:**\n* `symbol` (STRING, required) \u2192 lowercase, no dash (e.g., `btcusdt`)\n* `size` (INT, default 100, max 2000 \u2014 we set default 100)\n\n**Returns:** array of trade batches \u2192 each batch has `data: [{id, price, amount, direction, ts}]`\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', 'btcusdt', 'string')\nsize   = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** Unlike Binance, HTX nests trades inside `data` arrays per batch."
      },
      "typeVersion": 4.2
    },
    {
      "id": "29213890-b332-491a-80f3-589cc94c7aab",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2128,
        -992
      ],
      "parameters": {
        "width": 1200,
        "height": 2464,
        "content": "# \ud83e\udde0 HTX Spot Market Data AI Agent \u2013 Full System Documentation\n\nA specialized AI automation system for **HTX (Huobi) spot market data retrieval**.\nIt fetches and formats **live market data** only \u2014 **no predictions, no strategies**.\nOutputs are structured into **Telegram-ready reports** for traders and analysts.\n\n---\n\n## \ud83e\udde9 Included Workflows\n\nYou must install and activate **all of the following workflows/tools** for the system to function:\n\n| \u2705 Workflow / Tool Name | \ud83d\udccc Function Description                                                                  |\n| ---------------------- | ---------------------------------------------------------------------------------------- |\n| HTX AI Agent           | Core orchestrator. Calls HTX REST APIs and formats raw data into Telegram-ready reports. |\n| 24h Stats Tool         | Pulls rolling 24-hour OHLC, volume, and trade count for a symbol.                        |\n| Price (Latest) Tool    | Fetches the latest trade price and best bid/ask.                                         |\n| Best Bid/Ask Tool      | Returns top-of-book bid/ask snapshot.                                                    |\n| Order Book Depth Tool  | Retrieves order book bids/asks with configurable depth aggregation.                      |\n| Klines (Candles) Tool  | Returns OHLCV candlestick data for configurable intervals (1m\u20131y).                       |\n| Recent Trades Tool     | Shows most recent executed trades.                                                       |\n| Average Price Tool     | Computes midpoint between bid/ask using Calculator (HTX has no direct avg-price).        |\n| Calculator             | Performs math inside workflow (e.g., spreads, % changes).                                |\n| Think                  | Lightweight reasoning helper (JSON cleanup, formatting).                                 |\n| Simple Memory          | Stores `sessionId` and symbol state for continuity across Telegram interactions.         |\n\n---\n\n## \u2699\ufe0f Installation Instructions\n\n### Step 1: Import Workflows\n\n* Open **n8n Editor UI**\n* Import the JSON file(s) provided (`HTX AI Agent v1.02.json`)\n* Activate the workflows\n\n### Step 2: Set Credentials\n\n* **OpenAI API Credential** \u2192 for GPT-4.1-mini (formatting only)\n* **Telegram API Credential** \u2192 Bot key for sending/receiving messages\n* **HTX Market Data** \u2192 No auth required (public endpoints)\n\n### Step 3: Configure Webhook & Auth\n\n* Update the **Telegram ID Check node** with your personal Telegram ID\n* Only this ID can trigger the agent\n\n### Step 4: Deploy & Test\n\n* Send a symbol (e.g., `btcusdt`) to your Telegram bot\n* Agent retrieves live data and formats into a clean HTML report\n\n---\n\n## \ud83d\udda5\ufe0f System Workflow Overview\n\n```\n[Telegram Trigger]\n\u2192 [User Authentication]\n\u2192 [Add SessionId + Memory]\n\u2192 [HTX AI Agent]\n   \u21b3 (24h Stats, Price, Best Bid/Ask, Order Book, Klines, Trades)\n   \u21b3 (Calculator + Think for cleanup/formatting)\n\u2192 [Split Messages > 4000 chars]\n\u2192 [Telegram SendMessage]\n```\n\n---\n\n## \ud83d\udcec Telegram Output Style\n\n```html\n<b>HTX Market Data \u2013 BTCUSDT</b>\n\n<b>Price</b>\n\u2022 Last: 58,000.12\n\u2022 Best Bid: 57,990 | Best Ask: 58,010\n\n<b>24h Stats</b>\n\u2022 Open: 56,500 | High: 58,500 | Low: 56,200\n\u2022 Volume: 12,430 BTC | Turnover: 720M USDT\n\n<b>Order Book (Top 5)</b>\n\u2022 Bids: [57,990 x 0.5], [57,980 x 1.2] \u2026\n\u2022 Asks: [58,010 x 0.8], [58,020 x 1.5] \u2026\n\n<b>Klines (15m, last 3)</b>\n\u2022 O/H/L/C: 57,800 / 58,020 / 57,750 / 57,990\n```\n\n---\n\n## \u26a0\ufe0f Rules\n\n* Only fetch and format data \u2014 **no trading signals or advice**\n* Always use lowercase symbols (e.g., `btcusdt`)\n* Do not output raw JSON \u2014 must be formatted for Telegram\n* If data missing \u2192 show `N/A`\n\n---\n\n## \ud83d\ude80 Support & Licensing\n\n\ud83d\udd17 **Don Jayamaha \u2013 LinkedIn**\n[linkedin.com/in/donjayamahajr](http://linkedin.com/in/donjayamahajr)\n\n\u00a9 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\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4d9a7688-a32d-4e45-a66c-a30c88d00a81",
  "connections": {
    "Think": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "24h Stats": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Best Bid/Ask": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "HTX AI Agent": {
      "main": [
        [
          {
            "node": "Splits message is more than 4000 characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Average Price": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Recent Trades": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Price (Latest)": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Adds \"SessionId\"": {
      "main": [
        [
          {
            "node": "HTX AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Klines (Candles)": {
      "ai_tool": [
        [
          {
            "node": "HTX AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Order Book Depth": {
      "ai_tool": [
        [
          {
            "node": "HTX 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": "HTX AI Agent",
            "type": "ai_languageModel",
            "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
          }
        ]
      ]
    }
  }
}