{
  "id": "GpfHivOzWDehc8La",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Physical vs Digital Gold Investment Comparison with Cost & Return Analysis",
  "tags": [],
  "nodes": [
    {
      "id": "c5c407d2-1ddb-40ff-9831-607bcd03c0cc",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -896,
        80
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f7da2308-aac1-4040-8f15-d1305360f287",
      "name": "Get Digital Price",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -608,
        32
      ],
      "parameters": {
        "url": "https://www.goldapi.io/api/XAU/INR",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-access-token",
              "value": "="
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "d9bfe9e3-fa85-4a5f-a054-03b392863ffe",
      "name": "Get IBJA Website",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        16,
        48
      ],
      "parameters": {
        "url": "https://ibjarates.com/",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "6bb6e260-221b-4735-8a7c-d94849a49da2",
      "name": "Extract Physical Price",
      "type": "n8n-nodes-base.html",
      "position": [
        288,
        48
      ],
      "parameters": {
        "options": {},
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "IBJA_Price",
              "cssSelector": "#GoldRatesCompare999"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "87fad470-832b-4717-8216-2e9f49d76345",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        -208
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 416,
        "content": "## Digital Price Retrieval & Validation\n\n- Fetches the live 24K digital gold price in INR.\n- API: https://www.goldapi.io/api/XAU/INR\n- Includes a conditional check to catch missing API keys before proceeding.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cc0961e4-bbf6-4b1c-8778-5fd8a55ea027",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 480,
        "content": "## Physical Price Extraction\n\nScrapes the official benchmark rate for physical gold.\nSource: IBJA website.The IBJA rate is the trusted national benchmark used by local jewelers\n- Sends a standard HTTP GET request to fetch the raw HTML from https://ibjarates.com/.\n- Uses an HTML Extraction node to parse the DOM structure.\n- Isolates and extracts the specific 1-gram 24K price using the precise CSS selector: #GoldRatesCompare999.\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "67c87377-4324-4b1c-9584-f807318f5002",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 368,
        "content": "## Landed Cost Calculation (Comparator)\n- Calculates the true out-of-pocket cost by applying real-world taxes.\n- Digital: Adds 3% GST + 3% platform spread.\n- Physical: Adds 3% GST + 8% making charges.\n- Determines the arbitrage difference to find the cheapest option."
      },
      "typeVersion": 1
    },
    {
      "id": "45505290-828e-4194-82ed-80d208a46cbd",
      "name": "Get Market News",
      "type": "n8n-nodes-base.rssFeedRead",
      "position": [
        1008,
        48
      ],
      "parameters": {
        "url": "https://finance.yahoo.com/rss/headline?s=GC=F",
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "5894a32b-8a70-4614-9053-d7276a875e77",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -560,
        288
      ],
      "parameters": {
        "text": "=MARKET MATH:\nDigital 1g Price: {{ $('Comparator').item.json.Digital_1g_Final }}\nPhysical 1g Price: {{ $('Comparator').item.json.Price_Difference_Per_Gram }}\nCheaper Option: {{ $('Comparator').item.json.Cheaper_Option }}\n\nLATEST NEWS:\n{{ $json.data }}",
        "options": {
          "systemMessage": "=You are an elite Quantitative Financial Analyst specializing in the gold market. I will provide you with the calculated Landed Costs of 1 gram of gold (comparing Digital vs. Physical) and the latest market news. You must output your final analysis strictly as a JSON object with exactly three keys: > 1. \"Arbitrage_Check\" (A 1-sentence summary of which buying method is cheaper today and by how much).\n2. \"Sentiment\" (Must be exactly \"Greedy\", \"Neutral\" or \"Fearful\" based on the news).\n3. \"Efficiency_Score\" (A number from 1 to 100 rating how good of a day it is to buy gold).\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "eabf5bbd-ee4f-4ff4-8874-64be5094192a",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        -560,
        448
      ],
      "parameters": {
        "model": "openai/gpt-oss-20b",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "46fabf35-6ad6-4e4d-9e39-a683f52811f7",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1664,
        -112
      ],
      "parameters": {
        "width": 688,
        "height": 640,
        "content": "## Gold Price Analysis (Physical vs Digital)\n\nSummary:\nThis workflow is a fully automated, AI-powered financial advisor built in n8n. It calculates the true, out-of-pocket cost of buying 1 gram of digital vs. physical gold in India, reads the latest global market news and uses an AI model to give you a daily \"Buy/Wait\" score and market sentiment report.\n\n## How it works:\n- Data Collection: Fetches live 1g digital gold prices and scrapes the official physical benchmark from the IBJA.\n- The Math: Applies real-world taxes (Digital: +6% total fees; Physical: +11% total fees) to identify the cheapest option.\n- Market Context: Pulls the top 3 latest gold market headlines.\n- AI Analysis: Feeds the data into an LLM to output Market Sentiment (Bullish/Bearish/Neutral) and an Efficiency Score (1-100).\n\n## Setup Steps:\n- GoldAPI Authentication: Generate an access token from GoldAPI.io and paste it into the header parameters of the \"Get Digital Price\" node.\n\n- AI Agent Credentials: Create an API key for your chosen LLM provider (like Groq) and configure the credentials inside the Chat Model node connected to the AI Agent.\n\n- Google Sheets Setup: Create a new Google Sheet to log your daily reports, authenticate your Google account in the \"Add Report\" node and select your specific document to map the data fields.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2431b3c1-6fc4-4375-8edd-1c13e35aade3",
      "name": "Comparator",
      "type": "n8n-nodes-base.code",
      "position": [
        720,
        80
      ],
      "parameters": {
        "jsCode": "let spot1g =$('Get Digital Price').first().json.price_gram_24k ; \nlet rawIBJA = $input.first().json.IBJA_Price;\n\n// Clean the physical price just in case the website adds commas later\nlet physical1g = parseFloat(rawIBJA.toString().replace(/,/g, ''));\n\n// Ensure the digital price is read as a number\nspot1g = parseFloat(spot1g);\n\n// Apply the Real-World Taxes and Fees\n// Digital App: +3% GST and +3% Platform Spread\nlet digitalFinal = spot1g * 1.03 * 1.03;\n\n// Physical Coin: +3% GST and +8% Making Charges\nlet physicalFinal = physical1g * 1.03 * 1.08;\n\n// Calculate the Arbitrage (Difference)\nlet difference = physicalFinal - digitalFinal;\nlet cheaperOption = difference > 0 ? \"Digital\" : \"Physical\";\n\n// Output the clean, calculated data\nreturn {\n    json: {\n        Digital_1g_Final: parseFloat(digitalFinal.toFixed(2)),\n        Physical_1g_Final: parseFloat(physicalFinal.toFixed(2)),\n        Price_Difference_Per_Gram: parseFloat(Math.abs(difference).toFixed(2)),\n        Cheaper_Option: cheaperOption\n    }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "e43bdb08-eacd-44a3-b376-f11fbb26f51a",
      "name": "News Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        1184,
        48
      ],
      "parameters": {
        "maxItems": 3
      },
      "typeVersion": 1
    },
    {
      "id": "d61e952e-a9fd-48a5-8aad-0b3bad40c68c",
      "name": "Data Array",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1360,
        48
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "b3726c61-697e-48fd-bd23-caa0b649ca2f",
      "name": "Message Format",
      "type": "n8n-nodes-base.code",
      "position": [
        -272,
        288
      ],
      "parameters": {
        "jsCode": "// 1. Unpack the AI's JSON response\n// (Ensure your LLM node outputs to the 'text' or 'output' property)\nlet aiResponse = JSON.parse($input.first().json.text || $input.first().json.output); \n\n// 2. Grab the original math we calculated earlier\nlet digitalPrice = $('Comparator').first().json.Digital_1g_Final\nlet physicalPrice =$('Comparator').first().json.Physical_1g_Final\n\n// 3. Build the beautiful Telegram/WhatsApp message\nlet finalMessage = ` GOLD INTELLIGENCE REPORT \\n\\n`;\nfinalMessage += ` Digital (1g): \u20b9${digitalPrice}\\n`;\nfinalMessage += ` Physical (1g): \u20b9${physicalPrice}\\n`;\nfinalMessage += ` Arbitrage: ${aiResponse.Arbitrage_Check}\\n\\n`;\nfinalMessage += ` Market Sentiment: ${aiResponse.Sentiment}\\n`;\nfinalMessage += ` AI Buy Score: ${aiResponse.Efficiency_Score}/100\\n`;\n\n// 4. Output everything cleanly for Google Sheets and your messaging app\nreturn {\n    json: {\n        Date: new Date().toLocaleDateString('en-IN'),\n        Digital_Price: digitalPrice,\n        Physical_Price: physicalPrice,\n        Arbitrage: aiResponse.Arbitrage_Check,\n        Sentiment: aiResponse.Sentiment,\n        Efficiency_Score: aiResponse.Efficiency_Score,\n        Formatted_Message: finalMessage\n    }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "96625cd8-8042-4d12-ae1c-712060790069",
      "name": "Add Report",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        112,
        288
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ $json.date }}",
            "Arbitrage": "={{ $('Message Format').item.json.Arbitrage }}",
            "Sentiment": "={{ $json.Sentiment }}",
            "Digital_Price": "={{ $json['Digital Price'] }}",
            "Physical_Price": "={{ $json.Physical_Price }}",
            "Efficiency_Score": "={{ $json.Efficiency_Score }}",
            "Formatted_Message": "={{ $('Message Format').item.json.Formatted_Message }}"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Digital_Price",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Digital_Price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Physical_Price",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Physical_Price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Arbitrage",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Arbitrage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sentiment",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sentiment",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Efficiency_Score",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Efficiency_Score",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Formatted_Message",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Formatted_Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Digital Price",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Digital Price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1KCjydTlah16mwb-Dt4kTP10TNnUX-zlCLfcaC02erPo/edit#gid=0",
          "cachedResultName": "03_gold"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1KCjydTlah16mwb-Dt4kTP10TNnUX-zlCLfcaC02erPo",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1KCjydTlah16mwb-Dt4kTP10TNnUX-zlCLfcaC02erPo/edit?usp=drivesdk",
          "cachedResultName": "n8n-projects"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "9e6224d7-a3b6-43a9-9bd0-dbe9bf8edfd9",
      "name": "Add your access token",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -256,
        -48
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "708a81a7-b0d9-43e3-9e53-455c48225bfe",
      "name": "check for result",
      "type": "n8n-nodes-base.if",
      "position": [
        -432,
        32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4c0e6f28-3332-49df-bfb7-e8ba3a579ea1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": "No API Key provided"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "05bdabc3-7ad0-4ad0-8b91-3597d5783116",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -64,
        288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "442d1ee6-05c9-4064-aad0-72f279e9d823",
              "name": "date",
              "type": "string",
              "value": "={{ $json.Date }}"
            },
            {
              "id": "681c48b1-4878-4986-9352-267006927f78",
              "name": "Digital Price",
              "type": "number",
              "value": "={{ $json.Digital_Price }}"
            },
            {
              "id": "26846e0c-8e91-48c8-9734-8b33ae05a6bc",
              "name": "Physical_Price",
              "type": "number",
              "value": "={{ $json.Physical_Price }}"
            },
            {
              "id": "1d081dda-adb6-4a6d-8ea0-56a15b6b1e1f",
              "name": "Sentiment",
              "type": "string",
              "value": "={{ $json.Sentiment }}"
            },
            {
              "id": "0b27826e-75ab-4ac2-9283-4b248e8c36d2",
              "name": "Efficiency_Score",
              "type": "number",
              "value": "={{ $json.Efficiency_Score }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7504bb07-b5b6-4e19-a0ae-c0e195edcbee",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 352,
        "content": "## Market Context & News Aggregation\n\nEvaluates the price math and current news using a fast LLM.\nThe AI acts as a quantitative analyst.\nOutputs a structured JSON verdict including an Arbitrage Check, Market Sentiment (Greedy/Neutral/Fearful) and an Efficiency Score (1-100)."
      },
      "typeVersion": 1
    },
    {
      "id": "af4a75a5-c330-47f1-8fee-6e1f4bcd8d0a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 368,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Report Formatting & Storage\n- Prepares and logs the final data.\n- Parses the AI's JSON output and formats a clean text message.\n- Maps the data fields for storage.\n- Appends the daily report directly to a Google Sheet."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "a856d6cd-7c3d-4df7-be55-41e8ae0121db",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Message Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Comparator": {
      "main": [
        [
          {
            "node": "Get Market News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data Array": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "News Limit": {
      "main": [
        [
          {
            "node": "Data Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Add Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message Format": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Market News": {
      "main": [
        [
          {
            "node": "News Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get IBJA Website": {
      "main": [
        [
          {
            "node": "Extract Physical Price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check for result": {
      "main": [
        [
          {
            "node": "Add your access token",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get IBJA Website",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Digital Price": {
      "main": [
        [
          {
            "node": "check for result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Physical Price": {
      "main": [
        [
          {
            "node": "Comparator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get Digital Price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}