{
  "id": "1q1EuK6N4ULsoeUA",
  "name": "MEXC AI Agent v1.02",
  "tags": [],
  "nodes": [
    {
      "id": "509f7786-0fe9-472c-8f35-4180b8622f97",
      "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": "e3f53c77-e359-401a-85c6-4672d2f5df73",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1008,
        240
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "db8dfe71-a517-44f6-9342-e4d966257073",
      "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": "9e094e7b-6ba8-4bce-85db-a958af250821",
      "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": "65bc0b79-576a-4d60-a35b-1c63c64292eb",
      "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": "b740b5b9-44af-4330-99f0-7992c737762d",
      "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": "1179e9f3-9eec-4bea-a108-7c79ace4ce51",
      "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": "592f562b-3dfe-4feb-8866-c9ba55f58b06",
      "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": "bc24396e-13b6-4827-a5f2-d75bf00e35e6",
      "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": "4878293f-7811-424d-9414-8f950d300942",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -640
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 1076,
        "content": "# Main AI Agent: Data Fetcher (MEXC)\n\n**Role:** Fetch and format Spot market data from the official **MEXC REST API**.\nThe agent retrieves requested data but does **not** analyze, predict, or recommend.\n\n---\n\n## \ud83d\udd17 API Access\n\n**Base URL:** `https://api.mexc.com`\n**Method:** All requests are **HTTP GET**\n**Response:** JSON\n\n---\n\n## \ud83d\udccc Supported Endpoints\n\n* `/api/v3/depth` \u2192 Order Book Depth\n* `/api/v3/ticker/price` \u2192 Latest Price\n* `/api/v3/ticker/bookTicker` \u2192 Best Bid/Ask\n* `/api/v3/klines` \u2192 Klines (Candlestick Data)\n* `/api/v3/avgPrice` \u2192 Current Average Price\n* `/api/v3/ticker/24hr` \u2192 24h Stats\n* `/api/v3/trades` \u2192 Recent Trades\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "02f4d538-539c-4143-97ec-d18261582786",
      "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": "7c38d187-ef89-4b12-a82e-be105a395580",
      "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": "f23aa644-d50a-4bbf-85d1-7bd8c2be868b",
      "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": "7854ec4c-6ea8-44e3-ad47-0c825aaf6b79",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        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### **Order Book Depth**\n\n**Endpoint:** `GET /api/v3/depth`\n**What it does:** Returns **order book** bids/asks up to `limit`.\n**Params:**\n\n* `symbol` (STRING, required)\n* `limit` (INT, default 100; max 5000; we default 100)\n  **Request weight:** varies by `limit` (1\u2013100 \u2192 5; 101\u2013500 \u2192 25; 501\u20131000 \u2192 50; 1001\u20135000 \u2192 250).\n  **Returns:** `lastUpdateId`, `bids: [[price, qty], ...]`, `asks: [[price, qty], ...]`\n  **n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** If `limit > 5000`, only 5000 are returned."
      },
      "typeVersion": 1
    },
    {
      "id": "50d80156-70fb-4ddb-883c-47b5c6f8ff94",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 756,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Best Bid/Ask (Book Ticker)**\n\n**Endpoint:** `GET /api/v3/ticker/bookTicker`\n**What it does:** Best **bid/ask** and sizes for the symbol.\n**Params:** `symbol` (optional; **we send it**)\n**Request weight:** `2` with `symbol`, `4` otherwise.\n**Returns:** `{\"symbol\":\"BTCUSDT\",\"bidPrice\":\"...\",\"bidQty\":\"...\",\"askPrice\":\"...\",\"askQty\":\"...\"}`\n**n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Great for quick spread snapshot."
      },
      "typeVersion": 1
    },
    {
      "id": "b66bf2ca-197a-49b8-b308-6b7dc4dcaba1",
      "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": "58c4d2f7-9f02-4e4c-a10f-d4ce4500c5e1",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -992,
        736
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "b987b3a6-654b-4e4d-974d-31070b800d53",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 948,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **24h Stats**\n\n**Endpoint:** `GET /api/v3/ticker/24hr`\n**What it does:** 24-hour rolling window stats for a symbol: **open/high/low/last**, **volume**, **quoteVolume**, **% change**, etc.\n**Params:**\n\n* `symbol` (STRING, optional but we send it)\n  **Request weight:** `2` with one `symbol`; heavier without or with many symbols.\n  **Returns (FULL):** priceChange, priceChangePercent, weightedAvgPrice, openPrice, highPrice, lowPrice, lastPrice, volume, quoteVolume, openTime, closeTime, firstId, lastId, count.\n  **n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** This is MEXC\u2019s 24h rolling stats endpoint."
      },
      "typeVersion": 1
    },
    {
      "id": "2592fce2-8256-41c4-bff6-6c591ef448af",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 772,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Price (Latest)**\n\n**Endpoint:** `GET /api/v3/ticker/price`\n**What it does:** Returns the **latest trade price** for a symbol.\n**Params:** `symbol` (STRING, optional for all symbols; **we send it**)\n**Request weight:** `2` with `symbol` (otherwise `4`).\n**Returns:** `{\"symbol\":\"BTCUSDT\",\"price\":\"...\"}`\n**n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Use UPPERCASE symbols without `-` or `/` (e.g., `BTCUSDT`)."
      },
      "typeVersion": 1
    },
    {
      "id": "2dee34c5-7fb5-4719-8c1c-aadb2e6f505f",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1044,
        "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 /api/v3/klines`\n**What it does:** Candlestick bars for a symbol/interval.\n**Params:**\n\n* `symbol` (STRING, required)\n* `interval` (ENUM, required \u2014 e.g., `1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M`)\n* `limit` (INT, default 500, max 1000 \u2014 **we set 20**)\n* `startTime`, `endTime` (optional)\n  **Request weight:** `1`.\n  **Returns (array per candle):** `[ openTime, open, high, low, close, volume, closeTime, quoteAssetVolume, numberOfTrades, takerBuyBaseVolume, takerBuyQuoteVolume ]`\n  **n8n query mapping:**\n\n```txt\nsymbol  = $fromAI('parameters0_Value', '', 'string')\ninterval= $fromAI('parameters1_Value', '15m', 'string')\nlimit   = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:** Without `startTime/endTime`, returns most recent."
      },
      "typeVersion": 1
    },
    {
      "id": "708926f9-de91-4f44-98d1-ad12d64bfca7",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 740,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Average Price**\n\n**Endpoint:** `GET /api/v3/avgPrice`\n**What it does:** **Current average price** for a symbol (rolling window).\n**Params:** `symbol` (STRING, required)\n**Request weight:** `1`.\n**Returns:** `{\"mins\":5,\"price\":\"...\",\"closeTime\":...}`\n**n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Use UPPERCASE trading pairs without `-` (e.g., `BTCUSDT`)."
      },
      "typeVersion": 1
    },
    {
      "id": "823331b2-cf79-4d2c-8d1c-ba88d6020e1f",
      "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### \ud83c\udff7 Tool: **Recent Trades**\n\n**Endpoint:** `GET /api/v3/trades`\n**What it does:** Returns the **most recent public trades** for a symbol on MEXC.\n\n**Params:**\n* `symbol` (STRING, required)\n* `limit`  (INT, optional; default 100, max 1000)\n\n**Returns:** array of trades like `{ id, price, qty, quoteQty, time, isBuyerMaker, isBestMatch }`.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** For older historical trades, use the exchange's historical endpoint if available."
      },
      "typeVersion": 1
    },
    {
      "id": "f200193a-0cac-438a-83b7-68161d31339b",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        1520,
        592
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "662db1c1-de85-4366-9c39-9a06c966e3fd",
      "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": "3f788bd6-e273-4bdb-9757-54880f11f78b",
      "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": "f24a5b6c-868e-43c6-90e4-b63215c73992",
      "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": "2e90a645-3250-4b92-be55-76831e120646",
      "name": "MEXC  AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -96,
        240
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "You are the **MEXC Spot Market Data Agent**.\n\nYou have **HTTP request access** to the official **MEXC REST API** to retrieve market data for any requested Spot trading pair.\nYour role is to **fetch and present raw market data only**. You do **not** analyze, predict, or recommend.\n\n---\n\n## \ud83d\udd17 API Access\n\n**Base endpoint (Spot API):**\n\n* `https://api.mexc.com`\n\n**Format rules:**\n\n* All requests are **HTTP GET**\n* Responses are **JSON**\n* Parameters use query strings (e.g., `?symbol=BTCUSDT&limit=100`)\n* `symbol` is always uppercase, no `/` or `-` (e.g., `BTCUSDT`)\n\n---\n\n## \ud83d\udccc Available Market Data Endpoints\n\n1. **24h Stats**\n   `GET /api/v3/ticker/24hr?symbol=BTCUSDT`\n   \u2022 Returns 24h open, high, low, last, % change, volume, quote volume, etc.\n\n2. **Order Book Depth**\n   `GET /api/v3/depth?symbol=BTCUSDT&limit=100`\n   \u2022 Returns top bids/asks with quantities.\n\n3. **Latest Symbol Price**\n   `GET /api/v3/ticker/price?symbol=BTCUSDT`\n   \u2022 Returns the latest trade price.\n\n4. **Order Book Best Bid/Ask**\n   `GET /api/v3/ticker/bookTicker?symbol=BTCUSDT`\n   \u2022 Returns best bid/ask with sizes.\n\n5. **Kline / Candlestick Data**\n   `GET /api/v3/klines?symbol=BTCUSDT&interval=15m&limit=20`\n   \u2022 Returns OHLCV data for supported intervals.\n\n6. **Current Average Price**\n   `GET /api/v3/avgPrice?symbol=BTCUSDT`\n   \u2022 Returns rolling average price.\n\n7. **Recent Trades**\n   `GET /api/v3/trades?symbol=BTCUSDT&limit=100`\n   \u2022 Most recent trades (id, price, qty, time, isBuyerMaker, etc.).\n\n---\n\n## \ud83e\udde9 Utility Tools\n\n* **Calculator** \u2192 Perform math (spreads, % changes, ratios).\n* **Think** \u2192 Lightweight reasoning helper for restructuring JSON, selecting fields, and preparing outputs.\n\n---\n\n## \ud83d\udce4 Output Format\n\n* Output must be **structured, clean, and human-readable**.\n* Group data logically (Price, 24h Stats, Order Book, Klines, Trades).\n* Do **not** output raw JSON.\n* Do **not** include HTML unless explicitly required by workflow.\n\n---\n\n## \u26a0\ufe0f Rules\n\n* Always use the **correct API endpoint**.\n* Do **not fabricate values**.\n* Do **not provide trading advice or predictions**.\n* If data is missing or request fails, return `N/A`.\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "a9812b9e-19d1-4979-94bf-b58a69384b11",
      "name": "24h Stats",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -704,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/ticker/24hr",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **24h Stats**\n\n**Endpoint:** `GET /api/v3/ticker/24hr`\n**What it does:** 24-hour rolling window stats for a symbol: **open/high/low/last**, **volume**, **quoteVolume**, **% change**, etc.\n**Params:**\n\n* `symbol` (STRING, optional but we send it)\n  **Request weight:** `2` with one `symbol`; heavier without or with many symbols.\n  **Returns (FULL):** priceChange, priceChangePercent, weightedAvgPrice, openPrice, highPrice, lowPrice, lastPrice, volume, quoteVolume, openTime, closeTime, firstId, lastId, count.\n  **n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** This is MEXC\u2019s 24h rolling stats endpoint."
      },
      "typeVersion": 4.2
    },
    {
      "id": "ad3fda69-752b-4aac-af8e-ad9570f380ec",
      "name": "Order Book Depth",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -400,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/depth",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "limit",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `100`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Order Book Depth**\n\n**Endpoint:** `GET /api/v3/depth`\n**What it does:** Returns **order book** bids/asks up to `limit`.\n**Params:**\n\n* `symbol` (STRING, required)\n* `limit` (INT, default 100; max 5000; we default 100)\n  **Request weight:** varies by `limit` (1\u2013100 \u2192 5; 101\u2013500 \u2192 25; 501\u20131000 \u2192 50; 1001\u20135000 \u2192 250).\n  **Returns:** `lastUpdateId`, `bids: [[price, qty], ...]`, `asks: [[price, qty], ...]`\n  **n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** If `limit > 5000`, only 5000 are returned."
      },
      "typeVersion": 4.2
    },
    {
      "id": "9fac6382-44f7-467e-a4b2-8d8ff64889c7",
      "name": "Price (Latest)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -112,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/ticker/price",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Price (Latest)**\n\n**Endpoint:** `GET /api/v3/ticker/price`\n**What it does:** Returns the **latest trade price** for a symbol.\n**Params:** `symbol` (STRING, optional for all symbols; **we send it**)\n**Request weight:** `2` with `symbol` (otherwise `4`).\n**Returns:** `{\"symbol\":\"BTCUSDT\",\"price\":\"...\"}`\n**n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Use UPPERCASE symbols without `-` or `/` (e.g., `BTCUSDT`)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "70986b84-a668-4e64-9631-c941cd6b7d81",
      "name": "Best Bid/Ask",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        208,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/ticker/bookTicker",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Best Bid/Ask (Book Ticker)**\n\n**Endpoint:** `GET /api/v3/ticker/bookTicker`\n**What it does:** Best **bid/ask** and sizes for the symbol.\n**Params:** `symbol` (optional; **we send it**)\n**Request weight:** `2` with `symbol`, `4` otherwise.\n**Returns:** `{\"symbol\":\"BTCUSDT\",\"bidPrice\":\"...\",\"bidQty\":\"...\",\"askPrice\":\"...\",\"askQty\":\"...\"}`\n**n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Great for quick spread snapshot."
      },
      "typeVersion": 4.2
    },
    {
      "id": "3384dbb3-240e-4e9b-acbb-0e8d96a724cb",
      "name": "Klines (Candles)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        544,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/klines",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "interval",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `15m`, 'string') }}"
            },
            {
              "name": "limit",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', `20`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Klines (Candles)**\n\n**Endpoint:** `GET /api/v3/klines`\n**What it does:** Candlestick bars for a symbol/interval.\n**Params:**\n\n* `symbol` (STRING, required)\n* `interval` (ENUM, required \u2014 e.g., `1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M`)\n* `limit` (INT, default 500, max 1000 \u2014 **we set 20**)\n* `startTime`, `endTime` (optional)\n  **Request weight:** `1`.\n  **Returns (array per candle):** `[ openTime, open, high, low, close, volume, closeTime, quoteAssetVolume, numberOfTrades, takerBuyBaseVolume, takerBuyQuoteVolume ]`\n  **n8n query mapping:**\n\n```txt\nsymbol  = $fromAI('parameters0_Value', '', 'string')\ninterval= $fromAI('parameters1_Value', '15m', 'string')\nlimit   = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:** Without `startTime/endTime`, returns most recent."
      },
      "typeVersion": 4.2
    },
    {
      "id": "d6e0976c-1206-4e27-9248-601c48716d5d",
      "name": "Average Price",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        880,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/avgPrice",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Average Price**\n\n**Endpoint:** `GET /api/v3/avgPrice`\n**What it does:** **Current average price** for a symbol (rolling window).\n**Params:** `symbol` (STRING, required)\n**Request weight:** `1`.\n**Returns:** `{\"mins\":5,\"price\":\"...\",\"closeTime\":...}`\n**n8n query mapping:**\n\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Use UPPERCASE trading pairs without `-` (e.g., `BTCUSDT`)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "e37ba936-6b95-4a49-89d7-19ec25b7f2d3",
      "name": "Recent Trades",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        1200,
        592
      ],
      "parameters": {
        "url": "https://api.mexc.com/api/v3/trades",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "limit",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `100`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Recent Trades**\n\n**Endpoint:** `GET /api/v3/trades`\n**What it does:** Returns the **most recent public trades** for a symbol on MEXC.\n\n**Params:**\n* `symbol` (STRING, required)\n* `limit`  (INT, optional; default 100, max 1000)\n\n**Returns:** array of trades like `{ id, price, qty, quoteQty, time, isBuyerMaker, isBestMatch }`.\n\n**n8n query mapping:**\n```txt\nsymbol = $fromAI('parameters0_Value', '', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** For older historical trades, use the exchange's historical endpoint if available."
      },
      "typeVersion": 4.2
    },
    {
      "id": "43c5b731-c523-4998-9a08-551e8949fc07",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2128,
        -544
      ],
      "parameters": {
        "width": 1440,
        "height": 2064,
        "content": "# \ud83e\udde0 MEXC Spot Market Quant AI Agent \u2013 Full System Documentation\n\nA dedicated AI automation system for **spot market analysis** on MEXC. It integrates **price feeds, order book data, and 24h statistics**, processes structured inputs via n8n, and generates **Telegram-ready trading summaries**.\n\n---\n\n## \ud83e\udde9 Included Workflows\n\nYou must install and activate **all of the following workflows** for this system to function:\n\n| \u2705 Workflow Name                 | \ud83d\udccc Function Description                                                        |\n| ------------------------------- | ------------------------------------------------------------------------------ |\n| MEXC Spot Market Quant AI Agent | Core orchestrator. Handles user queries and generates the final market report. |\n| MEXC Price & Order Data Tool    | Fetches **latest price**, **24h stats**, and **order book depth** from MEXC.   |\n| MEXC Kline Tool                 | Pulls OHLCV candles for multiple intervals (15m, 1h, 4h, 1d).                  |\n| MEXC Recent Trades Tool         | Fetches recent executed trades for selected trading pairs.                     |\n\n---\n\n## \u2699\ufe0f Installation Instructions\n\n### Step 1: Import Workflows\n\n* Open your **n8n Editor UI**\n* Import each JSON file (from this package)\n* Save and activate workflows\n\n### Step 2: Configure Credentials\n\n* **OpenAI API Credential** \u2192 Add your GPT-4 key\n* **MEXC Price/Order/Kline APIs** \u2192 Public endpoints, **no authentication required**\n\n### Step 3: Webhook Setup\n\n* Ensure the AI Agent workflow can be triggered from your **Telegram bot** or internal webhook call\n* If using Telegram, add your **Telegram Bot API Token** in n8n credentials\n\n---\n\n## \ud83d\udda5\ufe0f System Workflow Overview\n\n```\n[Telegram/Webhook Trigger]\n\u2192 [Session Memory + Prompt Parsing]\n\u2192 [MEXC Spot Market Quant AI Agent]\n\u2192 [Price & 24h Stats Tool]\n\u2192 [Order Book Depth Tool]\n\u2192 [Klines (OHLCV) Tool]\n\u2192 [Recent Trades Tool]\n\u2192 [Reasoning + Report Formatter]\n\u2192 [Telegram/Output Channel]\n```\n\n---\n\n## \ud83d\udcec Telegram Output Example\n\n```html\n<b>MEXC: BTC/USDT Market Report</b>\n\n<b>Spot Strategy</b>\n\u2022 Action: Buy\n\u2022 Entry: $63,820 | SL: $61,200 | TP: $66,500\n\u2022 Reason:\n  \u2013 Strong 4h MACD Bullish Signal\n  \u2013 24h Volume Spike\n  \u2013 Order book shows strong bid walls\n\n<b>Market Data</b>\n\u2022 Last Price: $63,820\n\u2022 24h Change: +3.2%\n\u2022 24h Volume: 18,200 BTC\n\u2022 Spread: 0.02%\n\n<b>Recent Trades:</b>\n\u2022 Buy-side dominant (62%)\n```\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.\nAll rights reserved. This 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": "b5a94c09-a868-47e3-9c62-9bfa53cda2ec",
  "connections": {
    "Think": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "24h Stats": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Best Bid/Ask": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Average Price": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Recent Trades": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "MEXC  AI Agent": {
      "main": [
        [
          {
            "node": "Splits message is more than 4000 characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Price (Latest)": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Adds \"SessionId\"": {
      "main": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Klines (Candles)": {
      "ai_tool": [
        [
          {
            "node": "MEXC  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Order Book Depth": {
      "ai_tool": [
        [
          {
            "node": "MEXC  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": "MEXC  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
          }
        ]
      ]
    }
  }
}