{
  "id": "82r122lbmQPWishF",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Binance Spot Market Quant AI Agent",
  "tags": [],
  "nodes": [
    {
      "id": "6c6238ec-ba3d-4c59-a612-c3b4e9ae8b73",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -440,
        620
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b8b90061-9d5e-4e48-a0b0-bb6bdb193771",
      "name": "Binance Spot Market Quant AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -80,
        160
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "You are the **Binance Spot Market Quant AI Agent**, responsible for generating structured, professional swing-trading reports for **any trading pair** on the Binance Spot Market. You use **validated technical indicators**, **order flow data**, and **curated crypto sentiment** to create actionable trading strategies.\n\n---\n\n### \ud83d\udd17 Connected Tools\n\n1. **\ud83e\udde0 Binance Financial Market Analyst Tool**\n\n   \u2022 Aggregates outputs from:\n\n   * `Binance 15min Indicators Tool`\n   * `Binance 1h Indicators Tool`\n   * `Binance 4h Indicators Tool`\n   * `Binance 1d Indicators Tool`\n   * `Binance Price/OrderBook/Kline Tool`\n\n   \u2022 Each indicator tool calculates:\n\n   * **RSI, BBANDS, SMA, EMA, ADX, MACD**\n   * Based on the **latest 20 klines** for its interval\n   * Returns both values and signal labels (e.g. overbought, divergence)\n\n   \u2022 The Price Tool provides:\n\n   * **Live price**\n   * **24h OHLCV**\n   * **Order book depth (top 100 bids/asks)**\n   * **Klines** for `15m`, `1h`, `4h`, and `1d` intervals\n\n2. **\ud83d\udcf0 Binance News and Sentiment Analyst Tool**\n\n   \u2022 Pulls from sources like:\n\n   * CoinDesk, Cointelegraph, BitcoinMagazine, NewsBTC, CryptoBriefing, and more\n\n   \u2022 Returns:\n\n   * **Sentiment Score**: Bullish / Bearish / Neutral\n   * **Summary**: 2\u20133 sentence market snapshot\n   * **Top 3\u20135 headlines** (with source links)\n\n---\n\n### \ud83d\udcca Core Responsibilities\n\nYou always:\n\n1. **Call all tools concurrently** for each query\n\n   * Pass the extracted symbol and sessionId as input\n   * Wait for structured results from each tool\n   * Do not skip any tool even if user prompt is vague\n\n2. **Perform full technical analysis** for the symbol\n\n   * Short-term: `15m + 1h`\n   * Mid-term: `4h`\n   * Long-term: `1d`\n   * Detect breakouts, trend shifts, divergences, and confluence signals\n   * Confirm findings using multiple timeframes and indicator alignment\n\n3. **Synthesize the final report** with:\n\n<b>Spot Trade Strategy</b>\n\u2022 Action: Buy / Sell / Hold\n\u2022 Entry Price, Stop Loss, Take Profit\n\u2022 Rationale:\n\u2003- <b>Price Action Signals</b>\n\u2003- <b>Lagging Indicator Confirmation</b>\n\u2003- <b>Sentiment Alignment</b>\n\n<b>Leverage Strategy</b>\n\u2022 Position: Long / Short\n\u2022 Leverage: 2x / 3x / 5x\n\u2022 Rationale + Risk Zones\n\n4. **Score signal strength**\n   \u2022 Confidence Score: `0\u2013100`\n   \u2022 Label: Low / Medium / High / Very High\n\n5. **Include sentiment and headlines section**\n   \u2022 `<b>News Sentiment:</b>` \\[summary]\n   \u2022 `\u2022` Top headlines with clickable links\n\n---\n\n### \ud83d\udce4 Output Format (Telegram HTML)\n\nStart with:\n\n```html\n<b>{{SYMBOL}} Market Report</b>\n```\n\nUse clean formatting:\n\n* `<b>` for headers\n* `\u2022` for bullet lists\n* Logical grouping: price > indicators > strategy > sentiment\n\n---\n\n### \u26a0\ufe0f Rules\n\nDO NOT:\n\n* Fabricate any values\n* Repeat this system message\n* Output raw JSON or API structure\n\nONLY use **tool-delivered** and **validated** data. Write with clarity and tone of a senior quant analyst.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "13965042-ad03-4108-88b3-250955bdbd28",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1000,
        160
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3f98e10f-fe7e-4c87-9e4f-4b6d8bfb805b",
      "name": "User Authentication (Replace Telegram ID)",
      "type": "n8n-nodes-base.code",
      "position": [
        -680,
        160
      ],
      "parameters": {
        "jsCode": "if ($input.first().json.message.from.id !== <Replace Telegram ID>) { // 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": "ef715512-2d57-447e-969d-c173a823775b",
      "name": "Adds \"SessionId\"",
      "type": "n8n-nodes-base.set",
      "position": [
        -400,
        160
      ],
      "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": "876e3ec9-3453-4db9-928a-6163c1c6702b",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        900,
        160
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "70c70549-1c58-478d-a39f-5bccc7b76b04",
      "name": "Splits message is more than 4000 characters",
      "type": "n8n-nodes-base.code",
      "position": [
        480,
        160
      ],
      "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": "85e0b819-f722-43ae-93b7-5317ff877804",
      "name": "News and Sentiment Analysis Request",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        120,
        600
      ],
      "parameters": {
        "url": "https://treasurium.app.n8n.cloud/webhook/newsanalyst",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "message",
              "value": "=={{ $json.message }}"
            }
          ]
        },
        "toolDescription": "It will post the name of the cryptocurrency to get the News and Sentiment Analysis for use in the Binance Quant AI Agent."
      },
      "typeVersion": 4.2
    },
    {
      "id": "27c27a35-fe83-4c4b-b9b1-90f2e1de8602",
      "name": "Binance SM Financial Analyst Tool",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        380,
        580
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "Nm41n4i6VMhrixZs",
          "cachedResultName": "Work Drive \u2014 Binance SM Financial Analyst Tool"
        },
        "workflowInputs": {
          "value": {
            "message": "={{ $fromAI(\"message\",\"Populate this with a relevant message to this subagent\")}}",
            "sessionId": "={{ $json.sessionId }}"
          },
          "schema": [
            {
              "id": "message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sessionId",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "sessionId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "78c6847a-8449-45dd-8aa6-1ce69e3d4e67",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -160,
        620
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "7ded5880-cf83-483c-84b9-dfce5e11d616",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1060,
        -100
      ],
      "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": "dfb57705-77b8-4c88-a6b0-aa8128b08400",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        -100
      ],
      "parameters": {
        "color": 2,
        "height": 460,
        "content": "## Validate User Access\nNode: User **Authentication\nChecks incoming Telegram ID** against the approved user list."
      },
      "typeVersion": 1
    },
    {
      "id": "37372f5a-db8c-4335-81a4-de437aff4782",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        -100
      ],
      "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": "952adc52-49a1-49c8-8bd5-d31c8277af83",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        -220
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 580,
        "content": "## Main AI Agent: Report Generator\nNode: Binance Spot Market Quant AI Agent\nThis is the **core orchestrator**. It uses OpenAI to reason over:\n\n**Multi-timeframe indicator outputs**\n\n**Order book + price data**\n\n**Sentiment and news**\n\nIt calls both tools in parallel:\n\n**Binance Financial Market Analyst Tool**\n\n**Binance News & Sentiment Analyst Tool**\n\nThen it synthesizes a final trading report."
      },
      "typeVersion": 1
    },
    {
      "id": "a6475e05-c83a-4dce-acd1-19294077912f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -100
      ],
      "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": "413aff1b-43a3-4f81-b82d-eab2f18aed61",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        840,
        -100
      ],
      "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": "8b7687eb-9c5f-4745-8700-cc337a1a2505",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -520,
        520
      ],
      "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": "fc0fa082-96d7-4dda-8273-0aa44f6b1f97",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        40,
        520
      ],
      "parameters": {
        "color": 6,
        "height": 660,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Binance News & Sentiment Analyst Tool\nNode: ToolWebhook\nSends the symbol to:\n\nPOST https://treasurium.app.n8n.cloud/webhook/newsanalyst\nReturns:\n\n**\ud83d\udcc8 Sentiment (Bullish / Neutral / Bearish)**\n\n**\ud83d\udcf0 3\u20135 crypto headlines**\n\n**\ud83e\udde0 Summary paragraph (1\u20133 lines)**"
      },
      "typeVersion": 1
    },
    {
      "id": "becbf326-b8d3-482e-b9c5-7a1bed58b112",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        520
      ],
      "parameters": {
        "color": 6,
        "height": 660,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Binance Financial Market Analyst Tool\nNode: ToolWorkflow\nCalls all connected indicator agents:\n\n**15m, 1h, 4h, 1d**\n\nPrice/Orderbook/Klines agent\n\n**Each indicator (RSI, MACD, BBANDS, SMA, EMA, ADX)** is returned per timeframe, plus order book depth and candle snapshots."
      },
      "typeVersion": 1
    },
    {
      "id": "46cb7225-7ba9-4270-988e-74e4a30403fc",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        520
      ],
      "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": "238ff914-0c43-4cdf-9506-61e67306300f",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1400,
        -1340
      ],
      "parameters": {
        "width": 1780,
        "height": 2540,
        "content": "# \ud83e\udde0 Binance Spot Market Quant AI Agent \u2013 Full System Documentation\n\nA professional-grade AI automation system for **spot market trading insights** on Binance. It analyzes **multi-timeframe technical indicators**, **live price/order data**, and **crypto sentiment**, then delivers fully formatted **Telegram-style trading 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| Binance Spot Market Quant AI Agent                 | Final AI orchestrator. Parses user prompt and generates Telegram-ready reports.  |\n| Binance SM Financial Analyst Tool                  | Calls indicator tools and price/order data tools. Synthesizes structured inputs. |\n| Binance SM News and Sentiment Analyst Webhook Tool | Analyzes crypto sentiment, gives summary and headlines via POST webhook.         |\n| Binance SM Price/24hrStats/OrderBook/Kline Tool    | Pulls price, order book, 24h stats, and OHLCV klines for 15m\u20131d.                 |\n| Binance SM 15min Indicators Tool                   | Calculates 15m RSI, MACD, BBANDS, ADX, SMA/EMA from Binance kline data.          |\n| Binance SM 1hour Indicators Tool                   | Same as above but for 1h timeframe.                                              |\n| Binance SM 4hour Indicators Tool                   | Same as above but for 4h timeframe.                                              |\n| Binance SM 1day Indicators Tool                    | Same as above but for 1d timeframe.                                              |\n| Binance SM Indicators Webhook Tool                 | Technical backend. Handles all webhook logic for each timeframe tool.            |\n\n---\n\n## \u2699\ufe0f Installation Instructions\n\n### Step 1: Import Workflows\n\n* Open your **n8n Editor UI**\n* Import each workflow JSON file one by one\n* Activate them or ensure they're called via `Execute Workflow`\n\n### Step 2: Set Credentials\n\n* **OpenAI API Credential**: Add your OpenAI key for GPT-4o or GPT-4.1\n* **Binance Price Data**: No auth needed (public endpoint)\n\n### Step 3: Configure Webhook Endpoints\n\n* Deploy **Binance SM Indicators Webhook Tool**\n* Ensure the following routes are reachable:\n\n  * `/webhook/15m`\n  * `/webhook/1h`\n  * `/webhook/4h`\n  * `/webhook/1d`\n\n### Step 4: Telegram Integration\n\n* Add your Telegram Bot to n8n with correct API token\n* Update the **Telegram ID check node** with your own ID\n* Messages from your ID will trigger the agent\n\n### Step 5: Final Agent Execution\n\n* Trigger `Binance Spot Market Quant AI Agent` manually or from Telegram\n* The agent:\n\n  * Calls all connected tools with symbol and sessionId\n  * Waits for full indicator + sentiment response\n  * Returns a formatted multi-part trading report\n\n---\n\n## \ud83d\udda5\ufe0f System Workflow Overview\n\n```\n[Telegram Trigger]\n\u2192 [Session Memory + ID Check]\n\u2192 [Quant Agent]\n\u2192 [Financial Analyst Tool + Sentiment Tool]\n\u2192 [All Indicators (15m, 1h, 4h, 1d)]\n\u2192 [Price/Kline/OrderBook Tool]\n\u2192 [News and Sentiment Webhook]\n\u2192 [Signal Reasoning + Report Formatting]\n\u2192 [Final Telegram HTML Message]\n```\n\n---\n\n## \ud83d\udcec Telegram Output Style\n\n```html\n<b>BTCUSDT Market Report</b>\n\n<b>Spot Strategy</b>\n\u2022 Action: Buy\n\u2022 Entry: $63,800 | SL: $61,200 | TP: $66,500\n\u2022 Reason:\n\u2003- MACD Crossover (1h)\n\u2003- RSI Rebound from Oversold (15m)\n\u2003- Sentiment: Bullish\n\n<b>Leverage Strategy</b>\n\u2022 Position: Long 3x\n\u2022 Entry: $63,800\n\u2022 SL/TP zones same as above\n\n<b>News Sentiment:</b> Slightly Bullish\n\u2022 \"Bitcoin rallies as ETF inflows surge\" \u2013 CoinDesk\n\u2022 \"Whales accumulate BTC at key support\" \u2013 NewsBTC\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**. Reuse or resale prohibited without license.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "bb69da16-db3d-4804-ad9d-a3d971f8fa36",
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Binance Spot Market Quant AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Adds \"SessionId\"": {
      "main": [
        [
          {
            "node": "Binance Spot Market Quant AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "User Authentication (Replace Telegram ID)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Binance Spot Market Quant AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Binance SM Financial Analyst Tool": {
      "ai_tool": [
        [
          {
            "node": "Binance Spot Market Quant AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Binance Spot Market Quant AI Agent": {
      "main": [
        [
          {
            "node": "Splits message is more than 4000 characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "News and Sentiment Analysis Request": {
      "ai_tool": [
        [
          {
            "node": "Binance Spot Market Quant 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
          }
        ]
      ]
    }
  }
}