AutomationFlowsAI & RAG › Real-time Okx Spot Market Data with Gpt-4o & Telegram

Real-time Okx Spot Market Data with Gpt-4o & Telegram

ByDon Jayamaha Jr @don-the-gem-dealer on n8n.io

Instantly access live OKX Spot Market data directly in Telegram!

Event trigger★★★★★ complexityAI-powered35 nodesOpenAI ChatTelegram TriggerTelegramMemory Buffer WindowTool CalculatorTool ThinkAgentHTTP Request Tool
AI & RAG Trigger: Event Nodes: 35 Complexity: ★★★★★ AI nodes: yes Added:

This workflow corresponds to n8n.io template #8609 — we link there as the canonical source.

This workflow follows the Agent → HTTP Request Tool recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "NPE3aLxgBrs6UNcA",
  "name": "OKX AI Agent v1.02",
  "tags": [],
  "nodes": [
    {
      "id": "0fdddcb8-ad21-468d-8dc1-99e9a2e9997e",
      "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": "7b6f2205-5a51-4034-b558-19b0585da42e",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1008,
        240
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0433fe88-52d0-4fa6-80b7-e1f0afa6ce75",
      "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": "5d20cb16-35dd-4cfc-b22a-c4859eefbc56",
      "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": "65f42216-de3f-4961-b67e-34cf0ec4d358",
      "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": "8a4b0dae-f2df-4358-98aa-51b832a337b1",
      "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": "4dfa9d4a-3668-423f-9685-a8517fd398f2",
      "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": "ad8587d4-f03b-495d-b0c3-d608e29fe3a6",
      "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": "cb8bb1c5-4dd8-4d60-a224-863358e17d35",
      "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": "0b465e66-b299-4a21-a84a-7e4eb08098a7",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 788,
        "content": "## Main AI Agent: Data Fetcher\n\n**Node: OKX Data Agent**\nThis is the **core orchestrator**. It uses OpenAI only to **format and present raw OKX Spot market data**, not to analyze or generate strategies.\n\nIt has direct **HTTP request access** to the OKX REST API and retrieves:\n\n* **Tickers (single/all)** (`/api/v5/market/ticker` or `/api/v5/market/tickers?instType=SPOT`)\n* **24h stats** (`/api/v5/market/ticker?instId=BTC-USDT`)\n* **Order book depth** (`/api/v5/market/books?instId=BTC-USDT&sz=50`)\n* **Best bid/ask (book ticker)** (`/api/v5/market/books?instId=BTC-USDT&sz=1`)\n* **Candlesticks / Klines** (`/api/v5/market/candles?instId=BTC-USDT&bar=15m&limit=100`)\n* **Average / Mark Price** (`/api/v5/market/mark-price?instType=SPOT&instId=BTC-USDT`)\n* **Recent trades** (`/api/v5/market/trades?instId=BTC-USDT&limit=100`)\n\nThe agent calls these endpoints in parallel for the requested instrument, validates results, and then **presents the data in clean, structured text format** for Telegram.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "6a5c34be-a570-49b8-b875-a08a3725ef16",
      "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": "424be542-56b9-4078-859d-a31c18512838",
      "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": "fb2debe7-5160-406c-9e3c-7245148a1389",
      "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": "2515e909-480e-4ddb-ae09-fb022bbc47dc",
      "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/v5/market/books`\n**What it does:** Returns order book **bids/asks** up to `sz` (default 25).\n\n**Params:**\n\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n* `sz` (INT, optional; default 25; max 400)\n\n**Returns:** `asks`, `bids`, `ts`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\nsz     = $fromAI('parameters1_Value', 25, 'number')\n```\n\n**Notes:** Unlike Binance `limit`, OKX uses `sz` with max 400."
      },
      "typeVersion": 1
    },
    {
      "id": "66b35377-9b16-4b61-9beb-2ca38a370018",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 916,
        "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/v5/market/ticker`\n**What it does:** Provides the **best bid/ask** prices and sizes for an instrument.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n\n**Returns:** `{ \"instId\":\"BTC-USDT\", \"bidPx\":\"...\", \"bidSz\":\"...\", \"askPx\":\"...\", \"askSz\":\"...\" }`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Unlike Binance, OKX\u2019s `ticker` response includes last price, open24h, high24h, low24h, and **best bid/ask** in the same payload."
      },
      "typeVersion": 1
    },
    {
      "id": "924995df-b973-4055-95fd-4490ffdb21e9",
      "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": "c8d351a3-bb20-4ec4-a890-162b2295c7c4",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -992,
        736
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "9376ce27-8a71-45d7-a7df-863c25a2ff1e",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        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### **24h Stats (Ticker)**\n\n**Endpoint:** `GET /api/v5/market/ticker`\n**What it does:** Returns 24h stats for a Spot instrument: **last**, **open24h**, **high24h**, **low24h**, **vol24h (base)**, **volCcy24h (quote)**, **price change %**, etc.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** `instId` must be UPPERCASE with a hyphen, e.g. `ETH-USDT`."
      },
      "typeVersion": 1
    },
    {
      "id": "33c6deb2-f7ca-4d0f-ae6a-93bcd0a30b76",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        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### **Price (Latest)**\n\n**Endpoint:** `GET /api/v5/market/ticker`\n**What it does:** Returns the **latest trade price** for an instrument.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n\n**Returns:** `{ \"instId\":\"BTC-USDT\", \"last\":\"...\", \"askPx\":\"...\", \"bidPx\":\"...\", \"high24h\":\"...\", \"low24h\":\"...\" }`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** OKX always requires `instId` with dash format (e.g., `BTC-USDT`)."
      },
      "typeVersion": 1
    },
    {
      "id": "8207ae9a-ddf7-43e9-accb-155117ebcc54",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1108,
        "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/v5/market/candles`\n**What it does:** Returns candlestick (OHLCV) bars for an instrument.\n\n**Params:**\n\n* `instId` (STRING, required) \u2014 instrument ID (e.g., `BTC-USDT`)\n* `bar` (ENUM, required) \u2014 interval, e.g. `1m,3m,5m,15m,30m,1H,2H,4H,6H,12H,1D,1W,1M`\n* `limit` (INT, optional, default 100; max 100)\n* `after` / `before` (optional, pagination)\n\n**Returns (array per candle):** `[ ts, o, h, l, c, vol, volCcy, volCcyQuote, confirm ]`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\nbar    = $fromAI('parameters1_Value', '15m', 'string')\nlimit  = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:**\n* Binance uses `symbol`/`interval`; OKX uses `instId`/`bar`.\n* `limit` max is **100** (not 1000 like Binance)."
      },
      "typeVersion": 1
    },
    {
      "id": "0a1965e4-08cb-415d-912d-c154ec3fe103",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        512
      ],
      "parameters": {
        "color": 6,
        "height": 1012,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n### **Average / Mark Price**\n\n**Endpoint:** `GET /api/v5/market/mark-price`\n**What it does:** Returns the **mark price** (reference fair price) for an instrument, which can serve as an 'average-like' indicator.\n\n**Params:**\n\n* `instType` (STRING, required) \u2014 e.g., `SPOT`\n* `instId` (STRING, required) \u2014 instrument ID (e.g., `BTC-USDT`)\n\n**Returns:** `[{ instType, instId, markPx, ts }]`\n\n**n8n query mapping:**\n\n```txt\ninstType = 'SPOT'\ninstId   = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:**\n* Binance\u2019s `/avgPrice` gives a rolling average \u2014 OKX does not have this directly.\n* Use `markPx` as the closest equivalent (widely used as the fair price across markets)."
      },
      "typeVersion": 1
    },
    {
      "id": "944da462-023b-46ec-bd85-95f3e9c7d3ad",
      "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### **Recent Trades**\n\n**Endpoint:** `GET /api/v5/market/trades`\n**What it does:** Returns the **most recent public trades** for an OKX Spot instrument.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n* `limit`  (INT, optional; default 100, max 100)\n\n**Returns:** array of trades like `{ tradeId, px, sz, side, ts, instId }`.\n\n**n8n query mapping:**\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** `instId` must be UPPERCASE with a hyphen (e.g., `ETH-USDT`)."
      },
      "typeVersion": 1
    },
    {
      "id": "696106a9-6f82-4149-be59-266c409562bb",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        1520,
        592
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f62d4038-2114-4d76-a77d-2330ec9767b2",
      "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": "5fef8e2d-9290-451e-a54e-759bd6cf02cb",
      "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": "62f9ee31-ae28-40ae-8462-b41ba31d24dd",
      "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": "8f9284c5-dd6e-44c9-96d2-3c439aa99940",
      "name": "OKX  AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -96,
        240
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "You are the **OKX Spot Market Data Agent**.\n\nYou have **HTTP request access** to the official OKX REST API to retrieve market data for any requested OKX Spot trading pair.\nYour job is to **fetch and present data only**. You do **not** analyze, predict, or recommend.\n\n---\n\n## \ud83d\udd17 API Access\n\n**Base endpoint (default):**\n\n* [https://www.okx.com](https://www.okx.com)\n\n**Format rules:**\n\n* All requests are **HTTP GET**\n* Responses are **JSON**\n* Parameters use query strings (e.g., `?instId=BTC-USDT`)\n* `instId` is always uppercase with `-` (e.g., `BTC-USDT`)\n\n---\n\n## \ud83d\udccc Available Market Data Endpoints\n\n1. **Tickers (All or Single)**\n   `GET /api/v5/market/tickers?instType=SPOT`\n   `GET /api/v5/market/ticker?instId=BTC-USDT`\n   \u2022 Real-time ticker for one or all Spot instruments.\n\n2. **Order Book Depth**\n   `GET /api/v5/market/books?instId=BTC-USDT&sz=50`\n   \u2022 Returns bids/asks with depth (size configurable).\n\n3. **Recent Trades**\n   `GET /api/v5/market/trades?instId=BTC-USDT&limit=100`\n   \u2022 Most recent trades for a symbol.\n\n4. **Candlestick / Kline Data**\n   `GET /api/v5/market/candles?instId=BTC-USDT&bar=15m&limit=100`\n   \u2022 Supported intervals: `1m, 3m, 5m, 15m, 30m, 1H, 2H, 4H, 6H, 12H, 1D, 1W, 1M`\n   \u2022 Default limit = 100 (max 100).\n\n5. **24h Stats (Ticker Details)**\n   `GET /api/v5/market/ticker?instId=BTC-USDT`\n   \u2022 Includes open, high, low, last, volume, % change, etc.\n\n6. **Average Price (Mark Price)**\n   `GET /api/v5/market/mark-price?instType=SPOT&instId=BTC-USDT`\n   \u2022 Use `markPx` as the fair/average reference price.\n\n---\n\n## \ud83e\udde9 Utility Tools\n\n* **Calculator** \u2192 Perform math inside the workflow (spreads, % changes, etc).\n* **Think** \u2192 Lightweight reasoning helper to reshape JSON, select fields, and prepare outputs.\n\n---\n\n## \ud83d\udce4 Output Format\n\nRespond with **clean, structured text** (no HTML required). Example grouping:\n\n```\nBTC-USDT \u2014 OKX Spot Data\n\nPrice\n\u2022 Last: 58000.12\n\u2022 Avg (Mark): 57980.55\n\u2022 Change (24h): +2.4%\n\n24h Stats\n\u2022 Open: 56500 \u2022 High: 58500 \u2022 Low: 56200 \u2022 Volume: 12,430 BTC \u2022 Quote Vol: 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## \u26a0\ufe0f Rules\n\n* Always **call the correct OKX API endpoint** for the requested data.\n* Do **not** fabricate or calculate values yourself (except simple formatting).\n* Do **not** provide trading advice, sentiment, or predictions.\n* Do **not** output raw JSON; always present clean, human-readable values.\n* If data is missing or request fails, show `N/A`.\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "40071070-f676-4f72-a913-eadc349c5d9e",
      "name": "24h Stats",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -720,
        592
      ],
      "parameters": {
        "url": "https://www.okx.com/api/v5/market/ticker",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **24h Stats (Ticker)**\n\n**Endpoint:** `GET /api/v5/market/ticker`\n**What it does:** Returns 24h stats for a Spot instrument: **last**, **open24h**, **high24h**, **low24h**, **vol24h (base)**, **volCcy24h (quote)**, **price change %**, etc.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** `instId` must be UPPERCASE with a hyphen, e.g. `ETH-USDT`."
      },
      "typeVersion": 4.2
    },
    {
      "id": "2eca8bad-e582-43bc-b2f9-6dc36d3de490",
      "name": "Order Book Depth",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -400,
        592
      ],
      "parameters": {
        "url": "https://www.okx.com/api/v5/market/books",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "sz",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `25`, 'number') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Order Book Depth**\n\n**Endpoint:** `GET /api/v5/market/books`\n**What it does:** Returns order book **bids/asks** up to `sz` (default 25).\n\n**Params:**\n\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n* `sz` (INT, optional; default 25; max 400)\n\n**Returns:** `asks`, `bids`, `ts`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\nsz     = $fromAI('parameters1_Value', 25, 'number')\n```\n\n**Notes:** Unlike Binance `limit`, OKX uses `sz` with max 400."
      },
      "typeVersion": 4.2
    },
    {
      "id": "7e353ddc-98d5-45b0-b868-f42c74154008",
      "name": "Price (Latest)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -112,
        592
      ],
      "parameters": {
        "url": "https://www.okx.com/api/v5/market/ticker",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Price (Latest)**\n\n**Endpoint:** `GET /api/v5/market/ticker`\n**What it does:** Returns the **latest trade price** for an instrument.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n\n**Returns:** `{ \"instId\":\"BTC-USDT\", \"last\":\"...\", \"askPx\":\"...\", \"bidPx\":\"...\", \"high24h\":\"...\", \"low24h\":\"...\" }`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** OKX always requires `instId` with dash format (e.g., `BTC-USDT`)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "2474c7bf-34c2-4f71-9ba2-88c9f364c81c",
      "name": "Best Bid/Ask",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        208,
        592
      ],
      "parameters": {
        "url": "https://www.okx.com/api/v5/market/ticker",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Best Bid/Ask (Book Ticker)**\n\n**Endpoint:** `GET /api/v5/market/ticker`\n**What it does:** Provides the **best bid/ask** prices and sizes for an instrument.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n\n**Returns:** `{ \"instId\":\"BTC-USDT\", \"bidPx\":\"...\", \"bidSz\":\"...\", \"askPx\":\"...\", \"askSz\":\"...\" }`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:** Unlike Binance, OKX\u2019s `ticker` response includes last price, open24h, high24h, low24h, and **best bid/ask** in the same payload."
      },
      "typeVersion": 4.2
    },
    {
      "id": "d16b1649-1233-448c-af6f-9294a59c2f73",
      "name": "Klines (Candles)",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        560,
        592
      ],
      "parameters": {
        "url": "https://www.okx.com/api/v5/market/candles",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "bar",
              "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/v5/market/candles`\n**What it does:** Returns candlestick (OHLCV) bars for an instrument.\n\n**Params:**\n\n* `instId` (STRING, required) \u2014 instrument ID (e.g., `BTC-USDT`)\n* `bar` (ENUM, required) \u2014 interval, e.g. `1m,3m,5m,15m,30m,1H,2H,4H,6H,12H,1D,1W,1M`\n* `limit` (INT, optional, default 100; max 100)\n* `after` / `before` (optional, pagination)\n\n**Returns (array per candle):** `[ ts, o, h, l, c, vol, volCcy, volCcyQuote, confirm ]`\n\n**n8n query mapping:**\n\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\nbar    = $fromAI('parameters1_Value', '15m', 'string')\nlimit  = $fromAI('parameters2_Value', 20, 'number')\n```\n\n**Notes:**\n* Binance uses `symbol`/`interval`; OKX uses `instId`/`bar`.\n* `limit` max is **100** (not 1000 like Binance)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "45d7b0d9-8c95-479f-8cc0-6f48983e217e",
      "name": "Average / Mark Price",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        880,
        592
      ],
      "parameters": {
        "url": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('URL', ``, 'string') }}",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instType",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            },
            {
              "name": "instId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', ``, 'string') }}"
            }
          ]
        },
        "toolDescription": "### \ud83c\udff7 Tool: **Average / Mark Price**\n\n**Endpoint:** `GET /api/v5/market/mark-price`\n**What it does:** Returns the **mark price** (reference fair price) for an instrument, which can serve as an 'average-like' indicator.\n\n**Params:**\n\n* `instType` (STRING, required) \u2014 e.g., `SPOT`\n* `instId` (STRING, required) \u2014 instrument ID (e.g., `BTC-USDT`)\n\n**Returns:** `[{ instType, instId, markPx, ts }]`\n\n**n8n query mapping:**\n\n```txt\ninstType = 'SPOT'\ninstId   = $fromAI('parameters0_Value', '', 'string')\n```\n\n**Notes:**\n* Binance\u2019s `/avgPrice` gives a rolling average \u2014 OKX does not have this directly.\n* Use `markPx` as the closest equivalent (widely used as the fair price across markets)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "c8925c12-b11d-45be-8bee-41d64d8122e3",
      "name": "Recent Trades",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        1216,
        608
      ],
      "parameters": {
        "url": "https://www.okx.com/api/v5/market/trades",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "instId",
              "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/v5/market/trades`\n**What it does:** Returns the **most recent public trades** for an OKX Spot instrument.\n\n**Params:**\n* `instId` (STRING, required) \u2014 instrument id, e.g. `BTC-USDT`\n* `limit`  (INT, optional; default 100, max 100)\n\n**Returns:** array of trades like `{ tradeId, px, sz, side, ts, instId }`.\n\n**n8n query mapping:**\n```txt\ninstId = $fromAI('parameters0_Value', '', 'string')\nlimit  = $fromAI('parameters1_Value', 100, 'number')\n```\n\n**Notes:** `instId` must be UPPERCASE with a hyphen (e.g., `ETH-USDT`)."
      },
      "typeVersion": 4.2
    },
    {
      "id": "ffa14c26-a607-4793-820f-0bd8ee93de32",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2112,
        -688
      ],
      "parameters": {
        "width": 1424,
        "height": 2256,
        "content": "# \ud83e\udde0 OKX Spot Market Data AI Agent \u2013 Full System Documentation\n\nA production-ready AI automation system for **spot market data retrieval** on OKX.  \nIt provides **real-time price, order book, candlesticks, and trades**, then delivers fully formatted **Telegram-style market reports**.\n\n---\n\n## \ud83e\udde9 Included Workflows\n\n> You must install and activate **all of the following workflows** for the system to function correctly:\n\n| \u2705 Workflow Name                  | \ud83d\udccc Function Description                                                                 |\n| -------------------------------- | --------------------------------------------------------------------------------------- |\n| OKX Spot Market Data AI Agent    | Final AI orchestrator. Fetches OKX Spot data and formats structured Telegram reports.   |\n| OKX Price/24hrStats/OrderBook    | Retrieves latest price, 24h stats, and live order book depth.                           |\n| OKX Best Bid/Ask Tool            | Provides bid/ask spread snapshot.                                                       |\n| OKX Kline (Candlestick) Tool     | Pulls OHLCV candles across multiple timeframes (15m\u20131D).                                |\n| OKX Average / Mark Price Tool    | Returns OKX mark price (fair average reference).                                        |\n| OKX Recent Trades Tool           | Lists the last 100 trades for the given instrument.                                     |\n| OKX Utility Tools (Think/Calc)   | Lightweight helpers for JSON reshaping, math ops, and message formatting.               |\n| Telegram Trigger & Splitter      | Handles user authentication, input session memory, and Telegram message size limits.    |\n\n---\n\n## \u2699\ufe0f Installation Instructions\n\n### Step 1: Import Workflows\n* Open your **n8n Editor UI**  \n* Import each workflow JSON file one by one  \n* Ensure each is activated or callable via `Execute Workflow`\n\n### Step 2: Set Credentials\n* **OpenAI API Credential** \u2192 Add your OpenAI key for GPT-4.1 / GPT-4o-mini  \n* **Telegram Bot Credential** \u2192 Add your Telegram Bot API token  \n* **OKX API Access** \u2192 Public endpoints only (no auth required)\n\n### Step 3: Configure Webhook & Telegram\n* Deploy the **Telegram Trigger** node  \n* Update the **user authentication code node** with your Telegram ID  \n* Messages from your ID will trigger the agent\n\n### Step 4: Final Agent Execution\n* Trigger `OKX Spot Market Data AI Agent` manually or from Telegram  \n* The agent:\n  * Calls all connected OKX endpoints with `instId` and sessionId  \n  * Collects price, order book, trades, and kline data  \n  * Formats results into **structured human-readable market data report**  \n  * Sends via Telegram (auto-splits if >4000 chars)\n\n---\n\n## \ud83d\udda5\ufe0f System Workflow Overview\n\n```\n\n\\[Telegram Trigger]\n\u2192 \\[ID Check + Session Memory]\n\u2192 \\[OKX AI Agent]\n\u2192 \\[OKX API Tools: Price, Stats, OrderBook, Trades, Klines]\n\u2192 \\[Utility Tools: Calculator + Think]\n\u2192 \\[Split Long Messages]\n\u2192 \\[Telegram SendMessage]\n\n````\n\n---\n\n## \ud83d\udcec Telegram Output Style\n\n```txt\nBTC-USDT \u2014 OKX Spot Data\n\nPrice\n\u2022 Last: 58,000.12\n\u2022 Avg (Mark): 57,980.55\n\u2022 Change (24h): +2.4%\n\n24h Stats\n\u2022 Open: 56,500 \u2022 High: 58,500 \u2022 Low: 56,200 \n\u2022 Volume: 12,430 BTC \u2022 Quote Vol: 720M USDT\n\nOrder Book (Top 5)\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\nKlines (15m, latest 5)\n\u2022 O/H/L/C: 57,800 / 58,020 / 57,750 / 57,990\n\nRecent Trades\n\u2022 Buy 0.25 @ 58,000\n\u2022 Sell 0.10 @ 57,995\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. 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": "d8300b40-9963-44cd-908a-609073e7b2c6",
  "connections": {
    "Think": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "24h Stats": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Best Bid/Ask": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OKX  AI Agent": {
      "main": [
        [
          {
            "node": "Splits message is more than 4000 characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recent Trades": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Price (Latest)": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Adds \"SessionId\"": {
      "main": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Klines (Candles)": {
      "ai_tool": [
        [
          {
            "node": "OKX  AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Order Book Depth": {
      "ai_tool": [
        [
          {
            "node": "OKX  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": "OKX  AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Average / Mark Price": {
      "ai_tool": [
        [
          {
            "node": "OKX  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
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Instantly access live OKX Spot Market data directly in Telegram!

Source: https://n8n.io/workflows/8609/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Jarvis is a powerful multi-agent productivity assistant built in n8n. It works directly from Telegram and can understand both text messages and voice notes.

Telegram Trigger, Telegram, OpenAI +10
AI & RAG

This multi-agent n8n workflow delivers an automated, intelligent trading analysis system for the WEEX Spot Market. It uses GPT-4o to interpret user prompts, route them to the correct sub-agent tools,

OpenAI Chat, Telegram Trigger, Agent +7
AI & RAG

AI-powered Telegram bot for effortless expense tracking. Send receipts, voice messages, or text - the bot automatically extracts and categorizes your expenses. 📸 Receipt & Invoice OCR - Send photos of

Telegram Trigger, Mcp Client Tool, Tool Calculator +7
AI & RAG

This template is designed for anyone who wants to use Telegram as a personal AI assistant hub. If you often juggle tasks, emails, calendars, and expenses across multiple tools, this workflow consolida

OpenAI Chat, Memory Buffer Window, Mcp Client Tool +11
AI & RAG

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Output Parser Structured, Telegram, N8N Nodes Tesseractjs +14